From 40efc936d5c790689ec6033c9739262bc80a04ec Mon Sep 17 00:00:00 2001 From: Paolo Capriotti Date: Mon, 11 Oct 2021 08:59:26 +0200 Subject: [PATCH] Make non-collision test for 1-1 conv ids faster The `anySame` function has quadratic runtime, but here we can use an `Ord` instance, and just compare the `nubOrd` lists. This also removes a potential flakyness caused by repeated input pairs (which should be quite likely to happen, given the low entropy of the UUID generator). --- services/galley/test/unit/Test/Galley/API/One2One.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/galley/test/unit/Test/Galley/API/One2One.hs b/services/galley/test/unit/Test/Galley/API/One2One.hs index d3f6f0332fe..913a0ed8390 100644 --- a/services/galley/test/unit/Test/Galley/API/One2One.hs +++ b/services/galley/test/unit/Test/Galley/API/One2One.hs @@ -47,5 +47,6 @@ one2OneConvIdNonCollision = do let len = 10_000 -- A generator of lists of length 'len' of qualified user ID pairs let gen = vectorOf len arbitrary - quids <- head <$> sample' gen - anySame (fmap (uncurry one2OneConvId) quids) @?= False + quids <- nubOrd <$> generate gen + let hashes = nubOrd (fmap (uncurry one2OneConvId) quids) + length hashes @?= length quids