on master help sign in
Fix serialize test taking too long, too much mem
commit191abebe920cfb4eb3a6e37d070ef9d100b517c9 authorHarendra Kumar <harendra@composewell.com> dateThu 4 Jan 2024, 06:50 (3 years ago) parent55cc5d0
2 files changed+21−4
benchmark/Streamly/Benchmark/Data/Serialize.hs+1−3 test/Streamly/Test/Data/Serialize.hs+20−1
benchmark/Streamly/Benchmark/Data/Serialize.hs+1−3
@@ -268,6 +268,7 @@ instance NFData a => NFData (BinTree a) where
268268 rnf (Leaf a) = rnf a `seq` ()
269269 rnf (Tree l r) = rnf l `seq` rnf r
270270
271+-- XXX This may not terminate, or could become really large.
271272instance Arbitrary a => Arbitrary (BinTree a) where
272273 arbitrary = oneof [Leaf <$> arbitrary, Tree <$> arbitrary <*> arbitrary]
273274
@@ -559,8 +560,6 @@ main = do
559560 let !len = length lInt -- evaluate the list
560561#endif
561562#ifndef FUSION_CHECK
562− -- This can take too much memory/CPU, need to restrict the test
563− -- runQC
564563#ifdef USE_UNBOX
565564 runWithCLIOpts defaultStreamSize allBenchmarks
566565#else
@@ -568,7 +567,6 @@ main = do
568567 `seq` runWithCLIOpts
569568 defaultStreamSize
570569 (allBenchmarks tInt lInt recL recR)
571−
572570#endif
573571#else
574572 -- Enable FUSION_CHECK macro at the beginning of the file
test/Streamly/Test/Data/Serialize.hs+20−1
@@ -109,9 +109,19 @@ $(Serialize.deriveSerializeWith
109109 CONF
110110 [d|instance Serialize a => Serialize (BinTree a)|])
111111
112+-- XXX This may not terminate, or could become really large.
112113instance Arbitrary a => Arbitrary (BinTree a) where
113114 arbitrary = oneof [Leaf <$> arbitrary, Tree <$> arbitrary <*> arbitrary]
114115
116+-- Make a balanced tree of given level
117+mkBinTree :: (Arbitrary a) => Int -> IO (BinTree a)
118+mkBinTree = go (generate arbitrary)
119+
120+ where
121+
122+ go r 0 = Leaf <$> r
123+ go r n = Tree <$> go r (n - 1) <*> go r (n - 1)
124+
115125--------------------------------------------------------------------------------
116126-- Record syntax type
117127--------------------------------------------------------------------------------
@@ -207,6 +217,10 @@ roundtrip
207217 -> IO ()
208218roundtrip val = do
209219
220+ -- For debugging large size generated by arbitrary
221+ -- let sz = Serialize.addSizeTo 0 val
222+ -- putStrLn $ "Size is: " ++ show sz
223+
210224 val `shouldBe` Array.deserialize (Array.pinnedSerialize val)
211225
212226 res <- poke val
@@ -270,7 +284,12 @@ testCases = do
270284 $ \(x :: [CustomDatatype]) -> roundtrip x
271285
272286 limitQC
273− $ prop "BinTree" $ \(x :: BinTree Int) -> roundtrip x
287+ $ prop "BinTree"
288+ $ forAll (elements [1..15])
289+ (\(x :: Int) -> do
290+ (r :: BinTree Int) <- mkBinTree x
291+ roundtrip r
292+ )
274293
275294 where
276295