Skip to content

Commit

Permalink
rm redundant function re-definition.
Browse files Browse the repository at this point in the history
  • Loading branch information
fisx committed Dec 27, 2024
1 parent bbd8071 commit 5974b64
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
33 changes: 15 additions & 18 deletions integration/test/Test/Events.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import Servant.API (AsApi, ToServant, toServant)
import Servant.API.Generic (fromServant)
import qualified Servant.Client as Servant
import SetupHelpers
import Testlib.Prelude hiding (assertNoEvent)
import Testlib.Prelude
import UnliftIO hiding (handle)

testConsumeEventsOneWebSocket :: (HasCallStack) => App ()
Expand All @@ -46,10 +46,10 @@ testConsumeEventsOneWebSocket = do
e %. "data.event.payload.0.type" `shouldMatch` "user.client-add"
e %. "data.event.payload.0.client.id" `shouldMatch` clientId
e %. "data.delivery_tag"
assertNoEvent_ ws
assertNoEvent 1 ws

sendAck ws deliveryTag False
assertNoEvent_ ws
assertNoEvent 1 ws

handle <- randomHandle
putHandle alice handle >>= assertSuccess
Expand Down Expand Up @@ -79,7 +79,7 @@ testConsumeTempEvents = do
-- consumer being created
lift $ do
expectAndAckNewClientEvent ws0 clientId0
assertNoEvent_ ws0
assertNoEvent 1 ws0

wsTemp <- createEventsWebSocket alice Nothing

Expand All @@ -94,8 +94,8 @@ testConsumeTempEvents = do
-- Client0 should also be notified even if there is a temp client
void $ expectAndAckNewClientEvent ws0 clientId1

assertNoEvent_ wsTemp
assertNoEvent_ ws0
assertNoEvent 1 wsTemp
assertNoEvent 1 ws0
where
expectAndAckNewClientEvent :: EventWebSocket -> String -> App ()
expectAndAckNewClientEvent ws cid =
Expand Down Expand Up @@ -196,7 +196,7 @@ testMLSTempEvents = do
e %. "data.event.payload.0.type" `shouldMatch` "conversation.mls-welcome"
ackEvent ws e

assertNoEvent_ ws
assertNoEvent 1 ws

testConsumeEventsForDifferentUsers :: (HasCallStack) => App ()
testConsumeEventsForDifferentUsers = do
Expand All @@ -221,7 +221,7 @@ testConsumeEventsForDifferentUsers = do
e %. "data.event.payload.0.type" `shouldMatch` "user.client-add"
e %. "data.event.payload.0.client.id" `shouldMatch` clientId
e %. "data.delivery_tag"
assertNoEvent_ ws
assertNoEvent 1 ws
sendAck ws deliveryTag False

testConsumeEventsWhileHavingLegacyClients :: (HasCallStack) => App ()
Expand Down Expand Up @@ -278,7 +278,7 @@ testConsumeEventsAcks = do
sendAck ws deliveryTag False

runCodensity (createEventsWebSocket alice (Just clientId)) $ \ws -> do
assertNoEvent_ ws
assertNoEvent 1 ws

testConsumeEventsMultipleAcks :: (HasCallStack) => App ()
testConsumeEventsMultipleAcks = do
Expand All @@ -302,7 +302,7 @@ testConsumeEventsMultipleAcks = do
sendAck ws deliveryTag True

runCodensity (createEventsWebSocket alice (Just clientId)) $ \ws -> do
assertNoEvent_ ws
assertNoEvent 1 ws

testConsumeEventsAckNewEventWithoutAckingOldOne :: (HasCallStack) => App ()
testConsumeEventsAckNewEventWithoutAckingOldOne = do
Expand Down Expand Up @@ -336,7 +336,7 @@ testConsumeEventsAckNewEventWithoutAckingOldOne = do
sendAck ws deliveryTagClientAdd False

runCodensity (createEventsWebSocket alice (Just clientId)) $ \ws -> do
assertNoEvent_ ws
assertNoEvent 1 ws

testEventsDeadLettered :: (HasCallStack) => App ()
testEventsDeadLettered = do
Expand Down Expand Up @@ -370,7 +370,7 @@ testEventsDeadLettered = do
ackEvent ws e

-- We've consumed the whole queue.
assertNoEvent_ ws
assertNoEvent 1 ws

testTransientEventsDoNotTriggerDeadLetters :: (HasCallStack) => App ()
testTransientEventsDoNotTriggerDeadLetters = do
Expand Down Expand Up @@ -398,7 +398,7 @@ testTransientEventsDoNotTriggerDeadLetters = do
sendTypingStatus alice selfConvId "started" >>= assertSuccess

runCodensity (createEventsWebSocket alice (Just clientId)) $ \ws -> do
assertNoEvent_ ws
assertNoEvent 1 ws

testTransientEvents :: (HasCallStack) => App ()
testTransientEvents = do
Expand Down Expand Up @@ -437,7 +437,7 @@ testTransientEvents = do
e %. "data.event.payload.0.user.handle" `shouldMatch` handle
ackEvent ws e

assertNoEvent_ ws
assertNoEvent 1 ws

testChannelLimit :: (HasCallStack) => App ()
testChannelLimit = withModifiedBackend
Expand Down Expand Up @@ -466,7 +466,7 @@ testChannelLimit = withModifiedBackend
-- the first client fails to connect because the server runs out of channels
do
ws <- createEventsWebSocket alice (Just client0)
lift $ assertNoEvent_ ws
lift $ assertNoEvent 1 ws

testChannelKilled :: (HasCallStack) => App ()
testChannelKilled = startDynamicBackendsReturnResources [def] $ \[backend] -> do
Expand Down Expand Up @@ -631,9 +631,6 @@ assertNoEvent ws = do
eventJSON <- prettyJSON e
assertFailure $ "Did not expect event: \n" <> eventJSON

assertNoEvent_ :: (HasCallStack) => EventWebSocket -> App ()
assertNoEvent_ = void . assertNoEvent

consumeAllEvents :: EventWebSocket -> App ()
consumeAllEvents ws = do
timeout 1_000_000 (readChan ws.events) >>= \case
Expand Down
4 changes: 2 additions & 2 deletions integration/test/Testlib/Cannon.hs
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,8 @@ assertNoEvent ::
Int ->
WebSocket ->
App ()
assertNoEvent to ws = withWebSocketFailureContext ws $ do
mEvent <- awaitAnyEvent to ws
assertNoEvent tSecs ws = withWebSocketFailureContext ws $ do
mEvent <- awaitAnyEvent tSecs ws
case mEvent of
Just event -> assertFailure $ "Expected no event, but got: " <> show event
Nothing -> pure ()
Expand Down

0 comments on commit 5974b64

Please sign in to comment.