diff --git a/integration/test/Test/MLS/KeyPackage.hs b/integration/test/Test/MLS/KeyPackage.hs index 7c58110921f..31d3a8641e9 100644 --- a/integration/test/Test/MLS/KeyPackage.hs +++ b/integration/test/Test/MLS/KeyPackage.hs @@ -9,6 +9,7 @@ import API.BrigInternal import MLS.Util import SetupHelpers import Testlib.Prelude +import UnliftIO (pooledForConcurrentlyN) testDeleteKeyPackages :: App () testDeleteKeyPackages = do @@ -452,3 +453,37 @@ testReplaceKeyPackagesV7 = do testErrorCases (Just [suite]) altSuiteKeyPackages testErrorCases (Just [suite]) (oldSuiteKeyPackages <> altSuiteKeyPackages <> suiteKeyPackages) testErrorCases (Just [suite]) [] + +testUploadClaim1000KeyPackages :: App () +testUploadClaim1000KeyPackages = do + let suite = def + keyPackageCount = 1000 + + alice <- randomUser OwnDomain def + alice1 <- createMLSClient def {ciphersuites = [suite]} alice + + bob <- randomUser OwnDomain def + bob1 <- createMLSClient def {ciphersuites = [suite]} bob + + -- Generate 1000 key packages in parallel (16 concurrent workers) + kps <- map fst <$> pooledForConcurrentlyN 16 [1 .. keyPackageCount] \_ -> do + generateKeyPackage alice1 suite + + -- Upload all 1000 key packages in one batched call + void $ uploadKeyPackages alice1 kps >>= getBody 201 + + -- Verify count is 1000 + bindResponse (countKeyPackages suite alice1) $ \resp -> do + resp.status `shouldMatchInt` 200 + resp.json %. "count" `shouldMatchInt` keyPackageCount + + -- Bob claims one key package from alice + bindResponse (claimKeyPackages suite bob1 alice) $ \resp -> do + resp.status `shouldMatchInt` 200 + kpBundles <- resp.json %. "key_packages" & asList + length kpBundles `shouldMatchInt` 1 + + -- Verify count is now 999 (one claimed) + bindResponse (countKeyPackages suite alice1) $ \resp -> do + resp.status `shouldMatchInt` 200 + resp.json %. "count" `shouldMatchInt` (keyPackageCount - 1)