Skip to content

Commit

Permalink
Add some more state manipulation
Browse files Browse the repository at this point in the history
  • Loading branch information
smatting committed Feb 3, 2023
1 parent d9f5047 commit ebeae4a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
19 changes: 13 additions & 6 deletions services/galley/test/integration/API/MLS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3091,20 +3091,27 @@ testCreatorRemovesUserFromParent = do
(_, qcnv) <- setupMLSGroup alice1
void $ createAddCommit alice1 [bob, charlie] >>= sendAndConsumeCommit

-- Former comment: fork here, so changes outside of this block still apply to parent
let subname = SubConvId "conference"
void $ createSubConv qcnv alice1 subname
let qcs = fmap (flip SubConv subname) qcnv
gsParent <- State.gets mlsClientGroupState

-- all clients join
let subId = SubConvId "conference"
qcs <- createSubConv qcnv alice1 subId
sub <-
liftTest $
responseJsonError
=<< getSubConv (qUnqualified alice) qcnv subId
<!! do const 200 === statusCode
for_ [bob1, bob2, charlie1, charlie2] $ \c -> do
resetGroup c qcs (pscGroupId sub)
void $ createExternalCommit c Nothing qcs >>= sendAndConsumeCommitBundle

-- maybe backup state here

traceM $ "\n\n\n\n\n---- \n\n\n --- test: remove commit for bob1 and bob2"
events <-
events <- do
setClientGroupStates gsParent [alice1, bob1, bob2]

createRemoveCommit alice1 [bob1, bob2] >>= \msg -> do
State.modify (\s -> s {mlsConvId = Just (fmap Conv qcnv)})
es <- sendAndConsumeCommitBundle msg
traceM $ "\n ############ subconv consume: "

Expand Down
14 changes: 13 additions & 1 deletion services/galley/test/integration/API/MLS/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,16 @@ getClientGroupState cid = do
Nothing -> liftIO $ assertFailure ("Attempted to get non-existing group state for client " <> show cid)
Just g -> pure g

setClientGroupStates :: Map ClientIdentity ByteString -> [ClientIdentity] -> MLSTest ()
setClientGroupStates gsMod cids = do
gsCurrent <- State.gets mlsClientGroupState
let replace gs cid =
case cid `Map.lookup` gsMod of
Nothing -> gs
Just g -> Map.insert cid g gs
let gsNext = foldl' replace gsCurrent cids
State.modify (\s -> s {mlsClientGroupState = gsNext})

hasClientGroupState :: HasCallStack => ClientIdentity -> MLSTest Bool
hasClientGroupState cid =
State.gets (isJust . Map.lookup cid . mlsClientGroupState)
Expand Down Expand Up @@ -894,7 +904,9 @@ consumeMessage msg = do
consumeMessage1 :: HasCallStack => ClientIdentity -> ByteString -> MLSTest ()
consumeMessage1 cid msg = do
bd <- State.gets mlsBaseDir
traceM $ "------- consume: " <> show msg <> " -- to: " <> show cid
when False $
traceM $
"------- consume: " <> show msg <> " -- to: " <> show cid
void $
mlscli
cid
Expand Down

0 comments on commit ebeae4a

Please sign in to comment.