mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-10-23 15:12:26 +00:00
Sending messages end to end (#21)
* duplex connection end-to-end (working, debug logs) * agent: send, receive, acknowledge messages * logging proposal * logging: client/server (dis)connections * agent scenario testing framework * add tests, remove logs * clean up
This commit is contained in:
1 parent
65dd693c83
commit
70fe7616f2
10 files changed
+292
-72
No files matched your search
+13
-6
@@ -26,7 +26,7 @@ testSMPClient :: MonadUnliftIO m => (Handle -> m a) -> m a
|
||||
testSMPClient client = do
|
||||
threadDelay 5000 -- TODO hack: thread delay for SMP server to start
|
||||
runTCPClient testHost testPort $ \h -> do
|
||||
line <- getLn h
|
||||
line <- liftIO $ getLn h
|
||||
if line == "Welcome to SMP v0.2.0"
|
||||
then client h
|
||||
else error "not connected"
|
||||
@@ -40,18 +40,25 @@ cfg =
|
||||
msgIdBytes = 6
|
||||
}
|
||||
|
||||
withSmpServerOn :: (MonadUnliftIO m, MonadRandom m) => ServiceName -> m a -> m a
|
||||
withSmpServerOn port =
|
||||
E.bracket
|
||||
(forkIO $ runSMPServer cfg {tcpPort = port})
|
||||
(liftIO . killThread)
|
||||
. const
|
||||
|
||||
withSmpServer :: (MonadUnliftIO m, MonadRandom m) => m a -> m a
|
||||
withSmpServer = E.bracket (forkIO $ runSMPServer cfg) (liftIO . killThread) . const
|
||||
withSmpServer = withSmpServerOn testPort
|
||||
|
||||
runSmpTest :: (MonadUnliftIO m, MonadRandom m) => (Handle -> m a) -> m a
|
||||
runSmpTest test = withSmpServer $ testSMPClient test
|
||||
|
||||
runSmpTestN :: forall m a. (MonadUnliftIO m, MonadRandom m) => Int -> ([Handle] -> m a) -> m a
|
||||
runSmpTestN nClients test = withSmpServer $ run [] nClients
|
||||
runSmpTestN nClients test = withSmpServer $ run nClients []
|
||||
where
|
||||
run :: [Handle] -> Int -> m a
|
||||
run hs 0 = test hs
|
||||
run hs n = testSMPClient $ \h -> run (h : hs) (n - 1)
|
||||
run :: Int -> [Handle] -> m a
|
||||
run 0 hs = test hs
|
||||
run n hs = testSMPClient $ \h -> run (n - 1) (h : hs)
|
||||
|
||||
smpServerTest :: RawTransmission -> IO RawTransmission
|
||||
smpServerTest cmd = runSmpTest $ \h -> tPutRaw h cmd >> tGetRaw h
|
||||
|
||||
Reference in new issue
Block a user