From 997a6e8633af550c7aa3cee049ac42674de9a5e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Thu, 20 Aug 2026 20:53:39 +0200 Subject: Test: refactor successful attach to exported function --- main/Test.hs | 11 +++++++++++ test/attach.et | 30 +++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/main/Test.hs b/main/Test.hs index 6ee75bd..b06ed61 100644 --- a/main/Test.hs +++ b/main/Test.hs @@ -320,6 +320,7 @@ commands = , ( "peer-add", cmdPeerAdd ) , ( "peer-drop", cmdPeerDrop ) , ( "peer-list", cmdPeerList ) + , ( "peer-get-by-addr", cmdPeerGetByAddr ) , ( "test-message-send", cmdTestMessageSend ) , ( "test-stream-open", cmdTestStreamOpen ) , ( "test-stream-close", cmdTestStreamClose ) @@ -748,6 +749,16 @@ cmdPeerList = do ] cmdOut "peer-list-done" +cmdPeerGetByAddr :: Command +cmdPeerGetByAddr = do + Just RunningServer {..} <- gets tsServer + addr <- T.unwords <$> asks tiParams + ( _, peers ) <- liftIO $ readMVar rsPeers + forM_ peers $ \tpeer -> do + paddr <- getPeerAddress $ tpPeer tpeer + when (T.pack (show paddr) == addr) $ do + cmdOut $ "peer-get-by-addr " <> show (tpIndex tpeer) + cmdTestMessageSend :: Command cmdTestMessageSend = do diff --git a/test/attach.et b/test/attach.et index ae00048..9163730 100644 --- a/test/attach.et +++ b/test/attach.et @@ -2,6 +2,26 @@ module attach import common + +export def perform_attach of dev to owner: + flush from owner matching // # TODO: forces (owner : Process), drop when not necessary + + send "peer-get-by-addr ${owner.node.ip} 29665" to dev + send "peer-get-by-addr ${dev.node.ip} 29665" to owner + expect /peer-get-by-addr ([0-9]+)/ from dev capture owner_pidx + expect /peer-get-by-addr ([0-9]+)/ from owner capture dev_pidx + + send "attach-to $owner_pidx" to dev + expect /attach-request $dev_pidx ([0-9]*)/ from owner capture code1 + expect /attach-response $owner_pidx ([0-9]*)/ from dev capture code2 + guard (code1 == code2) + + send "attach-accept $dev_pidx" to owner + send "attach-accept $owner_pidx" to dev + expect /attach-request-done $dev_pidx/ from owner + expect /attach-response-done $owner_pidx/ from dev + + test Attach: let services = "attach,sync" @@ -91,15 +111,7 @@ test SyncAfterAttach: expect /peer ([0-9]+) addr ${p.node.ip} 29665/ from p1 capture pidx expect /peer $pidx id Device./ from p1 - send "attach-to 1" - expect /attach-request $pidx ([0-9]*)/ from p1 capture code1 - expect /attach-response 1 ([0-9]*)/ capture code2 - guard (code1 == code2) - - send "attach-accept $pidx" to p1 - send "attach-accept 1" - expect /attach-request-done $pidx/ from p1 - expect /attach-response-done 1/ + perform_attach of p to p1 spawn as pd on nd spawn as p1 on n1 -- cgit v1.2.3