From 6d66efa471e1cd477bdfb86d5e46a56740759ba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 13 Jul 2025 16:59:25 +0200 Subject: (test) Test: service parameter to enable discovery tunnel --- discovery.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discovery.test b/discovery.test index 9453e65..4b48d8b 100644 --- a/discovery.test +++ b/discovery.test @@ -93,7 +93,7 @@ test ManualDiscovery: test DiscoveryTunnel: - let services = "discovery" + let services = "discovery:tunnel" subnet sd subnet s1 -- cgit v1.2.3 From 52e68b9e50038439e5b4994285d6d1dba5133629 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Tue, 15 Jul 2025 21:28:30 +0200 Subject: (test) Test output stream opening and closing --- discovery.test | 7 ++++++- network.test | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/discovery.test b/discovery.test index 4b48d8b..a297f54 100644 --- a/discovery.test +++ b/discovery.test @@ -124,7 +124,7 @@ test DiscoveryTunnel: for id in [ p1obase ]: for p in [ pd, p1, p2 ]: - send "start-server services $services" to p + send "start-server services $services test-log" to p for p in [ p1, p2 ]: with p: @@ -138,6 +138,11 @@ test DiscoveryTunnel: send "discovery-tunnel 1 $id" to p2 + expect /net-ostream-open ${pd.node.ip} 29665 1 1/ from p2 + expect /net-ostream-open ${p1.node.ip} 29665 1 1/ from pd + expect /net-ostream-open ${pd.node.ip} 29665 1 1/ from p1 + expect /net-ostream-open ${p2.node.ip} 29665 1 1/ from pd + expect from p1: /peer [0-9]+ addr tunnel@.*/ /peer [0-9]+ id Device2 Owner2/ diff --git a/network.test b/network.test index 0f49a1e..a670f35 100644 --- a/network.test +++ b/network.test @@ -189,8 +189,8 @@ test ServiceStreams: spawn as p2 send "create-identity Device1" to p1 send "create-identity Device2" to p2 - send "start-server services $services" to p1 - send "start-server services $services" to p2 + send "start-server services $services test-log" to p1 + send "start-server services $services test-log" to p2 expect from p1: /peer 1 addr ${p2.node.ip} 29665/ /peer 1 id Device2/ @@ -202,6 +202,8 @@ test ServiceStreams: expect /test-stream-open-done 1 ([0-9]+)/ from p1 capture stream1 expect /test-stream-open-from 1 $stream1/ from p2 + expect /net-ostream-open ${p2.node.ip} 29665 1 1/ from p1 + send "test-stream-send 1 $stream1 hello" to p1 expect /test-stream-send-done 1 $stream1/ from p1 expect /test-stream-received 1 $stream1 0 hello/ from p2 @@ -210,12 +212,18 @@ test ServiceStreams: expect /test-stream-close-done 1 $stream1/ from p1 expect /test-stream-closed-from 1 $stream1 1/ from p2 + expect /net-ostream-close-send ${p2.node.ip} 29665 1/ from p1 + expect /net-ostream-close-ack ${p2.node.ip} 29665 1 0/ from p1 + send "test-stream-open 1 8" to p2 expect /test-stream-open-done 1 ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)/ from p2 capture stream2_1, stream2_2, stream2_3, stream2_4, stream2_5, stream2_6, stream2_7, stream2_8 expect /test-stream-open-from 1 $stream2_1 $stream2_2 $stream2_3 $stream2_4 $stream2_5 $stream2_6 $stream2_7 $stream2_8/ from p1 let streams2 = [ stream2_1, stream2_2, stream2_3, stream2_4, stream2_5, stream2_6, stream2_7, stream2_8 ] with p2: + expect /net-ostream-open ${p1.node.ip} 29665 . 8/ + flush matching /net-ostream-open ${p1.node.ip} 29665.*/ + for i in [ 1..20 ]: for s in streams2: send "test-stream-send 1 $s hello$i" @@ -226,6 +234,9 @@ test ServiceStreams: send "test-stream-close 1 $s" for s in streams2: expect /test-stream-close-done 1 $s/ + + expect /net-ostream-close-ack ${p1.node.ip} 29665 . 0/ + flush matching /net-ostream-close-[a-z]* ${p1.node.ip} 29665.*/ with p1: for i in [ 1..20 ]: for s in streams2: -- cgit v1.2.3 From 6d29af6549ec56f8f04df35ea9c0f11037755afe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Wed, 16 Jul 2025 21:46:56 +0200 Subject: (test) Close streams used for tunnel on connection drop --- discovery.test | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/discovery.test b/discovery.test index a297f54..d73e292 100644 --- a/discovery.test +++ b/discovery.test @@ -144,11 +144,19 @@ test DiscoveryTunnel: expect /net-ostream-open ${p2.node.ip} 29665 1 1/ from pd expect from p1: - /peer [0-9]+ addr tunnel@.*/ - /peer [0-9]+ id Device2 Owner2/ + /peer 2 addr tunnel@.*/ + /peer 2 id Device2 Owner2/ expect from p2: - /peer [0-9]+ addr tunnel@.*/ - /peer [0-9]+ id Device1 Owner1/ + /peer 2 addr tunnel@.*/ + /peer 2 id Device1 Owner1/ + + send "peer-drop 2" to p1 + send "peer-drop 2" to p2 + + expect /net-ostream-close-ack ${pd.node.ip} 29665 1 0/ from p2 + expect /net-ostream-close-ack ${p1.node.ip} 29665 1 0/ from pd + expect /net-ostream-close-ack ${pd.node.ip} 29665 1 0/ from p1 + expect /net-ostream-close-ack ${p2.node.ip} 29665 1 0/ from pd for p in [ pd, p1, p2 ]: send "stop-server" to p -- cgit v1.2.3 From c85b4fdbd0fe58af93ff70ad62abe8b5aed8f82e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Fri, 18 Jul 2025 20:40:27 +0200 Subject: (test) Close streams on failed tunnel requests --- discovery.test | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/discovery.test b/discovery.test index d73e292..e80a755 100644 --- a/discovery.test +++ b/discovery.test @@ -162,3 +162,57 @@ test DiscoveryTunnel: send "stop-server" to p for p in [ pd, p1, p2 ]: expect /stop-server-done/ from p + + +test DiscoveryTunnelRefused: + let services = "discovery" + + subnet sd + subnet s1 + subnet s2 + + spawn as pd on sd + spawn as p1 on s1 + spawn as p2 on s2 + + for n in [ p1.node, p2.node ]: + shell on n: + nft add table inet filter + nft add chain inet filter input '{ type filter hook input priority filter ; policy drop; }' + nft add rule inet filter input 'ct state { established, related } accept' + + send "create-identity Discovery" to pd + send "create-identity Device1 Owner1" to p1 + send "create-identity Device2 Owner2" to p2 + + expect /create-identity-done ref ($refpat).*/ from p1 capture p1id + send "identity-info $p1id" to p1 + expect /identity-info ref $p1id base ($refpat) owner ($refpat).*/ from p1 capture p1base, p1owner + send "identity-info $p1owner" to p1 + expect /identity-info ref $p1owner base ($refpat).*/ from p1 capture p1obase + + expect /create-identity-done ref $refpat.*/ from p2 + expect /create-identity-done ref $refpat.*/ from pd + + for id in [ p1obase ]: + for p in [ pd, p1, p2 ]: + send "start-server services $services test-log" to p + + for p in [ p1, p2 ]: + with p: + send "peer-add ${pd.node.ip}" + expect: + /peer 1 addr ${pd.node.ip} 29665/ + /peer 1 id Discovery/ + expect from pd: + /peer [12] addr ${p.node.ip} 29665/ + /peer [12] id .*/ + + send "discovery-tunnel 1 $id" to p2 + expect /net-ostream-open ${pd.node.ip} 29665 1 1/ from p2 + expect /net-ostream-close-ack ${pd.node.ip} 29665 1 0/ from p2 + + for p in [ pd, p1, p2 ]: + send "stop-server" to p + for p in [ pd, p1, p2 ]: + expect /stop-server-done/ from p -- cgit v1.2.3 From e69c90a34b5bdc96271cd966e84c76f44a99d69e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Wed, 30 Jul 2025 20:07:07 +0200 Subject: =?UTF-8?q?(test)=20Switch=20test=20script=20extension=20to=20?= =?UTF-8?q?=E2=80=9Cet=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- attach.et | 45 ++++ attach.test | 45 ---- chatroom.et | 662 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ chatroom.test | 662 --------------------------------------------------------- common.et | 3 + common.test | 3 - contact.et | 202 ++++++++++++++++++ contact.test | 202 ------------------ discovery.et | 218 +++++++++++++++++++ discovery.test | 218 ------------------- message.et | 265 +++++++++++++++++++++++ message.test | 265 ----------------------- network.et | 514 ++++++++++++++++++++++++++++++++++++++++++++ network.test | 514 -------------------------------------------- storage.et | 523 +++++++++++++++++++++++++++++++++++++++++++++ storage.test | 523 --------------------------------------------- sync.et | 95 +++++++++ sync.test | 95 --------- 18 files changed, 2527 insertions(+), 2527 deletions(-) create mode 100644 attach.et delete mode 100644 attach.test create mode 100644 chatroom.et delete mode 100644 chatroom.test create mode 100644 common.et delete mode 100644 common.test create mode 100644 contact.et delete mode 100644 contact.test create mode 100644 discovery.et delete mode 100644 discovery.test create mode 100644 message.et delete mode 100644 message.test create mode 100644 network.et delete mode 100644 network.test create mode 100644 storage.et delete mode 100644 storage.test create mode 100644 sync.et delete mode 100644 sync.test diff --git a/attach.et b/attach.et new file mode 100644 index 0000000..afbdd0e --- /dev/null +++ b/attach.et @@ -0,0 +1,45 @@ +test: + let services = "attach,sync" + + spawn as p1 + spawn as p2 + send "create-identity Device1 Owner" to p1 + send "create-identity Device2" to p2 + send "watch-local-identity" to p1 + send "watch-local-identity" to p2 + send "start-server services $services" to p1 + send "start-server services $services" to p2 + expect from p1: + /local-identity Device1 Owner/ + /peer 1 addr ${p2.node.ip} 29665/ + /peer 1 id Device2/ + expect from p2: + /local-identity Device2/ + /peer 1 addr ${p1.node.ip} 29665/ + /peer 1 id Device1 Owner/ + + send "attach-to 1" to p2 + expect /attach-request 1 .*/ from p1 + expect /attach-response 1 .*/ from p2 + send "attach-reject 1" to p1 + expect /attach-request-failed 1 user/ from p1 + expect /attach-response-failed 1 rejected/ from p2 + + send "attach-to 1" to p2 + expect /attach-request 1 .*/ from p1 + expect /attach-response 1 .*/ from p2 + send "attach-reject 1" to p2 + expect /attach-request-failed 1 rejected/ from p1 + expect /attach-response-failed 1 user/ from p2 + + send "attach-to 1" to p2 + expect /attach-request 1 ([0-9]*)/ from p1 capture code1 + expect /attach-response 1 ([0-9]*)/ from p2 capture code2 + guard (code1 == code2) + + send "attach-accept 1" to p1 + send "attach-accept 1" to p2 + expect /attach-request-done 1/ from p1 + expect /attach-response-done 1/ from p2 + expect /local-identity Device2 Owner/ from p2 + expect /peer 1 id Device2 Owner/ from p1 diff --git a/attach.test b/attach.test deleted file mode 100644 index afbdd0e..0000000 --- a/attach.test +++ /dev/null @@ -1,45 +0,0 @@ -test: - let services = "attach,sync" - - spawn as p1 - spawn as p2 - send "create-identity Device1 Owner" to p1 - send "create-identity Device2" to p2 - send "watch-local-identity" to p1 - send "watch-local-identity" to p2 - send "start-server services $services" to p1 - send "start-server services $services" to p2 - expect from p1: - /local-identity Device1 Owner/ - /peer 1 addr ${p2.node.ip} 29665/ - /peer 1 id Device2/ - expect from p2: - /local-identity Device2/ - /peer 1 addr ${p1.node.ip} 29665/ - /peer 1 id Device1 Owner/ - - send "attach-to 1" to p2 - expect /attach-request 1 .*/ from p1 - expect /attach-response 1 .*/ from p2 - send "attach-reject 1" to p1 - expect /attach-request-failed 1 user/ from p1 - expect /attach-response-failed 1 rejected/ from p2 - - send "attach-to 1" to p2 - expect /attach-request 1 .*/ from p1 - expect /attach-response 1 .*/ from p2 - send "attach-reject 1" to p2 - expect /attach-request-failed 1 rejected/ from p1 - expect /attach-response-failed 1 user/ from p2 - - send "attach-to 1" to p2 - expect /attach-request 1 ([0-9]*)/ from p1 capture code1 - expect /attach-response 1 ([0-9]*)/ from p2 capture code2 - guard (code1 == code2) - - send "attach-accept 1" to p1 - send "attach-accept 1" to p2 - expect /attach-request-done 1/ from p1 - expect /attach-response-done 1/ from p2 - expect /local-identity Device2 Owner/ from p2 - expect /peer 1 id Device2 Owner/ from p1 diff --git a/chatroom.et b/chatroom.et new file mode 100644 index 0000000..54f9b2a --- /dev/null +++ b/chatroom.et @@ -0,0 +1,662 @@ +def refpat = /blake2#[0-9a-f]+/ + +test ChatroomSetup: + let services = "chatroom" + + # Local chatrooms + + spawn as p1 + with p1: + send "create-identity Device1 Owner1" + + send "chatroom-create first" + send "chatroom-create second" + + send "chatroom-list-local" + + expect /chatroom-list-item ([a-z0-9#]+) first sub true/ capture first + expect /chatroom-list-item [a-z0-9#]+ second sub true/ + local: + expect /chatroom-list-(.*)/ capture done + guard (done == "done") + + expect /chatroom-create-done ([a-z0-9#]+) first.*/ from p1 capture first + expect /chatroom-create-done ([a-z0-9#]+) second.*/ from p1 capture second + + # Send chatrooms to new peers + + spawn as p2 + send "create-identity Device2 Owner2" to p2 + + spawn as p3 + send "create-identity Device3 Owner3" to p3 + + for p in [ p1, p2, p3 ]: + with p: + send "chatroom-watch-local" + send "start-server services $services" + + for p in [ p2, p3 ]: + with p: + expect /chatroom-watched-added [a-z0-9#]+ first sub false/ + expect /chatroom-watched-added [a-z0-9#]+ second sub false/ + + # Subscribe and unsubscribe + + with p1: + send "chatroom-unsubscribe $first" + expect /chatroom-watched-updated [a-z0-9#]+ first sub false .*/ + + send "chatroom-subscribe $first" + expect /chatroom-watched-updated [a-z0-9#]+ first sub true .*/ + + with p2: + send "chatroom-list-local" + expect /chatroom-list-item ([a-z0-9#]+) first sub false/ capture p2_first + expect /chatroom-list-item ([a-z0-9#]+) second sub false/ capture p2_second + local: + expect /chatroom-list-(.*)/ capture done + guard (done == "done") + + send "chatroom-subscribe $p2_first" + send "chatroom-subscribe $p2_second" + + expect /chatroom-watched-updated [a-z0-9#]+ first sub true .*/ + expect /chatroom-watched-updated [a-z0-9#]+ second sub true .*/ + + send "chatroom-unsubscribe $p2_first" + send "chatroom-unsubscribe $p2_second" + + expect /chatroom-watched-updated [a-z0-9#]+ first sub false .*/ + expect /chatroom-watched-updated [a-z0-9#]+ second sub false .*/ + + # Create and sync additional chatrooms + + send "chatroom-create third" to p1 + send "chatroom-create fourth" to p2 + send "chatroom-create fifth" to p3 + + expect /chatroom-create-done ([a-z0-9#]+) fourth.*/ from p2 capture fourth + expect /chatroom-create-done ([a-z0-9#]+) fifth.*/ from p3 capture fifth + + for p in [ p1, p2, p3 ]: + with p: + expect /chatroom-watched-added [a-z0-9#]+ third sub [a-z]+/ + expect /chatroom-watched-added [a-z0-9#]+ fourth sub [a-z]+/ + expect /chatroom-watched-added [a-z0-9#]+ fifth sub [a-z]+/ + + # Update chatroom name + + send "chatroom-set-name $first first2" to p1 + for p in [ p1, p2, p3 ]: + with p: + expect /chatroom-watched-updated [a-z0-9#]+ first2.*/ + + send "chatroom-set-name $fourth fourth2" to p2 + send "chatroom-set-name $fifth fifth2" to p3 + for p in [ p1, p2, p3 ]: + with p: + expect /chatroom-watched-updated [a-z0-9#]+ fourth2.*/ + expect /chatroom-watched-updated [a-z0-9#]+ fifth2.*/ + + +test ChatroomMessages: + let services = "chatroom" + + spawn as p1 + spawn as p2 + + send "create-identity Device1 Owner1" to p1 + send "create-identity Device2 Owner2" to p2 + + for p in [ p1, p2 ]: + with p: + send "chatroom-watch-local" + send "start-server services $services" + + send "chatroom-create first_room" to p1 + expect /chatroom-create-done ([a-z0-9#]+) first_room.*/ from p1 capture room1_p1 + + expect /chatroom-watched-added [a-z0-9#]+ first_room sub true/ from p1 + expect /chatroom-watched-added ([a-z0-9#]+) first_room sub false/ from p2 capture room1_p2 + + send "chatroom-message-send $room1_p1 message1" to p1 + expect /chatroom-message-new $room1_p1 room first_room from Owner1 text message1/ from p1 + + send "chatroom-message-send $room1_p1 message2" to p1 + local: + expect /chatroom-message-new $room1_p1 room first_room from Owner1 text (.*)/ from p1 capture msg + guard (msg == "message2") + + # Subscribe to chatroom + + send "chatroom-subscribe $room1_p2" to p2 + expect /chatroom-watched-updated [a-z0-9#]+ first_room sub true .*/ from p2 + with p2: + expect /chatroom-message-new $room1_p2 room first_room from Owner1 text (.*)/ capture msg + guard (msg == "message1") + with p2: + expect /chatroom-message-new $room1_p2 room first_room from Owner1 text (.*)/ capture msg + guard (msg == "message2") + + send "chatroom-message-send $room1_p2 message3" to p2 + for p in [ p1, p2 ]: + with p: + expect /chatroom-message-new [a-z0-9#]+ room first_room from Owner2 text message3/ + + send "chatroom-message-send $room1_p1 message4" to p1 + for p in [ p1, p2 ]: + with p: + expect /chatroom-message-new [a-z0-9#]+ room first_room from Owner1 text message4/ + + # Multiple rooms + + send "chatroom-create second_room" to p1 + expect /chatroom-create-done ([a-z0-9#]+) second_room.*/ from p1 capture room2_p1 + + send "chatroom-create third_room" to p2 + expect /chatroom-create-done ([a-z0-9#]+) third_room.*/ from p2 capture room3_p2 + + expect /chatroom-watched-added $room2_p1 second_room sub true/ from p1 + expect /chatroom-watched-added $room3_p2 third_room sub true/ from p2 + expect /chatroom-watched-added ([a-z0-9#]+) second_room sub false/ from p2 capture room2_p2 + expect /chatroom-watched-added ([a-z0-9#]+) third_room sub false/ from p1 capture room3_p1 + + spawn as p3 + send "create-identity Device3 Owner3" to p3 + send "chatroom-watch-local" to p3 + send "start-server services $services" to p3 + expect /chatroom-watched-added ([a-z0-9#]+) first_room sub false/ from p3 capture room1_p3 + expect /chatroom-watched-added ([a-z0-9#]+) second_room sub false/ from p3 capture room2_p3 + expect /chatroom-watched-added ([a-z0-9#]+) third_room sub false/ from p3 capture room3_p3 + + with p3: + for room in [ room1_p3, room2_p3, room3_p3 ]: + send "chatroom-subscribe $room" + expect /chatroom-watched-updated $room [a-z_]+ sub true .*/ + for i in [1..4]: + expect /chatroom-message-new $room1_p3 room first_room from Owner. text (.*)/ capture message + guard (message == "message$i") + + with p2: + send "chatroom-message-send $room2_p2 msg_r2_1" + send "chatroom-message-send $room2_p2 msg_r2_2" + send "chatroom-message-send $room2_p2 msg_r2_3" + expect /chatroom-message-new $room2_p2 room second_room from Owner2 text msg_r2_1/ + expect /chatroom-message-new $room2_p2 room second_room from Owner2 text msg_r2_2/ + expect /chatroom-message-new $room2_p2 room second_room from Owner2 text msg_r2_3/ + + send "chatroom-message-send $room3_p2 msg_r3_1" + send "chatroom-message-send $room3_p2 msg_r3_2" + send "chatroom-message-send $room3_p2 msg_r3_3" + expect /chatroom-message-new $room3_p2 room third_room from Owner2 text msg_r3_1/ + expect /chatroom-message-new $room3_p2 room third_room from Owner2 text msg_r3_2/ + expect /chatroom-message-new $room3_p2 room third_room from Owner2 text msg_r3_3/ + + with p1: + local: + expect /chatroom-message-new [a-z0-9#]+ room ([a-z_]+) from Owner2 text ([a-z0-9_]+)/ capture room, message + guard (room == "second_room") + guard (message == "msg_r2_1") + local: + expect /chatroom-message-new [a-z0-9#]+ room ([a-z_]+) from Owner2 text ([a-z0-9_]+)/ capture room, message + guard (room == "second_room") + guard (message == "msg_r2_2") + local: + expect /chatroom-message-new [a-z0-9#]+ room ([a-z_]+) from Owner2 text ([a-z0-9_]+)/ capture room, message + guard (room == "second_room") + guard (message == "msg_r2_3") + + with p3: + expect /chatroom-message-new $room2_p3 room second_room from Owner2 text msg_r2_1/ + expect /chatroom-message-new $room2_p3 room second_room from Owner2 text msg_r2_2/ + expect /chatroom-message-new $room2_p3 room second_room from Owner2 text msg_r2_3/ + expect /chatroom-message-new $room3_p3 room third_room from Owner2 text msg_r3_1/ + expect /chatroom-message-new $room3_p3 room third_room from Owner2 text msg_r3_2/ + expect /chatroom-message-new $room3_p3 room third_room from Owner2 text msg_r3_3/ + + # Unsubscribe + + send "chatroom-unsubscribe $room1_p1" to p1 + expect /chatroom-watched-updated $room1_p1 [a-z_]+ sub false .*/ from p1 + send "chatroom-unsubscribe $room1_p3" to p3 + expect /chatroom-watched-updated $room1_p3 [a-z_]+ sub false .*/ from p3 + send "chatroom-unsubscribe $room2_p3" to p3 + expect /chatroom-watched-updated $room2_p3 [a-z_]+ sub false .*/ from p3 + + with p2: + send "chatroom-message-send $room1_p2 msg_r1_4" + expect /chatroom-message-new $room1_p2 room first_room from Owner2 text msg_r1_4/ + + send "chatroom-message-send $room2_p2 msg_r2_4" + expect /chatroom-message-new $room2_p2 room second_room from Owner2 text msg_r2_4/ + + send "chatroom-message-send $room3_p2 msg_r3_4" + expect /chatroom-message-new $room3_p2 room third_room from Owner2 text msg_r3_4/ + + with p1: + local: + expect /chatroom-message-new [a-z0-9#]+ room ([a-z_]+) from Owner2 text ([a-z0-9_]+)/ capture room, message + guard (room == "second_room") + guard (message == "msg_r2_4") + + with p3: + local: + expect /chatroom-message-new [a-z0-9#]+ room ([a-z_]+) from Owner2 text ([a-z0-9_]+)/ capture room, message + guard (room == "third_room") + guard (message == "msg_r3_4") + + +test ChatroomSubscribedBeforeStart: + let services = "chatroom" + + spawn as p1 + spawn as p2 + + send "create-identity Device1 Owner1" to p1 + send "create-identity Device2 Owner2" to p2 + + for p in [ p1, p2 ]: + with p: + send "chatroom-watch-local" + send "start-server services $services" + + send "chatroom-create first_room" to p1 + expect /chatroom-create-done ([a-z0-9#]+) first_room.*/ from p1 capture room1_p1 + + expect /chatroom-watched-added [a-z0-9#]+ first_room sub true/ from p1 + expect /chatroom-watched-added ([a-z0-9#]+) first_room sub false/ from p2 capture room1_p2 + + with p2: + send "chatroom-subscribe $room1_p2" + expect /chatroom-watched-updated [a-z0-9#]+ first_room sub true .*/ + + for p in [p1, p2]: + with p: + send "stop-server" + for p in [p1, p2]: + with p: + expect /stop-server-done/ + for p in [p1, p2]: + with p: + send "start-server services $services" + + send "chatroom-message-send $room1_p1 message1" to p1 + expect /chatroom-message-new $room1_p1 room first_room from Owner1 text message1/ from p1 + expect /chatroom-message-new $room1_p2 room first_room from Owner1 text message1/ from p2 + + send "chatroom-message-send $room1_p2 message2" to p2 + expect /chatroom-message-new $room1_p1 room first_room from Owner2 text message2/ from p1 + expect /chatroom-message-new $room1_p2 room first_room from Owner2 text message2/ from p2 + + +test ParallelThreads: + let services = "chatroom" + + spawn as p1 + spawn as p2 + + send "create-identity Device1 Owner1" to p1 + send "create-identity Device2 Owner2" to p2 + + for p in [ p1, p2 ]: + with p: + send "chatroom-watch-local" + send "start-server services $services" + + send "chatroom-create first_room" to p1 + expect /chatroom-create-done ([a-z0-9#]+) first_room.*/ from p1 capture room1_p1 + + expect /chatroom-watched-added [a-z0-9#]+ first_room sub true/ from p1 + expect /chatroom-watched-added ([a-z0-9#]+) first_room sub false/ from p2 capture room1_p2 + + with p2: + send "chatroom-subscribe $room1_p2" + expect /chatroom-watched-updated [a-z0-9#]+ first_room sub true .*/ + + for p in [p1, p2]: + with p: + send "stop-server" + for p in [p1, p2]: + with p: + expect /stop-server-done/ + + send "chatroom-message-send $room1_p1 message1A" to p1 + send "chatroom-message-send $room1_p1 message1B" to p1 + send "chatroom-message-send $room1_p2 message2A" to p2 + send "chatroom-message-send $room1_p2 message2B" to p2 + with p1: + expect /chatroom-message-new $room1_p1 room first_room from Owner. text message(..)/ capture msg + guard (msg == "1A") + with p1: + expect /chatroom-message-new $room1_p1 room first_room from Owner. text message(..)/ capture msg + guard (msg == "1B") + with p2: + expect /chatroom-message-new $room1_p2 room first_room from Owner. text message(..)/ capture msg + guard (msg == "2A") + with p2: + expect /chatroom-message-new $room1_p2 room first_room from Owner. text message(..)/ capture msg + guard (msg == "2B") + + for p in [p1, p2]: + with p: + send "start-server services $services" + + with p1: + expect /chatroom-message-new $room1_p1 room first_room from Owner. text message(..)/ capture msg + guard (msg == "2A") + with p1: + expect /chatroom-message-new $room1_p1 room first_room from Owner. text message(..)/ capture msg + guard (msg == "2B") + with p2: + expect /chatroom-message-new $room1_p2 room first_room from Owner. text message(..)/ capture msg + guard (msg == "1A") + with p2: + expect /chatroom-message-new $room1_p2 room first_room from Owner. text message(..)/ capture msg + guard (msg == "1B") + + +test ChatroomMembers: + let services = "chatroom" + + spawn as p1 + spawn as p2 + spawn as p3 + + send "create-identity Device1 Owner1" to p1 + send "create-identity Device2 Owner2" to p2 + send "create-identity Device3 Owner3" to p3 + + for p in [ p1, p2, p3 ]: + with p: + send "chatroom-watch-local" + send "start-server services $services" + + send "chatroom-create first_room" to p1 + expect /chatroom-create-done ([a-z0-9#]+) first_room.*/ from p1 capture room1_p1 + + expect /chatroom-watched-added $room1_p1 first_room sub true/ from p1 + expect /chatroom-watched-added ([a-z0-9#]+) first_room sub false/ from p2 capture room1_p2 + expect /chatroom-watched-added ([a-z0-9#]+) first_room sub false/ from p3 capture room1_p3 + + local: + send "chatroom-members $room1_p1" to p1 + expect /chatroom-members-([a-z]+)/ from p1 capture done + guard (done == "done") + local: + send "chatroom-members $room1_p2" to p2 + expect /chatroom-members-([a-z]+)/ from p2 capture done + guard (done == "done") + + send "chatroom-message-send $room1_p1 message1" to p1 + send "chatroom-message-send $room1_p1 message2" to p1 + send "chatroom-join $room1_p2" to p2 + send "chatroom-message-send $room1_p2 message3" to p2 + send "chatroom-join $room1_p3" to p3 + + with p1: + expect /chatroom-message-new $room1_p1 room first_room from Owner1 text message2/ + expect /chatroom-message-new $room1_p1 room first_room from Owner2 text message3/ + expect /chatroom-message-new $room1_p1 room first_room from Owner3/ + with p2: + expect /chatroom-message-new $room1_p2 room first_room from Owner1 text message2/ + expect /chatroom-message-new $room1_p2 room first_room from Owner2 text message3/ + expect /chatroom-message-new $room1_p2 room first_room from Owner3/ + with p3: + expect /chatroom-message-new $room1_p3 room first_room from Owner1 text message2/ + expect /chatroom-message-new $room1_p3 room first_room from Owner2 text message3/ + expect /chatroom-message-new $room1_p3 room first_room from Owner3/ + + local: + send "chatroom-members $room1_p1" to p1 + expect /chatroom-members-item Owner1/ from p1 + expect /chatroom-members-item Owner2/ from p1 + expect /chatroom-members-item Owner3/ from p1 + expect /chatroom-members-([a-z]+)/ from p1 capture done + guard (done == "done") + local: + send "chatroom-members $room1_p2" to p2 + expect /chatroom-members-item Owner1/ from p2 + expect /chatroom-members-item Owner2/ from p2 + expect /chatroom-members-item Owner3/ from p2 + expect /chatroom-members-([a-z]+)/ from p2 capture done + guard (done == "done") + + send "chatroom-leave $room1_p1" to p1 + send "chatroom-leave $room1_p3" to p3 + + for p in [ p1, p2 ]: + with p: + expect /chatroom-message-new [a-z0-9#]+ room first_room from Owner1 leave/ + + for p in [ p2, p3 ]: + with p: + expect /chatroom-message-new [a-z0-9#]+ room first_room from Owner3 leave/ + + send "chatroom-members $room1_p1" to p1 + send "chatroom-members $room1_p2" to p2 + send "chatroom-members $room1_p3" to p3 + for p in [ p1, p2, p3 ]: + with p: + expect /chatroom-members-item Owner2/ + expect /chatroom-members-([a-z]+)/ capture done + guard (done == "done") + + +test ChatroomIdentity: + let services = "chatroom" + + spawn as p1 + spawn as p2 + + send "create-identity Device1 Owner1" to p1 + send "create-identity Device2 Owner2" to p2 + + for p in [ p1, p2 ]: + with p: + send "chatroom-watch-local" + send "start-server services $services" + + send "chatroom-create first_room" to p1 + expect /chatroom-create-done ([a-z0-9#]+) first_room.*/ from p1 capture room1_p1 + expect /chatroom-watched-added ([a-z0-9#]+) first_room sub false/ from p2 capture room1_p2 + + send "chatroom-join-as $room1_p1 Custom1" to p1 + expect /chatroom-join-as-done $room1_p1/ from p1 + send "chatroom-join-as $room1_p2 Custom2" to p2 + expect /chatroom-join-as-done $room1_p2/ from p2 + + send "chatroom-message-send $room1_p1 message1" to p1 + send "chatroom-message-send $room1_p2 message2" to p2 + + for p in [ p1, p2 ]: + with p: + expect /chatroom-message-new [a-z0-9#]+ room first_room from ([^ ]+) text message1/ capture name1 + guard (name1 == "Custom1") + expect /chatroom-message-new [a-z0-9#]+ room first_room from ([^ ]+) text message2/ capture name2 + guard (name2 == "Custom2") + + spawn as p1b on p1.node + spawn as p2b on p2.node + for p in [ p1b, p2b ]: + with p: + send "chatroom-watch-local" + + send "chatroom-message-send $room1_p1 message3" to p1b + send "chatroom-message-send $room1_p2 message4" to p2b + + for p in [ p1, p2, p1b, p2b ]: + with p: + expect /chatroom-message-new [a-z0-9#]+ room first_room from ([^ ]+) text message3/ capture name1 + guard (name1 == "Custom1") + expect /chatroom-message-new [a-z0-9#]+ room first_room from ([^ ]+) text message4/ capture name2 + guard (name2 == "Custom2") + + +test ChatroomDelete: + let services = "chatroom" + + node n1 + node n2 + node n3 + + # Create and sync chatrooms on n1 and sync to n2 + local: + spawn as p1 on n1 + with p1: + send "create-identity Device1 Owner1" + expect /create-identity-done .*/ + + send "chatroom-watch-local" + send "start-server services $services" + + send "chatroom-create first" + send "chatroom-create second" + expect /chatroom-create-done $refpat first.*/ + expect /chatroom-create-done $refpat second.*/ + + + spawn as p2 on n2 + with p2: + send "create-identity Device2 Owner2" + expect /create-identity-done .*/ + + send "chatroom-watch-local" + send "start-server services $services" + + expect /chatroom-watched-added ($refpat) first sub false/ capture first + expect /chatroom-watched-added ($refpat) second sub false/ capture second + + send "chatroom-subscribe $first" + send "chatroom-subscribe $second" + expect /chatroom-watched-updated $first first sub true .*/ + expect /chatroom-watched-updated $second second sub true .*/ + + local: + spawn as p3 on n3 + with p3: + send "create-identity Device3 Owner3" + expect /create-identity-done .*/ + + local: + spawn as p1 on n1 + spawn as p2 on n2 + spawn as p3 on n3 + + # Delete first chatroom from n1 + with p1: + send "chatroom-watch-local" + send "start-server services $services" + + send "chatroom-list-local" + expect /chatroom-list-item ($refpat) first sub true/ capture first + expect /chatroom-list-item $refpat second sub true/ + local: + expect /chatroom-list-(.*)/ capture done + guard (done == "done") + + send "chatroom-delete $first" + expect /chatroom-delete-done .*/ + + # Setup n3 + with p3: + send "chatroom-watch-local" + send "start-server services $services" + + expect /chatroom-watched-added $refpat second sub false/ + + # Check that both n1 and n3 see only the second chatroom + for p in [ p1, p3 ]: + with p: + send "chatroom-list-local" + expect /chatroom-list-item $refpat second .*/ + local: + expect /chatroom-list-(.*)/ capture done + guard (done == "done") + + # Reactive server on n2 and create third chatroom + with p2: + send "chatroom-watch-local" + send "start-server services $services" + + send "chatroom-create third" + expect /chatroom-create-done $refpat third.*/ + + # Verify that first chatroom appears only on n3 ... + with p3: + expect /chatroom-watched-added $refpat first sub false/ + expect /chatroom-watched-added $refpat third sub false/ + + send "chatroom-list-local" + expect /chatroom-list-item $refpat first .*/ + expect /chatroom-list-item $refpat second .*/ + expect /chatroom-list-item $refpat third .*/ + local: + expect /chatroom-list-(.*)/ capture done + guard (done == "done") + + # ... and not on n1 + with p1: + expect /chatroom-watched-added ($refpat) third sub false/ capture third + send "chatroom-subscribe $third" + expect /chatroom-watched-updated $third third sub true .*/ + + send "chatroom-list-local" + expect /chatroom-list-item $refpat second .*/ + expect /chatroom-list-item $refpat third .*/ + local: + expect /chatroom-list-(.*)/ capture done + guard (done == "done") + + # Delete second chatroom on n2 + with p2: + send "chatroom-list-local" + expect /chatroom-list-item $refpat first .*/ + expect /chatroom-list-item ($refpat) second .*/ capture second + expect /chatroom-list-item $refpat third .*/ + local: + expect /chatroom-list-(.*)/ capture done + guard (done == "done") + + send "chatroom-delete $second" + expect /chatroom-delete-done .*/ + + # Send messages + with p3: + send "chatroom-list-local" + expect /chatroom-list-item ($refpat) first .*/ capture first + expect /chatroom-list-item ($refpat) second .*/ capture second + expect /chatroom-list-item ($refpat) third .*/ capture third + local: + expect /chatroom-list-(.*)/ capture done + guard (done == "done") + + send "chatroom-message-send $first message_first" + send "chatroom-message-send $second message_second" + send "chatroom-message-send $third message_third" + + # Receive only to non-deleted ones + with p1: + expect /chatroom-message-new $refpat room second from Owner3 text message_second/ + expect /chatroom-message-new $refpat room ([a-z]+) from Owner3 text ([a-z_]+)/ capture room, msg + guard (room == "third") + guard (msg == "message_third") + + send "chatroom-list-local" + expect /chatroom-list-item $refpat second .*/ + expect /chatroom-list-item $refpat third .*/ + local: + expect /chatroom-list-(.*)/ capture done + guard (done == "done") + with p2: + expect /chatroom-message-new $refpat room first from Owner3 text message_first/ + expect /chatroom-message-new $refpat room ([a-z]+) from Owner3 text ([a-z_]+)/ capture room, msg + guard (room == "third") + guard (msg == "message_third") + + send "chatroom-list-local" + expect /chatroom-list-item $refpat first .*/ + expect /chatroom-list-item $refpat third .*/ + local: + expect /chatroom-list-(.*)/ capture done + guard (done == "done") diff --git a/chatroom.test b/chatroom.test deleted file mode 100644 index 54f9b2a..0000000 --- a/chatroom.test +++ /dev/null @@ -1,662 +0,0 @@ -def refpat = /blake2#[0-9a-f]+/ - -test ChatroomSetup: - let services = "chatroom" - - # Local chatrooms - - spawn as p1 - with p1: - send "create-identity Device1 Owner1" - - send "chatroom-create first" - send "chatroom-create second" - - send "chatroom-list-local" - - expect /chatroom-list-item ([a-z0-9#]+) first sub true/ capture first - expect /chatroom-list-item [a-z0-9#]+ second sub true/ - local: - expect /chatroom-list-(.*)/ capture done - guard (done == "done") - - expect /chatroom-create-done ([a-z0-9#]+) first.*/ from p1 capture first - expect /chatroom-create-done ([a-z0-9#]+) second.*/ from p1 capture second - - # Send chatrooms to new peers - - spawn as p2 - send "create-identity Device2 Owner2" to p2 - - spawn as p3 - send "create-identity Device3 Owner3" to p3 - - for p in [ p1, p2, p3 ]: - with p: - send "chatroom-watch-local" - send "start-server services $services" - - for p in [ p2, p3 ]: - with p: - expect /chatroom-watched-added [a-z0-9#]+ first sub false/ - expect /chatroom-watched-added [a-z0-9#]+ second sub false/ - - # Subscribe and unsubscribe - - with p1: - send "chatroom-unsubscribe $first" - expect /chatroom-watched-updated [a-z0-9#]+ first sub false .*/ - - send "chatroom-subscribe $first" - expect /chatroom-watched-updated [a-z0-9#]+ first sub true .*/ - - with p2: - send "chatroom-list-local" - expect /chatroom-list-item ([a-z0-9#]+) first sub false/ capture p2_first - expect /chatroom-list-item ([a-z0-9#]+) second sub false/ capture p2_second - local: - expect /chatroom-list-(.*)/ capture done - guard (done == "done") - - send "chatroom-subscribe $p2_first" - send "chatroom-subscribe $p2_second" - - expect /chatroom-watched-updated [a-z0-9#]+ first sub true .*/ - expect /chatroom-watched-updated [a-z0-9#]+ second sub true .*/ - - send "chatroom-unsubscribe $p2_first" - send "chatroom-unsubscribe $p2_second" - - expect /chatroom-watched-updated [a-z0-9#]+ first sub false .*/ - expect /chatroom-watched-updated [a-z0-9#]+ second sub false .*/ - - # Create and sync additional chatrooms - - send "chatroom-create third" to p1 - send "chatroom-create fourth" to p2 - send "chatroom-create fifth" to p3 - - expect /chatroom-create-done ([a-z0-9#]+) fourth.*/ from p2 capture fourth - expect /chatroom-create-done ([a-z0-9#]+) fifth.*/ from p3 capture fifth - - for p in [ p1, p2, p3 ]: - with p: - expect /chatroom-watched-added [a-z0-9#]+ third sub [a-z]+/ - expect /chatroom-watched-added [a-z0-9#]+ fourth sub [a-z]+/ - expect /chatroom-watched-added [a-z0-9#]+ fifth sub [a-z]+/ - - # Update chatroom name - - send "chatroom-set-name $first first2" to p1 - for p in [ p1, p2, p3 ]: - with p: - expect /chatroom-watched-updated [a-z0-9#]+ first2.*/ - - send "chatroom-set-name $fourth fourth2" to p2 - send "chatroom-set-name $fifth fifth2" to p3 - for p in [ p1, p2, p3 ]: - with p: - expect /chatroom-watched-updated [a-z0-9#]+ fourth2.*/ - expect /chatroom-watched-updated [a-z0-9#]+ fifth2.*/ - - -test ChatroomMessages: - let services = "chatroom" - - spawn as p1 - spawn as p2 - - send "create-identity Device1 Owner1" to p1 - send "create-identity Device2 Owner2" to p2 - - for p in [ p1, p2 ]: - with p: - send "chatroom-watch-local" - send "start-server services $services" - - send "chatroom-create first_room" to p1 - expect /chatroom-create-done ([a-z0-9#]+) first_room.*/ from p1 capture room1_p1 - - expect /chatroom-watched-added [a-z0-9#]+ first_room sub true/ from p1 - expect /chatroom-watched-added ([a-z0-9#]+) first_room sub false/ from p2 capture room1_p2 - - send "chatroom-message-send $room1_p1 message1" to p1 - expect /chatroom-message-new $room1_p1 room first_room from Owner1 text message1/ from p1 - - send "chatroom-message-send $room1_p1 message2" to p1 - local: - expect /chatroom-message-new $room1_p1 room first_room from Owner1 text (.*)/ from p1 capture msg - guard (msg == "message2") - - # Subscribe to chatroom - - send "chatroom-subscribe $room1_p2" to p2 - expect /chatroom-watched-updated [a-z0-9#]+ first_room sub true .*/ from p2 - with p2: - expect /chatroom-message-new $room1_p2 room first_room from Owner1 text (.*)/ capture msg - guard (msg == "message1") - with p2: - expect /chatroom-message-new $room1_p2 room first_room from Owner1 text (.*)/ capture msg - guard (msg == "message2") - - send "chatroom-message-send $room1_p2 message3" to p2 - for p in [ p1, p2 ]: - with p: - expect /chatroom-message-new [a-z0-9#]+ room first_room from Owner2 text message3/ - - send "chatroom-message-send $room1_p1 message4" to p1 - for p in [ p1, p2 ]: - with p: - expect /chatroom-message-new [a-z0-9#]+ room first_room from Owner1 text message4/ - - # Multiple rooms - - send "chatroom-create second_room" to p1 - expect /chatroom-create-done ([a-z0-9#]+) second_room.*/ from p1 capture room2_p1 - - send "chatroom-create third_room" to p2 - expect /chatroom-create-done ([a-z0-9#]+) third_room.*/ from p2 capture room3_p2 - - expect /chatroom-watched-added $room2_p1 second_room sub true/ from p1 - expect /chatroom-watched-added $room3_p2 third_room sub true/ from p2 - expect /chatroom-watched-added ([a-z0-9#]+) second_room sub false/ from p2 capture room2_p2 - expect /chatroom-watched-added ([a-z0-9#]+) third_room sub false/ from p1 capture room3_p1 - - spawn as p3 - send "create-identity Device3 Owner3" to p3 - send "chatroom-watch-local" to p3 - send "start-server services $services" to p3 - expect /chatroom-watched-added ([a-z0-9#]+) first_room sub false/ from p3 capture room1_p3 - expect /chatroom-watched-added ([a-z0-9#]+) second_room sub false/ from p3 capture room2_p3 - expect /chatroom-watched-added ([a-z0-9#]+) third_room sub false/ from p3 capture room3_p3 - - with p3: - for room in [ room1_p3, room2_p3, room3_p3 ]: - send "chatroom-subscribe $room" - expect /chatroom-watched-updated $room [a-z_]+ sub true .*/ - for i in [1..4]: - expect /chatroom-message-new $room1_p3 room first_room from Owner. text (.*)/ capture message - guard (message == "message$i") - - with p2: - send "chatroom-message-send $room2_p2 msg_r2_1" - send "chatroom-message-send $room2_p2 msg_r2_2" - send "chatroom-message-send $room2_p2 msg_r2_3" - expect /chatroom-message-new $room2_p2 room second_room from Owner2 text msg_r2_1/ - expect /chatroom-message-new $room2_p2 room second_room from Owner2 text msg_r2_2/ - expect /chatroom-message-new $room2_p2 room second_room from Owner2 text msg_r2_3/ - - send "chatroom-message-send $room3_p2 msg_r3_1" - send "chatroom-message-send $room3_p2 msg_r3_2" - send "chatroom-message-send $room3_p2 msg_r3_3" - expect /chatroom-message-new $room3_p2 room third_room from Owner2 text msg_r3_1/ - expect /chatroom-message-new $room3_p2 room third_room from Owner2 text msg_r3_2/ - expect /chatroom-message-new $room3_p2 room third_room from Owner2 text msg_r3_3/ - - with p1: - local: - expect /chatroom-message-new [a-z0-9#]+ room ([a-z_]+) from Owner2 text ([a-z0-9_]+)/ capture room, message - guard (room == "second_room") - guard (message == "msg_r2_1") - local: - expect /chatroom-message-new [a-z0-9#]+ room ([a-z_]+) from Owner2 text ([a-z0-9_]+)/ capture room, message - guard (room == "second_room") - guard (message == "msg_r2_2") - local: - expect /chatroom-message-new [a-z0-9#]+ room ([a-z_]+) from Owner2 text ([a-z0-9_]+)/ capture room, message - guard (room == "second_room") - guard (message == "msg_r2_3") - - with p3: - expect /chatroom-message-new $room2_p3 room second_room from Owner2 text msg_r2_1/ - expect /chatroom-message-new $room2_p3 room second_room from Owner2 text msg_r2_2/ - expect /chatroom-message-new $room2_p3 room second_room from Owner2 text msg_r2_3/ - expect /chatroom-message-new $room3_p3 room third_room from Owner2 text msg_r3_1/ - expect /chatroom-message-new $room3_p3 room third_room from Owner2 text msg_r3_2/ - expect /chatroom-message-new $room3_p3 room third_room from Owner2 text msg_r3_3/ - - # Unsubscribe - - send "chatroom-unsubscribe $room1_p1" to p1 - expect /chatroom-watched-updated $room1_p1 [a-z_]+ sub false .*/ from p1 - send "chatroom-unsubscribe $room1_p3" to p3 - expect /chatroom-watched-updated $room1_p3 [a-z_]+ sub false .*/ from p3 - send "chatroom-unsubscribe $room2_p3" to p3 - expect /chatroom-watched-updated $room2_p3 [a-z_]+ sub false .*/ from p3 - - with p2: - send "chatroom-message-send $room1_p2 msg_r1_4" - expect /chatroom-message-new $room1_p2 room first_room from Owner2 text msg_r1_4/ - - send "chatroom-message-send $room2_p2 msg_r2_4" - expect /chatroom-message-new $room2_p2 room second_room from Owner2 text msg_r2_4/ - - send "chatroom-message-send $room3_p2 msg_r3_4" - expect /chatroom-message-new $room3_p2 room third_room from Owner2 text msg_r3_4/ - - with p1: - local: - expect /chatroom-message-new [a-z0-9#]+ room ([a-z_]+) from Owner2 text ([a-z0-9_]+)/ capture room, message - guard (room == "second_room") - guard (message == "msg_r2_4") - - with p3: - local: - expect /chatroom-message-new [a-z0-9#]+ room ([a-z_]+) from Owner2 text ([a-z0-9_]+)/ capture room, message - guard (room == "third_room") - guard (message == "msg_r3_4") - - -test ChatroomSubscribedBeforeStart: - let services = "chatroom" - - spawn as p1 - spawn as p2 - - send "create-identity Device1 Owner1" to p1 - send "create-identity Device2 Owner2" to p2 - - for p in [ p1, p2 ]: - with p: - send "chatroom-watch-local" - send "start-server services $services" - - send "chatroom-create first_room" to p1 - expect /chatroom-create-done ([a-z0-9#]+) first_room.*/ from p1 capture room1_p1 - - expect /chatroom-watched-added [a-z0-9#]+ first_room sub true/ from p1 - expect /chatroom-watched-added ([a-z0-9#]+) first_room sub false/ from p2 capture room1_p2 - - with p2: - send "chatroom-subscribe $room1_p2" - expect /chatroom-watched-updated [a-z0-9#]+ first_room sub true .*/ - - for p in [p1, p2]: - with p: - send "stop-server" - for p in [p1, p2]: - with p: - expect /stop-server-done/ - for p in [p1, p2]: - with p: - send "start-server services $services" - - send "chatroom-message-send $room1_p1 message1" to p1 - expect /chatroom-message-new $room1_p1 room first_room from Owner1 text message1/ from p1 - expect /chatroom-message-new $room1_p2 room first_room from Owner1 text message1/ from p2 - - send "chatroom-message-send $room1_p2 message2" to p2 - expect /chatroom-message-new $room1_p1 room first_room from Owner2 text message2/ from p1 - expect /chatroom-message-new $room1_p2 room first_room from Owner2 text message2/ from p2 - - -test ParallelThreads: - let services = "chatroom" - - spawn as p1 - spawn as p2 - - send "create-identity Device1 Owner1" to p1 - send "create-identity Device2 Owner2" to p2 - - for p in [ p1, p2 ]: - with p: - send "chatroom-watch-local" - send "start-server services $services" - - send "chatroom-create first_room" to p1 - expect /chatroom-create-done ([a-z0-9#]+) first_room.*/ from p1 capture room1_p1 - - expect /chatroom-watched-added [a-z0-9#]+ first_room sub true/ from p1 - expect /chatroom-watched-added ([a-z0-9#]+) first_room sub false/ from p2 capture room1_p2 - - with p2: - send "chatroom-subscribe $room1_p2" - expect /chatroom-watched-updated [a-z0-9#]+ first_room sub true .*/ - - for p in [p1, p2]: - with p: - send "stop-server" - for p in [p1, p2]: - with p: - expect /stop-server-done/ - - send "chatroom-message-send $room1_p1 message1A" to p1 - send "chatroom-message-send $room1_p1 message1B" to p1 - send "chatroom-message-send $room1_p2 message2A" to p2 - send "chatroom-message-send $room1_p2 message2B" to p2 - with p1: - expect /chatroom-message-new $room1_p1 room first_room from Owner. text message(..)/ capture msg - guard (msg == "1A") - with p1: - expect /chatroom-message-new $room1_p1 room first_room from Owner. text message(..)/ capture msg - guard (msg == "1B") - with p2: - expect /chatroom-message-new $room1_p2 room first_room from Owner. text message(..)/ capture msg - guard (msg == "2A") - with p2: - expect /chatroom-message-new $room1_p2 room first_room from Owner. text message(..)/ capture msg - guard (msg == "2B") - - for p in [p1, p2]: - with p: - send "start-server services $services" - - with p1: - expect /chatroom-message-new $room1_p1 room first_room from Owner. text message(..)/ capture msg - guard (msg == "2A") - with p1: - expect /chatroom-message-new $room1_p1 room first_room from Owner. text message(..)/ capture msg - guard (msg == "2B") - with p2: - expect /chatroom-message-new $room1_p2 room first_room from Owner. text message(..)/ capture msg - guard (msg == "1A") - with p2: - expect /chatroom-message-new $room1_p2 room first_room from Owner. text message(..)/ capture msg - guard (msg == "1B") - - -test ChatroomMembers: - let services = "chatroom" - - spawn as p1 - spawn as p2 - spawn as p3 - - send "create-identity Device1 Owner1" to p1 - send "create-identity Device2 Owner2" to p2 - send "create-identity Device3 Owner3" to p3 - - for p in [ p1, p2, p3 ]: - with p: - send "chatroom-watch-local" - send "start-server services $services" - - send "chatroom-create first_room" to p1 - expect /chatroom-create-done ([a-z0-9#]+) first_room.*/ from p1 capture room1_p1 - - expect /chatroom-watched-added $room1_p1 first_room sub true/ from p1 - expect /chatroom-watched-added ([a-z0-9#]+) first_room sub false/ from p2 capture room1_p2 - expect /chatroom-watched-added ([a-z0-9#]+) first_room sub false/ from p3 capture room1_p3 - - local: - send "chatroom-members $room1_p1" to p1 - expect /chatroom-members-([a-z]+)/ from p1 capture done - guard (done == "done") - local: - send "chatroom-members $room1_p2" to p2 - expect /chatroom-members-([a-z]+)/ from p2 capture done - guard (done == "done") - - send "chatroom-message-send $room1_p1 message1" to p1 - send "chatroom-message-send $room1_p1 message2" to p1 - send "chatroom-join $room1_p2" to p2 - send "chatroom-message-send $room1_p2 message3" to p2 - send "chatroom-join $room1_p3" to p3 - - with p1: - expect /chatroom-message-new $room1_p1 room first_room from Owner1 text message2/ - expect /chatroom-message-new $room1_p1 room first_room from Owner2 text message3/ - expect /chatroom-message-new $room1_p1 room first_room from Owner3/ - with p2: - expect /chatroom-message-new $room1_p2 room first_room from Owner1 text message2/ - expect /chatroom-message-new $room1_p2 room first_room from Owner2 text message3/ - expect /chatroom-message-new $room1_p2 room first_room from Owner3/ - with p3: - expect /chatroom-message-new $room1_p3 room first_room from Owner1 text message2/ - expect /chatroom-message-new $room1_p3 room first_room from Owner2 text message3/ - expect /chatroom-message-new $room1_p3 room first_room from Owner3/ - - local: - send "chatroom-members $room1_p1" to p1 - expect /chatroom-members-item Owner1/ from p1 - expect /chatroom-members-item Owner2/ from p1 - expect /chatroom-members-item Owner3/ from p1 - expect /chatroom-members-([a-z]+)/ from p1 capture done - guard (done == "done") - local: - send "chatroom-members $room1_p2" to p2 - expect /chatroom-members-item Owner1/ from p2 - expect /chatroom-members-item Owner2/ from p2 - expect /chatroom-members-item Owner3/ from p2 - expect /chatroom-members-([a-z]+)/ from p2 capture done - guard (done == "done") - - send "chatroom-leave $room1_p1" to p1 - send "chatroom-leave $room1_p3" to p3 - - for p in [ p1, p2 ]: - with p: - expect /chatroom-message-new [a-z0-9#]+ room first_room from Owner1 leave/ - - for p in [ p2, p3 ]: - with p: - expect /chatroom-message-new [a-z0-9#]+ room first_room from Owner3 leave/ - - send "chatroom-members $room1_p1" to p1 - send "chatroom-members $room1_p2" to p2 - send "chatroom-members $room1_p3" to p3 - for p in [ p1, p2, p3 ]: - with p: - expect /chatroom-members-item Owner2/ - expect /chatroom-members-([a-z]+)/ capture done - guard (done == "done") - - -test ChatroomIdentity: - let services = "chatroom" - - spawn as p1 - spawn as p2 - - send "create-identity Device1 Owner1" to p1 - send "create-identity Device2 Owner2" to p2 - - for p in [ p1, p2 ]: - with p: - send "chatroom-watch-local" - send "start-server services $services" - - send "chatroom-create first_room" to p1 - expect /chatroom-create-done ([a-z0-9#]+) first_room.*/ from p1 capture room1_p1 - expect /chatroom-watched-added ([a-z0-9#]+) first_room sub false/ from p2 capture room1_p2 - - send "chatroom-join-as $room1_p1 Custom1" to p1 - expect /chatroom-join-as-done $room1_p1/ from p1 - send "chatroom-join-as $room1_p2 Custom2" to p2 - expect /chatroom-join-as-done $room1_p2/ from p2 - - send "chatroom-message-send $room1_p1 message1" to p1 - send "chatroom-message-send $room1_p2 message2" to p2 - - for p in [ p1, p2 ]: - with p: - expect /chatroom-message-new [a-z0-9#]+ room first_room from ([^ ]+) text message1/ capture name1 - guard (name1 == "Custom1") - expect /chatroom-message-new [a-z0-9#]+ room first_room from ([^ ]+) text message2/ capture name2 - guard (name2 == "Custom2") - - spawn as p1b on p1.node - spawn as p2b on p2.node - for p in [ p1b, p2b ]: - with p: - send "chatroom-watch-local" - - send "chatroom-message-send $room1_p1 message3" to p1b - send "chatroom-message-send $room1_p2 message4" to p2b - - for p in [ p1, p2, p1b, p2b ]: - with p: - expect /chatroom-message-new [a-z0-9#]+ room first_room from ([^ ]+) text message3/ capture name1 - guard (name1 == "Custom1") - expect /chatroom-message-new [a-z0-9#]+ room first_room from ([^ ]+) text message4/ capture name2 - guard (name2 == "Custom2") - - -test ChatroomDelete: - let services = "chatroom" - - node n1 - node n2 - node n3 - - # Create and sync chatrooms on n1 and sync to n2 - local: - spawn as p1 on n1 - with p1: - send "create-identity Device1 Owner1" - expect /create-identity-done .*/ - - send "chatroom-watch-local" - send "start-server services $services" - - send "chatroom-create first" - send "chatroom-create second" - expect /chatroom-create-done $refpat first.*/ - expect /chatroom-create-done $refpat second.*/ - - - spawn as p2 on n2 - with p2: - send "create-identity Device2 Owner2" - expect /create-identity-done .*/ - - send "chatroom-watch-local" - send "start-server services $services" - - expect /chatroom-watched-added ($refpat) first sub false/ capture first - expect /chatroom-watched-added ($refpat) second sub false/ capture second - - send "chatroom-subscribe $first" - send "chatroom-subscribe $second" - expect /chatroom-watched-updated $first first sub true .*/ - expect /chatroom-watched-updated $second second sub true .*/ - - local: - spawn as p3 on n3 - with p3: - send "create-identity Device3 Owner3" - expect /create-identity-done .*/ - - local: - spawn as p1 on n1 - spawn as p2 on n2 - spawn as p3 on n3 - - # Delete first chatroom from n1 - with p1: - send "chatroom-watch-local" - send "start-server services $services" - - send "chatroom-list-local" - expect /chatroom-list-item ($refpat) first sub true/ capture first - expect /chatroom-list-item $refpat second sub true/ - local: - expect /chatroom-list-(.*)/ capture done - guard (done == "done") - - send "chatroom-delete $first" - expect /chatroom-delete-done .*/ - - # Setup n3 - with p3: - send "chatroom-watch-local" - send "start-server services $services" - - expect /chatroom-watched-added $refpat second sub false/ - - # Check that both n1 and n3 see only the second chatroom - for p in [ p1, p3 ]: - with p: - send "chatroom-list-local" - expect /chatroom-list-item $refpat second .*/ - local: - expect /chatroom-list-(.*)/ capture done - guard (done == "done") - - # Reactive server on n2 and create third chatroom - with p2: - send "chatroom-watch-local" - send "start-server services $services" - - send "chatroom-create third" - expect /chatroom-create-done $refpat third.*/ - - # Verify that first chatroom appears only on n3 ... - with p3: - expect /chatroom-watched-added $refpat first sub false/ - expect /chatroom-watched-added $refpat third sub false/ - - send "chatroom-list-local" - expect /chatroom-list-item $refpat first .*/ - expect /chatroom-list-item $refpat second .*/ - expect /chatroom-list-item $refpat third .*/ - local: - expect /chatroom-list-(.*)/ capture done - guard (done == "done") - - # ... and not on n1 - with p1: - expect /chatroom-watched-added ($refpat) third sub false/ capture third - send "chatroom-subscribe $third" - expect /chatroom-watched-updated $third third sub true .*/ - - send "chatroom-list-local" - expect /chatroom-list-item $refpat second .*/ - expect /chatroom-list-item $refpat third .*/ - local: - expect /chatroom-list-(.*)/ capture done - guard (done == "done") - - # Delete second chatroom on n2 - with p2: - send "chatroom-list-local" - expect /chatroom-list-item $refpat first .*/ - expect /chatroom-list-item ($refpat) second .*/ capture second - expect /chatroom-list-item $refpat third .*/ - local: - expect /chatroom-list-(.*)/ capture done - guard (done == "done") - - send "chatroom-delete $second" - expect /chatroom-delete-done .*/ - - # Send messages - with p3: - send "chatroom-list-local" - expect /chatroom-list-item ($refpat) first .*/ capture first - expect /chatroom-list-item ($refpat) second .*/ capture second - expect /chatroom-list-item ($refpat) third .*/ capture third - local: - expect /chatroom-list-(.*)/ capture done - guard (done == "done") - - send "chatroom-message-send $first message_first" - send "chatroom-message-send $second message_second" - send "chatroom-message-send $third message_third" - - # Receive only to non-deleted ones - with p1: - expect /chatroom-message-new $refpat room second from Owner3 text message_second/ - expect /chatroom-message-new $refpat room ([a-z]+) from Owner3 text ([a-z_]+)/ capture room, msg - guard (room == "third") - guard (msg == "message_third") - - send "chatroom-list-local" - expect /chatroom-list-item $refpat second .*/ - expect /chatroom-list-item $refpat third .*/ - local: - expect /chatroom-list-(.*)/ capture done - guard (done == "done") - with p2: - expect /chatroom-message-new $refpat room first from Owner3 text message_first/ - expect /chatroom-message-new $refpat room ([a-z]+) from Owner3 text ([a-z_]+)/ capture room, msg - guard (room == "third") - guard (msg == "message_third") - - send "chatroom-list-local" - expect /chatroom-list-item $refpat first .*/ - expect /chatroom-list-item $refpat third .*/ - local: - expect /chatroom-list-(.*)/ capture done - guard (done == "done") diff --git a/common.et b/common.et new file mode 100644 index 0000000..89941f0 --- /dev/null +++ b/common.et @@ -0,0 +1,3 @@ +module common + +export def refpat = /blake2#[0-9a-f]*/ diff --git a/common.test b/common.test deleted file mode 100644 index 89941f0..0000000 --- a/common.test +++ /dev/null @@ -1,3 +0,0 @@ -module common - -export def refpat = /blake2#[0-9a-f]*/ diff --git a/contact.et b/contact.et new file mode 100644 index 0000000..978f8a6 --- /dev/null +++ b/contact.et @@ -0,0 +1,202 @@ +test Contact: + let services = "attach,contact,sync" + + spawn as p1 + spawn as p2 + spawn as p3 + spawn as p4 + + send "create-identity Device1 Owner1" to p1 + send "create-identity Device2 Owner2" to p2 + send "create-identity Device3 Owner3" to p3 + send "create-identity Device4" to p4 + + send "start-server services $services" to p1 + send "start-server services $services" to p2 + send "start-server services $services" to p3 + send "start-server services $services" to p4 + + expect from p1: + /peer ([0-9]+) addr ${p2.node.ip} 29665/ capture peer1_2 + /peer $peer1_2 id Device2 Owner2/ + /peer ([0-9]+) addr ${p3.node.ip} 29665/ capture peer1_3 + /peer $peer1_3 id Device3 Owner3/ + /peer ([0-9]+) addr ${p4.node.ip} 29665/ capture peer1_4 + /peer $peer1_4 id Device4/ + + expect from p2: + /peer ([0-9]+) addr ${p1.node.ip} 29665/ capture peer2_1 + /peer $peer2_1 id Device1 Owner1/ + /peer ([0-9]+) addr ${p3.node.ip} 29665/ capture peer2_3 + /peer $peer2_3 id Device3 Owner3/ + /peer ([0-9]+) addr ${p4.node.ip} 29665/ capture peer2_4 + /peer $peer2_4 id Device4/ + + expect from p3: + /peer ([0-9]+) addr ${p1.node.ip} 29665/ capture peer3_1 + /peer $peer3_1 id Device1 Owner1/ + /peer ([0-9]+) addr ${p2.node.ip} 29665/ capture peer3_2 + /peer $peer3_2 id Device2 Owner2/ + /peer ([0-9]+) addr ${p4.node.ip} 29665/ capture peer3_4 + /peer $peer3_4 id Device4/ + + expect from p4: + /peer ([0-9]+) addr ${p1.node.ip} 29665/ capture peer4_1 + /peer $peer4_1 id Device1 Owner1/ + /peer ([0-9]+) addr ${p2.node.ip} 29665/ capture peer4_2 + /peer $peer4_2 id Device2 Owner2/ + /peer ([0-9]+) addr ${p3.node.ip} 29665/ capture peer4_3 + /peer $peer4_3 id Device3 Owner3/ + + # Rejected contacts + + send "contact-request $peer1_2" to p1 + expect /contact-request $peer2_1 [0-9]*/ from p2 + expect /contact-response $peer1_2 [0-9]*/ from p1 + send "contact-reject $peer1_2" to p1 + expect /contact-request-failed $peer2_1 rejected/ from p2 + expect /contact-response-failed $peer1_2 user/ from p1 + + send "contact-request $peer1_2" to p1 + expect /contact-request $peer2_1 [0-9]*/ from p2 + expect /contact-response $peer1_2 [0-9]*/ from p1 + send "contact-reject $peer2_1" to p2 + expect /contact-request-failed $peer2_1 user/ from p2 + expect /contact-response-failed $peer1_2 rejected/ from p1 + + # Contact between 1 and 2 + + local: + send "contact-request $peer1_2" to p1 + expect /contact-request $peer2_1 ([0-9]*)/ from p2 capture code2 + expect /contact-response $peer1_2 ([0-9]*)/ from p1 capture code1 + guard (code1 == code2) + + send "contact-accept $peer1_2" to p1 + send "contact-accept $peer2_1" to p2 + expect /contact-request-done $peer2_1/ from p2 + expect /contact-response-done $peer1_2/ from p1 + + send "contact-list" to p1 + expect from p1: + /contact-list-item [a-z0-9#]+ Owner2 Owner2/ + /contact-list-(.*)/ capture done1_1 + guard (done1_1 == "done") + send "contact-list" to p2 + expect from p2: + /contact-list-item [a-z0-9#]+ Owner1 Owner1/ + /contact-list-(.*)/ capture done1_2 + guard (done1_2 == "done") + + # Attach peer 4 to Owner1 + + send "watch-local-identity" to p4 + expect /local-identity Device4/ from p4 + + send "attach-to $peer4_1" to p4 + local: + expect /attach-request $peer1_4 ([0-9]*)/ from p1 capture code1 + expect /attach-response $peer4_1 ([0-9]*)/ from p4 capture code4 + guard (code1 == code4) + + send "attach-accept $peer1_4" to p1 + send "attach-accept $peer4_1" to p4 + expect /attach-request-done $peer1_4/ from p1 + expect /attach-response-done $peer4_1/ from p4 + expect /local-identity Device4 Owner1/ from p4 + expect /peer $peer1_4 id Device4 Owner1/ from p1 + expect /peer $peer2_4 id Device4 Owner1/ from p2 + expect /peer $peer3_4 id Device4 Owner1/ from p3 + + # Contact between 3 and 4 + + send "contact-request $peer3_4" to p3 + local: + expect /contact-request $peer4_3 ([0-9]*)/ from p4 capture code4 + expect /contact-response $peer3_4 ([0-9]*)/ from p3 capture code3 + guard (code3 == code4) + + send "contact-accept $peer3_4" to p3 + send "contact-accept $peer4_3" to p4 + expect /contact-request-done $peer4_3/ from p4 + expect /contact-response-done $peer3_4/ from p3 + + send "contact-list" to p3 + expect from p3: + /contact-list-item [a-z0-9#]+ Owner1 Owner1/ + /contact-list-(.*)/ capture done2_3 + guard (done2_3 == "done") + + send "shared-state-get" to p1 + expect /shared-state-get (.*)/ from p1 capture s1 + send "shared-state-wait $s1" to p4 + expect /shared-state-wait $s1/ from p4 + + send "contact-list" to p4 + expect from p4: + /contact-list-item ([a-z0-9#]+) Owner2 Owner2/ capture c4_2 + /contact-list-item ([a-z0-9#]+) Owner3 Owner3/ capture c4_3 + /contact-list-(.*)/ capture done2_4 + guard (done2_4 == "done") + + # Check sync between 1 and 4 + + send "shared-state-get" to p4 + expect /shared-state-get (.*)/ from p4 capture s4 + send "shared-state-wait $s4" to p1 + expect /shared-state-wait $s4/ from p1 + + send "contact-list" to p1 + expect from p1: + /contact-list-item ([a-z0-9#]+) Owner2 Owner2/ capture c1_2 + /contact-list-item ([a-z0-9#]+) Owner3 Owner3/ capture c1_3 + /contact-list-(.*)/ capture done2_1 + guard (done2_1 == "done") + + # Update custom name + + send "contact-set-name $c4_2 Custom2" to p4 + expect /contact-set-name-done/ from p4 + + send "contact-list" to p4 + expect from p4: + /contact-list-item $c4_2 Custom2 Owner2/ + /contact-list-item $c4_3 Owner3 Owner3/ + /contact-list-(.*)/ capture done3_4 + guard (done3_4 == "done") + + send "shared-state-get" to p4 + expect /shared-state-get (.*)/ from p4 capture s4b + send "shared-state-wait $s4b" to p1 + expect /shared-state-wait $s4b/ from p1 + + send "contact-list" to p1 + expect from p1: + /contact-list-item $c4_2 Custom2 Owner2/ + /contact-list-item $c4_3 Owner3 Owner3/ + /contact-list-(.*)/ capture done3_1 + guard (done3_1 == "done") + + send "contact-set-name $c1_2 Custom2B" to p1 + expect /contact-set-name-done/ from p1 + send "contact-set-name $c1_3 Custom3B" to p1 + expect /contact-set-name-done/ from p1 + + send "contact-list" to p1 + expect from p1: + /contact-list-item $c1_2 Custom2B Owner2/ + /contact-list-item $c1_3 Custom3B Owner3/ + /contact-list-(.*)/ capture done4_1 + guard (done4_1 == "done") + + send "shared-state-get" to p1 + expect /shared-state-get (.*)/ from p1 capture s1b + send "shared-state-wait $s1b" to p4 + expect /shared-state-wait $s1b/ from p4 + + send "contact-list" to p4 + expect from p4: + /contact-list-item $c4_2 Custom2B Owner2/ + /contact-list-item $c4_3 Custom3B Owner3/ + /contact-list-(.*)/ capture done4_4 + guard (done4_4 == "done") diff --git a/contact.test b/contact.test deleted file mode 100644 index 978f8a6..0000000 --- a/contact.test +++ /dev/null @@ -1,202 +0,0 @@ -test Contact: - let services = "attach,contact,sync" - - spawn as p1 - spawn as p2 - spawn as p3 - spawn as p4 - - send "create-identity Device1 Owner1" to p1 - send "create-identity Device2 Owner2" to p2 - send "create-identity Device3 Owner3" to p3 - send "create-identity Device4" to p4 - - send "start-server services $services" to p1 - send "start-server services $services" to p2 - send "start-server services $services" to p3 - send "start-server services $services" to p4 - - expect from p1: - /peer ([0-9]+) addr ${p2.node.ip} 29665/ capture peer1_2 - /peer $peer1_2 id Device2 Owner2/ - /peer ([0-9]+) addr ${p3.node.ip} 29665/ capture peer1_3 - /peer $peer1_3 id Device3 Owner3/ - /peer ([0-9]+) addr ${p4.node.ip} 29665/ capture peer1_4 - /peer $peer1_4 id Device4/ - - expect from p2: - /peer ([0-9]+) addr ${p1.node.ip} 29665/ capture peer2_1 - /peer $peer2_1 id Device1 Owner1/ - /peer ([0-9]+) addr ${p3.node.ip} 29665/ capture peer2_3 - /peer $peer2_3 id Device3 Owner3/ - /peer ([0-9]+) addr ${p4.node.ip} 29665/ capture peer2_4 - /peer $peer2_4 id Device4/ - - expect from p3: - /peer ([0-9]+) addr ${p1.node.ip} 29665/ capture peer3_1 - /peer $peer3_1 id Device1 Owner1/ - /peer ([0-9]+) addr ${p2.node.ip} 29665/ capture peer3_2 - /peer $peer3_2 id Device2 Owner2/ - /peer ([0-9]+) addr ${p4.node.ip} 29665/ capture peer3_4 - /peer $peer3_4 id Device4/ - - expect from p4: - /peer ([0-9]+) addr ${p1.node.ip} 29665/ capture peer4_1 - /peer $peer4_1 id Device1 Owner1/ - /peer ([0-9]+) addr ${p2.node.ip} 29665/ capture peer4_2 - /peer $peer4_2 id Device2 Owner2/ - /peer ([0-9]+) addr ${p3.node.ip} 29665/ capture peer4_3 - /peer $peer4_3 id Device3 Owner3/ - - # Rejected contacts - - send "contact-request $peer1_2" to p1 - expect /contact-request $peer2_1 [0-9]*/ from p2 - expect /contact-response $peer1_2 [0-9]*/ from p1 - send "contact-reject $peer1_2" to p1 - expect /contact-request-failed $peer2_1 rejected/ from p2 - expect /contact-response-failed $peer1_2 user/ from p1 - - send "contact-request $peer1_2" to p1 - expect /contact-request $peer2_1 [0-9]*/ from p2 - expect /contact-response $peer1_2 [0-9]*/ from p1 - send "contact-reject $peer2_1" to p2 - expect /contact-request-failed $peer2_1 user/ from p2 - expect /contact-response-failed $peer1_2 rejected/ from p1 - - # Contact between 1 and 2 - - local: - send "contact-request $peer1_2" to p1 - expect /contact-request $peer2_1 ([0-9]*)/ from p2 capture code2 - expect /contact-response $peer1_2 ([0-9]*)/ from p1 capture code1 - guard (code1 == code2) - - send "contact-accept $peer1_2" to p1 - send "contact-accept $peer2_1" to p2 - expect /contact-request-done $peer2_1/ from p2 - expect /contact-response-done $peer1_2/ from p1 - - send "contact-list" to p1 - expect from p1: - /contact-list-item [a-z0-9#]+ Owner2 Owner2/ - /contact-list-(.*)/ capture done1_1 - guard (done1_1 == "done") - send "contact-list" to p2 - expect from p2: - /contact-list-item [a-z0-9#]+ Owner1 Owner1/ - /contact-list-(.*)/ capture done1_2 - guard (done1_2 == "done") - - # Attach peer 4 to Owner1 - - send "watch-local-identity" to p4 - expect /local-identity Device4/ from p4 - - send "attach-to $peer4_1" to p4 - local: - expect /attach-request $peer1_4 ([0-9]*)/ from p1 capture code1 - expect /attach-response $peer4_1 ([0-9]*)/ from p4 capture code4 - guard (code1 == code4) - - send "attach-accept $peer1_4" to p1 - send "attach-accept $peer4_1" to p4 - expect /attach-request-done $peer1_4/ from p1 - expect /attach-response-done $peer4_1/ from p4 - expect /local-identity Device4 Owner1/ from p4 - expect /peer $peer1_4 id Device4 Owner1/ from p1 - expect /peer $peer2_4 id Device4 Owner1/ from p2 - expect /peer $peer3_4 id Device4 Owner1/ from p3 - - # Contact between 3 and 4 - - send "contact-request $peer3_4" to p3 - local: - expect /contact-request $peer4_3 ([0-9]*)/ from p4 capture code4 - expect /contact-response $peer3_4 ([0-9]*)/ from p3 capture code3 - guard (code3 == code4) - - send "contact-accept $peer3_4" to p3 - send "contact-accept $peer4_3" to p4 - expect /contact-request-done $peer4_3/ from p4 - expect /contact-response-done $peer3_4/ from p3 - - send "contact-list" to p3 - expect from p3: - /contact-list-item [a-z0-9#]+ Owner1 Owner1/ - /contact-list-(.*)/ capture done2_3 - guard (done2_3 == "done") - - send "shared-state-get" to p1 - expect /shared-state-get (.*)/ from p1 capture s1 - send "shared-state-wait $s1" to p4 - expect /shared-state-wait $s1/ from p4 - - send "contact-list" to p4 - expect from p4: - /contact-list-item ([a-z0-9#]+) Owner2 Owner2/ capture c4_2 - /contact-list-item ([a-z0-9#]+) Owner3 Owner3/ capture c4_3 - /contact-list-(.*)/ capture done2_4 - guard (done2_4 == "done") - - # Check sync between 1 and 4 - - send "shared-state-get" to p4 - expect /shared-state-get (.*)/ from p4 capture s4 - send "shared-state-wait $s4" to p1 - expect /shared-state-wait $s4/ from p1 - - send "contact-list" to p1 - expect from p1: - /contact-list-item ([a-z0-9#]+) Owner2 Owner2/ capture c1_2 - /contact-list-item ([a-z0-9#]+) Owner3 Owner3/ capture c1_3 - /contact-list-(.*)/ capture done2_1 - guard (done2_1 == "done") - - # Update custom name - - send "contact-set-name $c4_2 Custom2" to p4 - expect /contact-set-name-done/ from p4 - - send "contact-list" to p4 - expect from p4: - /contact-list-item $c4_2 Custom2 Owner2/ - /contact-list-item $c4_3 Owner3 Owner3/ - /contact-list-(.*)/ capture done3_4 - guard (done3_4 == "done") - - send "shared-state-get" to p4 - expect /shared-state-get (.*)/ from p4 capture s4b - send "shared-state-wait $s4b" to p1 - expect /shared-state-wait $s4b/ from p1 - - send "contact-list" to p1 - expect from p1: - /contact-list-item $c4_2 Custom2 Owner2/ - /contact-list-item $c4_3 Owner3 Owner3/ - /contact-list-(.*)/ capture done3_1 - guard (done3_1 == "done") - - send "contact-set-name $c1_2 Custom2B" to p1 - expect /contact-set-name-done/ from p1 - send "contact-set-name $c1_3 Custom3B" to p1 - expect /contact-set-name-done/ from p1 - - send "contact-list" to p1 - expect from p1: - /contact-list-item $c1_2 Custom2B Owner2/ - /contact-list-item $c1_3 Custom3B Owner3/ - /contact-list-(.*)/ capture done4_1 - guard (done4_1 == "done") - - send "shared-state-get" to p1 - expect /shared-state-get (.*)/ from p1 capture s1b - send "shared-state-wait $s1b" to p4 - expect /shared-state-wait $s1b/ from p4 - - send "contact-list" to p4 - expect from p4: - /contact-list-item $c4_2 Custom2B Owner2/ - /contact-list-item $c4_3 Custom3B Owner3/ - /contact-list-(.*)/ capture done4_4 - guard (done4_4 == "done") diff --git a/discovery.et b/discovery.et new file mode 100644 index 0000000..e80a755 --- /dev/null +++ b/discovery.et @@ -0,0 +1,218 @@ +module discovery + +def refpat = /blake2#[0-9a-f]*/ + +test ManualDiscovery: + let services = "discovery" + + subnet sd + subnet s1 + subnet s2 + + spawn as pd on sd + spawn as p1 on s1 + spawn as p2 on s2 + send "create-identity Discovery" to pd + send "create-identity Device1 Owner1" to p1 + send "create-identity Device2 Owner2" to p2 + + expect /create-identity-done ref ($refpat).*/ from p1 capture p1id + send "identity-info $p1id" to p1 + expect /identity-info ref $p1id base ($refpat) owner ($refpat).*/ from p1 capture p1base, p1owner + send "identity-info $p1owner" to p1 + expect /identity-info ref $p1owner base ($refpat).*/ from p1 capture p1obase + + expect /create-identity-done ref $refpat.*/ from p2 + expect /create-identity-done ref $refpat.*/ from pd + + # Test discovery using owner and device identities: + for id in [ p1obase, p1base ]: + for p in [ pd, p1, p2 ]: + send "start-server services $services" to p + + for p in [ p1, p2 ]: + with p: + send "peer-add ${pd.node.ip}" + expect: + /peer 1 addr ${pd.node.ip} 29665/ + /peer 1 id Discovery/ + expect from pd: + /peer [12] addr ${p.node.ip} 29665/ + /peer [12] id .*/ + + send "discovery-connect $id" to p2 + + expect from p1: + /peer [0-9]+ addr ${p2.node.ip} 29665/ + /peer [0-9]+ id Device2 Owner2/ + expect from p2: + /peer [0-9]+ addr ${p1.node.ip} 29665/ + /peer [0-9]+ id Device1 Owner1/ + + for p in [ pd, p1, p2 ]: + send "stop-server" to p + for p in [ pd, p1, p2 ]: + expect /stop-server-done/ from p + + # Test delayed discovery with new peer + for id in [ p1obase ]: + for p in [ pd, p1, p2 ]: + send "start-server services $services" to p + + with p1: + send "peer-add ${pd.node.ip}" + expect: + /peer 1 addr ${pd.node.ip} 29665/ + /peer 1 id Discovery/ + expect from pd: + /peer [12] addr ${p1.node.ip} 29665/ + /peer [12] id Device1 Owner1/ + + send "discovery-connect $id" to p2 + + with p2: + send "peer-add ${pd.node.ip}" + expect: + /peer 1 addr ${pd.node.ip} 29665/ + /peer 1 id Discovery/ + expect from pd: + /peer [12] addr ${p2.node.ip} 29665/ + /peer [12] id Device2 Owner2/ + + expect from p1: + /peer [0-9]+ addr ${p2.node.ip} 29665/ + /peer [0-9]+ id Device2 Owner2/ + expect from p2: + /peer [0-9]+ addr ${p1.node.ip} 29665/ + /peer [0-9]+ id Device1 Owner1/ + + for p in [ pd, p1, p2 ]: + send "stop-server" to p + for p in [ pd, p1, p2 ]: + expect /stop-server-done/ from p + + +test DiscoveryTunnel: + let services = "discovery:tunnel" + + subnet sd + subnet s1 + subnet s2 + + spawn as pd on sd + spawn as p1 on s1 + spawn as p2 on s2 + + for n in [ p1.node, p2.node ]: + shell on n: + nft add table inet filter + nft add chain inet filter input '{ type filter hook input priority filter ; policy drop; }' + nft add rule inet filter input 'ct state { established, related } accept' + + send "create-identity Discovery" to pd + send "create-identity Device1 Owner1" to p1 + send "create-identity Device2 Owner2" to p2 + + expect /create-identity-done ref ($refpat).*/ from p1 capture p1id + send "identity-info $p1id" to p1 + expect /identity-info ref $p1id base ($refpat) owner ($refpat).*/ from p1 capture p1base, p1owner + send "identity-info $p1owner" to p1 + expect /identity-info ref $p1owner base ($refpat).*/ from p1 capture p1obase + + expect /create-identity-done ref $refpat.*/ from p2 + expect /create-identity-done ref $refpat.*/ from pd + + for id in [ p1obase ]: + for p in [ pd, p1, p2 ]: + send "start-server services $services test-log" to p + + for p in [ p1, p2 ]: + with p: + send "peer-add ${pd.node.ip}" + expect: + /peer 1 addr ${pd.node.ip} 29665/ + /peer 1 id Discovery/ + expect from pd: + /peer [12] addr ${p.node.ip} 29665/ + /peer [12] id .*/ + + send "discovery-tunnel 1 $id" to p2 + + expect /net-ostream-open ${pd.node.ip} 29665 1 1/ from p2 + expect /net-ostream-open ${p1.node.ip} 29665 1 1/ from pd + expect /net-ostream-open ${pd.node.ip} 29665 1 1/ from p1 + expect /net-ostream-open ${p2.node.ip} 29665 1 1/ from pd + + expect from p1: + /peer 2 addr tunnel@.*/ + /peer 2 id Device2 Owner2/ + expect from p2: + /peer 2 addr tunnel@.*/ + /peer 2 id Device1 Owner1/ + + send "peer-drop 2" to p1 + send "peer-drop 2" to p2 + + expect /net-ostream-close-ack ${pd.node.ip} 29665 1 0/ from p2 + expect /net-ostream-close-ack ${p1.node.ip} 29665 1 0/ from pd + expect /net-ostream-close-ack ${pd.node.ip} 29665 1 0/ from p1 + expect /net-ostream-close-ack ${p2.node.ip} 29665 1 0/ from pd + + for p in [ pd, p1, p2 ]: + send "stop-server" to p + for p in [ pd, p1, p2 ]: + expect /stop-server-done/ from p + + +test DiscoveryTunnelRefused: + let services = "discovery" + + subnet sd + subnet s1 + subnet s2 + + spawn as pd on sd + spawn as p1 on s1 + spawn as p2 on s2 + + for n in [ p1.node, p2.node ]: + shell on n: + nft add table inet filter + nft add chain inet filter input '{ type filter hook input priority filter ; policy drop; }' + nft add rule inet filter input 'ct state { established, related } accept' + + send "create-identity Discovery" to pd + send "create-identity Device1 Owner1" to p1 + send "create-identity Device2 Owner2" to p2 + + expect /create-identity-done ref ($refpat).*/ from p1 capture p1id + send "identity-info $p1id" to p1 + expect /identity-info ref $p1id base ($refpat) owner ($refpat).*/ from p1 capture p1base, p1owner + send "identity-info $p1owner" to p1 + expect /identity-info ref $p1owner base ($refpat).*/ from p1 capture p1obase + + expect /create-identity-done ref $refpat.*/ from p2 + expect /create-identity-done ref $refpat.*/ from pd + + for id in [ p1obase ]: + for p in [ pd, p1, p2 ]: + send "start-server services $services test-log" to p + + for p in [ p1, p2 ]: + with p: + send "peer-add ${pd.node.ip}" + expect: + /peer 1 addr ${pd.node.ip} 29665/ + /peer 1 id Discovery/ + expect from pd: + /peer [12] addr ${p.node.ip} 29665/ + /peer [12] id .*/ + + send "discovery-tunnel 1 $id" to p2 + expect /net-ostream-open ${pd.node.ip} 29665 1 1/ from p2 + expect /net-ostream-close-ack ${pd.node.ip} 29665 1 0/ from p2 + + for p in [ pd, p1, p2 ]: + send "stop-server" to p + for p in [ pd, p1, p2 ]: + expect /stop-server-done/ from p diff --git a/discovery.test b/discovery.test deleted file mode 100644 index e80a755..0000000 --- a/discovery.test +++ /dev/null @@ -1,218 +0,0 @@ -module discovery - -def refpat = /blake2#[0-9a-f]*/ - -test ManualDiscovery: - let services = "discovery" - - subnet sd - subnet s1 - subnet s2 - - spawn as pd on sd - spawn as p1 on s1 - spawn as p2 on s2 - send "create-identity Discovery" to pd - send "create-identity Device1 Owner1" to p1 - send "create-identity Device2 Owner2" to p2 - - expect /create-identity-done ref ($refpat).*/ from p1 capture p1id - send "identity-info $p1id" to p1 - expect /identity-info ref $p1id base ($refpat) owner ($refpat).*/ from p1 capture p1base, p1owner - send "identity-info $p1owner" to p1 - expect /identity-info ref $p1owner base ($refpat).*/ from p1 capture p1obase - - expect /create-identity-done ref $refpat.*/ from p2 - expect /create-identity-done ref $refpat.*/ from pd - - # Test discovery using owner and device identities: - for id in [ p1obase, p1base ]: - for p in [ pd, p1, p2 ]: - send "start-server services $services" to p - - for p in [ p1, p2 ]: - with p: - send "peer-add ${pd.node.ip}" - expect: - /peer 1 addr ${pd.node.ip} 29665/ - /peer 1 id Discovery/ - expect from pd: - /peer [12] addr ${p.node.ip} 29665/ - /peer [12] id .*/ - - send "discovery-connect $id" to p2 - - expect from p1: - /peer [0-9]+ addr ${p2.node.ip} 29665/ - /peer [0-9]+ id Device2 Owner2/ - expect from p2: - /peer [0-9]+ addr ${p1.node.ip} 29665/ - /peer [0-9]+ id Device1 Owner1/ - - for p in [ pd, p1, p2 ]: - send "stop-server" to p - for p in [ pd, p1, p2 ]: - expect /stop-server-done/ from p - - # Test delayed discovery with new peer - for id in [ p1obase ]: - for p in [ pd, p1, p2 ]: - send "start-server services $services" to p - - with p1: - send "peer-add ${pd.node.ip}" - expect: - /peer 1 addr ${pd.node.ip} 29665/ - /peer 1 id Discovery/ - expect from pd: - /peer [12] addr ${p1.node.ip} 29665/ - /peer [12] id Device1 Owner1/ - - send "discovery-connect $id" to p2 - - with p2: - send "peer-add ${pd.node.ip}" - expect: - /peer 1 addr ${pd.node.ip} 29665/ - /peer 1 id Discovery/ - expect from pd: - /peer [12] addr ${p2.node.ip} 29665/ - /peer [12] id Device2 Owner2/ - - expect from p1: - /peer [0-9]+ addr ${p2.node.ip} 29665/ - /peer [0-9]+ id Device2 Owner2/ - expect from p2: - /peer [0-9]+ addr ${p1.node.ip} 29665/ - /peer [0-9]+ id Device1 Owner1/ - - for p in [ pd, p1, p2 ]: - send "stop-server" to p - for p in [ pd, p1, p2 ]: - expect /stop-server-done/ from p - - -test DiscoveryTunnel: - let services = "discovery:tunnel" - - subnet sd - subnet s1 - subnet s2 - - spawn as pd on sd - spawn as p1 on s1 - spawn as p2 on s2 - - for n in [ p1.node, p2.node ]: - shell on n: - nft add table inet filter - nft add chain inet filter input '{ type filter hook input priority filter ; policy drop; }' - nft add rule inet filter input 'ct state { established, related } accept' - - send "create-identity Discovery" to pd - send "create-identity Device1 Owner1" to p1 - send "create-identity Device2 Owner2" to p2 - - expect /create-identity-done ref ($refpat).*/ from p1 capture p1id - send "identity-info $p1id" to p1 - expect /identity-info ref $p1id base ($refpat) owner ($refpat).*/ from p1 capture p1base, p1owner - send "identity-info $p1owner" to p1 - expect /identity-info ref $p1owner base ($refpat).*/ from p1 capture p1obase - - expect /create-identity-done ref $refpat.*/ from p2 - expect /create-identity-done ref $refpat.*/ from pd - - for id in [ p1obase ]: - for p in [ pd, p1, p2 ]: - send "start-server services $services test-log" to p - - for p in [ p1, p2 ]: - with p: - send "peer-add ${pd.node.ip}" - expect: - /peer 1 addr ${pd.node.ip} 29665/ - /peer 1 id Discovery/ - expect from pd: - /peer [12] addr ${p.node.ip} 29665/ - /peer [12] id .*/ - - send "discovery-tunnel 1 $id" to p2 - - expect /net-ostream-open ${pd.node.ip} 29665 1 1/ from p2 - expect /net-ostream-open ${p1.node.ip} 29665 1 1/ from pd - expect /net-ostream-open ${pd.node.ip} 29665 1 1/ from p1 - expect /net-ostream-open ${p2.node.ip} 29665 1 1/ from pd - - expect from p1: - /peer 2 addr tunnel@.*/ - /peer 2 id Device2 Owner2/ - expect from p2: - /peer 2 addr tunnel@.*/ - /peer 2 id Device1 Owner1/ - - send "peer-drop 2" to p1 - send "peer-drop 2" to p2 - - expect /net-ostream-close-ack ${pd.node.ip} 29665 1 0/ from p2 - expect /net-ostream-close-ack ${p1.node.ip} 29665 1 0/ from pd - expect /net-ostream-close-ack ${pd.node.ip} 29665 1 0/ from p1 - expect /net-ostream-close-ack ${p2.node.ip} 29665 1 0/ from pd - - for p in [ pd, p1, p2 ]: - send "stop-server" to p - for p in [ pd, p1, p2 ]: - expect /stop-server-done/ from p - - -test DiscoveryTunnelRefused: - let services = "discovery" - - subnet sd - subnet s1 - subnet s2 - - spawn as pd on sd - spawn as p1 on s1 - spawn as p2 on s2 - - for n in [ p1.node, p2.node ]: - shell on n: - nft add table inet filter - nft add chain inet filter input '{ type filter hook input priority filter ; policy drop; }' - nft add rule inet filter input 'ct state { established, related } accept' - - send "create-identity Discovery" to pd - send "create-identity Device1 Owner1" to p1 - send "create-identity Device2 Owner2" to p2 - - expect /create-identity-done ref ($refpat).*/ from p1 capture p1id - send "identity-info $p1id" to p1 - expect /identity-info ref $p1id base ($refpat) owner ($refpat).*/ from p1 capture p1base, p1owner - send "identity-info $p1owner" to p1 - expect /identity-info ref $p1owner base ($refpat).*/ from p1 capture p1obase - - expect /create-identity-done ref $refpat.*/ from p2 - expect /create-identity-done ref $refpat.*/ from pd - - for id in [ p1obase ]: - for p in [ pd, p1, p2 ]: - send "start-server services $services test-log" to p - - for p in [ p1, p2 ]: - with p: - send "peer-add ${pd.node.ip}" - expect: - /peer 1 addr ${pd.node.ip} 29665/ - /peer 1 id Discovery/ - expect from pd: - /peer [12] addr ${p.node.ip} 29665/ - /peer [12] id .*/ - - send "discovery-tunnel 1 $id" to p2 - expect /net-ostream-open ${pd.node.ip} 29665 1 1/ from p2 - expect /net-ostream-close-ack ${pd.node.ip} 29665 1 0/ from p2 - - for p in [ pd, p1, p2 ]: - send "stop-server" to p - for p in [ pd, p1, p2 ]: - expect /stop-server-done/ from p diff --git a/message.et b/message.et new file mode 100644 index 0000000..2990d0f --- /dev/null +++ b/message.et @@ -0,0 +1,265 @@ +module message + +import common + +test DirectMessage: + let services = "contact,dm" + + spawn as p1 + spawn as p2 + send "create-identity Device1 Owner1" to p1 + send "create-identity Device2 Owner2" to p2 + send "start-server services $services" to p1 + send "start-server services $services" to p2 + + expect from p1: + /peer ([0-9]+) addr ${p2.node.ip} 29665/ capture peer1_2 + /peer $peer1_2 id Device2 Owner2/ + + expect from p2: + /peer ([0-9]+) addr ${p1.node.ip} 29665/ capture peer2_1 + /peer $peer2_1 id Device1 Owner1/ + + with p1: + send "dm-list-peer $peer1_2" + expect /dm-list-done/ + + # Send messages to peers + + for i in [1..2]: + send "dm-send-peer $peer1_2 hello$i" to p1 + expect /dm-received from Owner1 text hello$i/ from p2 + + for i in [1..2]: + send "dm-send-peer $peer2_1 hi$i" to p2 + expect /dm-received from Owner2 text hi$i/ from p1 + + for i in [3..4]: + send "dm-send-peer $peer1_2 hello$i" to p1 + expect /dm-received from Owner1 text hello$i/ from p2 + send "dm-send-peer $peer2_1 hi$i" to p2 + expect /dm-received from Owner2 text hi$i/ from p1 + + # Create contacts + + local: + send "contact-request $peer1_2" to p1 + expect /contact-request $peer2_1 ([0-9]*)/ from p2 capture code2 + expect /contact-response $peer1_2 ([0-9]*)/ from p1 capture code1 + guard (code1 == code2) + + send "contact-accept $peer1_2" to p1 + send "contact-accept $peer2_1" to p2 + expect /contact-request-done $peer2_1/ from p2 + expect /contact-response-done $peer1_2/ from p1 + + send "contact-list" to p1 + expect from p1: + /contact-list-item ([a-z0-9#]+) Owner2 Owner2/ capture c1_2 + /contact-list-(.*)/ capture done1_1 + + send "contact-list" to p2 + expect from p2: + /contact-list-item ([a-z0-9#]+) Owner1 Owner1/ capture c2_1 + /contact-list-(.*)/ capture done1_2 + + # Send messages to contacts + + for i in [1..2]: + send "dm-send-contact $c1_2 hello_c_$i" to p1 + expect /dm-received from Owner1 text hello_c_$i/ from p2 + + for i in [1..2]: + send "dm-send-contact $c2_1 hi_c_$i" to p2 + expect /dm-received from Owner2 text hi_c_$i/ from p1 + + for i in [3..4]: + send "dm-send-contact $c1_2 hello_c_$i" to p1 + expect /dm-received from Owner1 text hello_c_$i/ from p2 + send "dm-send-contact $c2_1 hi_c_$i" to p2 + expect /dm-received from Owner2 text hi_c_$i/ from p1 + + send "dm-list-contact $c1_2" to p1 + send "dm-list-contact $c2_1" to p2 + for p in [p1, p2]: + with p: + for i in [1..4]: + expect /dm-list-item from Owner1 text hello_c_$i/ + expect /dm-list-item from Owner2 text hi_c_$i/ + for i in [1..4]: + expect /dm-list-item from Owner1 text hello$i/ + expect /dm-list-item from Owner2 text hi$i/ + expect /dm-list-(.*)/ capture done + guard (done == "done") + + # Reload message history + + for p in [p1, p2]: + with p: + send "stop-server" + for p in [p1, p2]: + with p: + expect /stop-server-done/ + for p in [p1, p2]: + with p: + send "start-server services $services" + + with p1: + send "contact-list" + expect: + /contact-list-item $c1_2 Owner2 Owner2/ + /contact-list-(.*)/ capture done + guard (done == "done") + + send "dm-list-contact $c1_2" to p1 + send "dm-list-contact $c2_1" to p2 + for p in [p1, p2]: + with p: + for i in [1..4]: + expect /dm-list-item from Owner1 text hello_c_$i/ + expect /dm-list-item from Owner2 text hi_c_$i/ + for i in [1..4]: + expect /dm-list-item from Owner1 text hello$i/ + expect /dm-list-item from Owner2 text hi$i/ + expect /dm-list-(.*)/ capture done + guard (done == "done") + + # Send message while offline + + for p in [p1, p2]: + with p: + send "stop-server" + for p in [p1, p2]: + with p: + expect /stop-server-done/ + send "start-server services $services" to p2 + + send "dm-send-contact $c1_2 while_offline" to p1 + send "start-server services $services" to p1 + + expect /dm-received from Owner1 text while_offline/ from p2 + + for p in [p1, p2]: + with p: + send "stop-server" + for p in [p1, p2]: + with p: + expect /stop-server-done/ + send "start-server services $services" to p1 + + send "dm-send-contact $c1_2 while_peer_offline" to p1 + # TODO: sync from p1 on peer p2 discovery not ensured without addition wait + #wait + send "start-server services $services" to p2 + + expect /dm-received from Owner1 text while_peer_offline/ from p2 + + +test DirectMessageDiscovery: + let services = "dm,discovery" + + subnet sd + subnet s1 + subnet s2 + subnet s3 + subnet s4 + + spawn on sd as pd + spawn on s1 as p1 + spawn on s2 as p2 + spawn on s3 as p3 + spawn on s4 as p4 + + send "create-identity Discovery" to pd + + send "create-identity Device1 Owner1" to p1 + expect /create-identity-done ref ($refpat)/ from p1 capture p1_id + send "identity-info $p1_id" to p1 + expect /identity-info ref $p1_id base ($refpat) owner ($refpat).*/ from p1 capture p1_base, p1_owner + + send "create-identity Device2 Owner2" to p2 + expect /create-identity-done ref ($refpat)/ from p2 capture p2_id + send "identity-info $p2_id" to p2 + expect /identity-info ref $p2_id base ($refpat) owner ($refpat).*/ from p2 capture p2_base, p2_owner + send "identity-info $p2_owner" to p2 + expect /identity-info ref $p2_owner base ($refpat).*/ from p2 capture p2_obase + + send "create-identity Device3 Owner3" to p3 + expect /create-identity-done ref ($refpat)/ from p3 capture p3_id + send "identity-info $p3_id" to p3 + expect /identity-info ref $p3_id base ($refpat) owner ($refpat).*/ from p3 capture p3_base, p3_owner + + send "create-identity Device4 Owner4" to p4 + expect /create-identity-done ref ($refpat)/ from p4 capture p4_id + send "identity-info $p4_id" to p4 + expect /identity-info ref $p4_id base ($refpat) owner ($refpat).*/ from p4 capture p4_base, p4_owner + + + for p in [ p1, p2, p3, p4 ]: + with p: + send "start-server services $services" + + for p in [ p2, p3, p4 ]: + with p1: + send "peer-add ${p.node.ip}" + expect: + /peer [0-9]+ addr ${p.node.ip} 29665/ + /peer [0-9]+ id Device. Owner./ + expect from p: + /peer 1 addr ${p1.node.ip} 29665/ + /peer 1 id Device1 Owner1/ + + # Make sure p1 has other identities in storage: + for i in [ 1 .. 3 ]: + send "dm-send-peer $i init1" to p1 + for p in [ p2, p3, p4 ]: + expect /dm-received from Owner1 text init1/ from p + send "dm-send-identity $p1_owner init2" to p + expect /dm-received from Owner. text init2/ from p1 + + # Restart servers to remove peers: + for p in [ p1, p2, p3, p4 ]: + with p: + send "stop-server" + for p in [ p1, p2, p3, p4 ]: + with p: + expect /stop-server-done/ + + # Prepare message before peers connect to discovery + send "dm-send-identity $p4_owner hello_to_p4" to p1 + + for p in [ p1, p2, p3, p4, pd ]: + with p: + send "start-server services $services" + + for p in [ p2, p3, p4, p1 ]: + with p: + send "peer-add ${pd.node.ip}" + expect: + /peer 1 addr ${pd.node.ip} 29665/ + /peer 1 id Discovery/ + expect from pd: + /peer [0-9]+ addr ${p.node.ip} 29665/ + /peer [0-9]+ id Device. Owner./ + + multiply_timeout by 2.0 + + # Connect via discovery manually, then send message + send "discovery-connect $p2_obase" to p1 + expect from p1: + /peer [0-9]+ addr ${p2.node.ip} 29665/ + /peer [0-9]+ id Device2 Owner2/ + send "dm-send-identity $p2_owner hello_to_p2" to p1 + expect /dm-received from Owner1 text hello_to_p2/ from p2 + + # Send message, expect automatic discovery + send "dm-send-identity $p3_owner hello_to_p3" to p1 + expect /dm-received from Owner1 text hello_to_p3/ from p3 + + # Verify the first message + expect /dm-received from Owner1 text hello_to_p4/ from p4 + + for p in [ p1, p2, p3, p4, pd ]: + send "stop-server" to p + for p in [ p1, p2, p3, p4, pd ]: + expect /stop-server-done/ from p diff --git a/message.test b/message.test deleted file mode 100644 index 2990d0f..0000000 --- a/message.test +++ /dev/null @@ -1,265 +0,0 @@ -module message - -import common - -test DirectMessage: - let services = "contact,dm" - - spawn as p1 - spawn as p2 - send "create-identity Device1 Owner1" to p1 - send "create-identity Device2 Owner2" to p2 - send "start-server services $services" to p1 - send "start-server services $services" to p2 - - expect from p1: - /peer ([0-9]+) addr ${p2.node.ip} 29665/ capture peer1_2 - /peer $peer1_2 id Device2 Owner2/ - - expect from p2: - /peer ([0-9]+) addr ${p1.node.ip} 29665/ capture peer2_1 - /peer $peer2_1 id Device1 Owner1/ - - with p1: - send "dm-list-peer $peer1_2" - expect /dm-list-done/ - - # Send messages to peers - - for i in [1..2]: - send "dm-send-peer $peer1_2 hello$i" to p1 - expect /dm-received from Owner1 text hello$i/ from p2 - - for i in [1..2]: - send "dm-send-peer $peer2_1 hi$i" to p2 - expect /dm-received from Owner2 text hi$i/ from p1 - - for i in [3..4]: - send "dm-send-peer $peer1_2 hello$i" to p1 - expect /dm-received from Owner1 text hello$i/ from p2 - send "dm-send-peer $peer2_1 hi$i" to p2 - expect /dm-received from Owner2 text hi$i/ from p1 - - # Create contacts - - local: - send "contact-request $peer1_2" to p1 - expect /contact-request $peer2_1 ([0-9]*)/ from p2 capture code2 - expect /contact-response $peer1_2 ([0-9]*)/ from p1 capture code1 - guard (code1 == code2) - - send "contact-accept $peer1_2" to p1 - send "contact-accept $peer2_1" to p2 - expect /contact-request-done $peer2_1/ from p2 - expect /contact-response-done $peer1_2/ from p1 - - send "contact-list" to p1 - expect from p1: - /contact-list-item ([a-z0-9#]+) Owner2 Owner2/ capture c1_2 - /contact-list-(.*)/ capture done1_1 - - send "contact-list" to p2 - expect from p2: - /contact-list-item ([a-z0-9#]+) Owner1 Owner1/ capture c2_1 - /contact-list-(.*)/ capture done1_2 - - # Send messages to contacts - - for i in [1..2]: - send "dm-send-contact $c1_2 hello_c_$i" to p1 - expect /dm-received from Owner1 text hello_c_$i/ from p2 - - for i in [1..2]: - send "dm-send-contact $c2_1 hi_c_$i" to p2 - expect /dm-received from Owner2 text hi_c_$i/ from p1 - - for i in [3..4]: - send "dm-send-contact $c1_2 hello_c_$i" to p1 - expect /dm-received from Owner1 text hello_c_$i/ from p2 - send "dm-send-contact $c2_1 hi_c_$i" to p2 - expect /dm-received from Owner2 text hi_c_$i/ from p1 - - send "dm-list-contact $c1_2" to p1 - send "dm-list-contact $c2_1" to p2 - for p in [p1, p2]: - with p: - for i in [1..4]: - expect /dm-list-item from Owner1 text hello_c_$i/ - expect /dm-list-item from Owner2 text hi_c_$i/ - for i in [1..4]: - expect /dm-list-item from Owner1 text hello$i/ - expect /dm-list-item from Owner2 text hi$i/ - expect /dm-list-(.*)/ capture done - guard (done == "done") - - # Reload message history - - for p in [p1, p2]: - with p: - send "stop-server" - for p in [p1, p2]: - with p: - expect /stop-server-done/ - for p in [p1, p2]: - with p: - send "start-server services $services" - - with p1: - send "contact-list" - expect: - /contact-list-item $c1_2 Owner2 Owner2/ - /contact-list-(.*)/ capture done - guard (done == "done") - - send "dm-list-contact $c1_2" to p1 - send "dm-list-contact $c2_1" to p2 - for p in [p1, p2]: - with p: - for i in [1..4]: - expect /dm-list-item from Owner1 text hello_c_$i/ - expect /dm-list-item from Owner2 text hi_c_$i/ - for i in [1..4]: - expect /dm-list-item from Owner1 text hello$i/ - expect /dm-list-item from Owner2 text hi$i/ - expect /dm-list-(.*)/ capture done - guard (done == "done") - - # Send message while offline - - for p in [p1, p2]: - with p: - send "stop-server" - for p in [p1, p2]: - with p: - expect /stop-server-done/ - send "start-server services $services" to p2 - - send "dm-send-contact $c1_2 while_offline" to p1 - send "start-server services $services" to p1 - - expect /dm-received from Owner1 text while_offline/ from p2 - - for p in [p1, p2]: - with p: - send "stop-server" - for p in [p1, p2]: - with p: - expect /stop-server-done/ - send "start-server services $services" to p1 - - send "dm-send-contact $c1_2 while_peer_offline" to p1 - # TODO: sync from p1 on peer p2 discovery not ensured without addition wait - #wait - send "start-server services $services" to p2 - - expect /dm-received from Owner1 text while_peer_offline/ from p2 - - -test DirectMessageDiscovery: - let services = "dm,discovery" - - subnet sd - subnet s1 - subnet s2 - subnet s3 - subnet s4 - - spawn on sd as pd - spawn on s1 as p1 - spawn on s2 as p2 - spawn on s3 as p3 - spawn on s4 as p4 - - send "create-identity Discovery" to pd - - send "create-identity Device1 Owner1" to p1 - expect /create-identity-done ref ($refpat)/ from p1 capture p1_id - send "identity-info $p1_id" to p1 - expect /identity-info ref $p1_id base ($refpat) owner ($refpat).*/ from p1 capture p1_base, p1_owner - - send "create-identity Device2 Owner2" to p2 - expect /create-identity-done ref ($refpat)/ from p2 capture p2_id - send "identity-info $p2_id" to p2 - expect /identity-info ref $p2_id base ($refpat) owner ($refpat).*/ from p2 capture p2_base, p2_owner - send "identity-info $p2_owner" to p2 - expect /identity-info ref $p2_owner base ($refpat).*/ from p2 capture p2_obase - - send "create-identity Device3 Owner3" to p3 - expect /create-identity-done ref ($refpat)/ from p3 capture p3_id - send "identity-info $p3_id" to p3 - expect /identity-info ref $p3_id base ($refpat) owner ($refpat).*/ from p3 capture p3_base, p3_owner - - send "create-identity Device4 Owner4" to p4 - expect /create-identity-done ref ($refpat)/ from p4 capture p4_id - send "identity-info $p4_id" to p4 - expect /identity-info ref $p4_id base ($refpat) owner ($refpat).*/ from p4 capture p4_base, p4_owner - - - for p in [ p1, p2, p3, p4 ]: - with p: - send "start-server services $services" - - for p in [ p2, p3, p4 ]: - with p1: - send "peer-add ${p.node.ip}" - expect: - /peer [0-9]+ addr ${p.node.ip} 29665/ - /peer [0-9]+ id Device. Owner./ - expect from p: - /peer 1 addr ${p1.node.ip} 29665/ - /peer 1 id Device1 Owner1/ - - # Make sure p1 has other identities in storage: - for i in [ 1 .. 3 ]: - send "dm-send-peer $i init1" to p1 - for p in [ p2, p3, p4 ]: - expect /dm-received from Owner1 text init1/ from p - send "dm-send-identity $p1_owner init2" to p - expect /dm-received from Owner. text init2/ from p1 - - # Restart servers to remove peers: - for p in [ p1, p2, p3, p4 ]: - with p: - send "stop-server" - for p in [ p1, p2, p3, p4 ]: - with p: - expect /stop-server-done/ - - # Prepare message before peers connect to discovery - send "dm-send-identity $p4_owner hello_to_p4" to p1 - - for p in [ p1, p2, p3, p4, pd ]: - with p: - send "start-server services $services" - - for p in [ p2, p3, p4, p1 ]: - with p: - send "peer-add ${pd.node.ip}" - expect: - /peer 1 addr ${pd.node.ip} 29665/ - /peer 1 id Discovery/ - expect from pd: - /peer [0-9]+ addr ${p.node.ip} 29665/ - /peer [0-9]+ id Device. Owner./ - - multiply_timeout by 2.0 - - # Connect via discovery manually, then send message - send "discovery-connect $p2_obase" to p1 - expect from p1: - /peer [0-9]+ addr ${p2.node.ip} 29665/ - /peer [0-9]+ id Device2 Owner2/ - send "dm-send-identity $p2_owner hello_to_p2" to p1 - expect /dm-received from Owner1 text hello_to_p2/ from p2 - - # Send message, expect automatic discovery - send "dm-send-identity $p3_owner hello_to_p3" to p1 - expect /dm-received from Owner1 text hello_to_p3/ from p3 - - # Verify the first message - expect /dm-received from Owner1 text hello_to_p4/ from p4 - - for p in [ p1, p2, p3, p4, pd ]: - send "stop-server" to p - for p in [ p1, p2, p3, p4, pd ]: - expect /stop-server-done/ from p diff --git a/network.et b/network.et new file mode 100644 index 0000000..a670f35 --- /dev/null +++ b/network.et @@ -0,0 +1,514 @@ +test Discovery: + spawn as p1 + spawn as p2 + send "create-identity Device1 Owner" to p1 + send "create-identity Device2" to p2 + send "start-server" to p1 + send "start-server" to p2 + expect from p1: + /peer 1 addr ${p2.node.ip} 29665/ + /peer 1 id Device2/ + expect from p2: + /peer 1 addr ${p1.node.ip} 29665/ + /peer 1 id Device1 Owner/ + + send "update-local-identity Device1A" to p1 + expect /peer 1 id Device1A Owner/ from p2 + + send "update-shared-identity OwnerA" to p1 + expect /peer 1 id Device1A OwnerA/ from p2 + + send "update-local-identity Device1B" to p1 + expect /peer 1 id Device1B OwnerA/ from p2 + + send "update-shared-identity OwnerB" to p1 + expect /peer 1 id Device1B OwnerB/ from p2 + + with p2: + send "stop-server" + expect /stop-server-done/ + + send "update-shared-identity OwnerC" to p1 + + with p1: + send "stop-server" + expect /stop-server-done/ + + spawn as p3 + spawn as p4 + spawn as p5 + spawn as p6 + send "create-identity Device3" to p3 + send "create-identity Device4" to p4 + send "create-identity Device5" to p5 + send "create-identity Device6" to p6 + + for p in [ p1, p2, p3, p4, p5, p6 ]: + send "start-server" to p + + expect from p1: + /peer ([0-9]+) addr ${p2.node.ip} 29665/ capture peer1_2 + /peer $peer1_2 id Device2/ + /peer ([0-9]+) addr ${p3.node.ip} 29665/ capture peer1_3 + /peer $peer1_3 id Device3/ + /peer ([0-9]+) addr ${p4.node.ip} 29665/ capture peer1_4 + /peer $peer1_4 id Device4/ + /peer ([0-9]+) addr ${p5.node.ip} 29665/ capture peer1_5 + /peer $peer1_5 id Device5/ + /peer ([0-9]+) addr ${p6.node.ip} 29665/ capture peer1_6 + /peer $peer1_6 id Device6/ + + expect from p2: + /peer ([0-9]+) addr ${p1.node.ip} 29665/ capture peer2_1 + /peer $peer2_1 id Device1B OwnerC/ + /peer ([0-9]+) addr ${p3.node.ip} 29665/ capture peer2_3 + /peer $peer2_3 id Device3/ + /peer ([0-9]+) addr ${p4.node.ip} 29665/ capture peer2_4 + /peer $peer2_4 id Device4/ + /peer ([0-9]+) addr ${p5.node.ip} 29665/ capture peer2_5 + /peer $peer2_5 id Device5/ + /peer ([0-9]+) addr ${p6.node.ip} 29665/ capture peer2_6 + /peer $peer2_6 id Device6/ + + expect from p3: + /peer ([0-9]+) addr ${p1.node.ip} 29665/ capture peer3_1 + /peer $peer3_1 id Device1B OwnerC/ + /peer ([0-9]+) addr ${p2.node.ip} 29665/ capture peer3_2 + /peer $peer3_2 id Device2/ + /peer ([0-9]+) addr ${p4.node.ip} 29665/ capture peer3_4 + /peer $peer3_4 id Device4/ + /peer ([0-9]+) addr ${p5.node.ip} 29665/ capture peer3_5 + /peer $peer3_5 id Device5/ + /peer ([0-9]+) addr ${p6.node.ip} 29665/ capture peer3_6 + /peer $peer3_6 id Device6/ + + expect from p4: + /peer ([0-9]+) addr ${p1.node.ip} 29665/ capture peer4_1 + /peer $peer4_1 id Device1B OwnerC/ + /peer ([0-9]+) addr ${p2.node.ip} 29665/ capture peer4_2 + /peer $peer4_2 id Device2/ + /peer ([0-9]+) addr ${p3.node.ip} 29665/ capture peer4_3 + /peer $peer4_3 id Device3/ + /peer ([0-9]+) addr ${p5.node.ip} 29665/ capture peer4_5 + /peer $peer4_5 id Device5/ + /peer ([0-9]+) addr ${p6.node.ip} 29665/ capture peer4_6 + /peer $peer4_6 id Device6/ + + expect from p5: + /peer ([0-9]+) addr ${p1.node.ip} 29665/ capture peer5_1 + /peer $peer5_1 id Device1B OwnerC/ + /peer ([0-9]+) addr ${p2.node.ip} 29665/ capture peer5_2 + /peer $peer5_2 id Device2/ + /peer ([0-9]+) addr ${p3.node.ip} 29665/ capture peer5_3 + /peer $peer5_3 id Device3/ + /peer ([0-9]+) addr ${p4.node.ip} 29665/ capture peer5_4 + /peer $peer5_4 id Device4/ + /peer ([0-9]+) addr ${p6.node.ip} 29665/ capture peer5_6 + /peer $peer5_6 id Device6/ + + expect from p6: + /peer ([0-9]+) addr ${p1.node.ip} 29665/ capture peer6_1 + /peer $peer6_1 id Device1B OwnerC/ + /peer ([0-9]+) addr ${p2.node.ip} 29665/ capture peer6_2 + /peer $peer6_2 id Device2/ + /peer ([0-9]+) addr ${p3.node.ip} 29665/ capture peer6_3 + /peer $peer6_3 id Device3/ + /peer ([0-9]+) addr ${p4.node.ip} 29665/ capture peer6_4 + /peer $peer6_4 id Device4/ + /peer ([0-9]+) addr ${p5.node.ip} 29665/ capture peer6_5 + /peer $peer6_5 id Device5/ + + +test LargeData: + let services = "test" + + spawn as p1 + spawn as p2 + send "create-identity Device1" to p1 + send "create-identity Device2" to p2 + send "start-server services $services" to p1 + send "start-server services $services" to p2 + expect from p1: + /peer 1 addr ${p2.node.ip} 29665/ + /peer 1 id Device2/ + expect from p2: + /peer 1 addr ${p1.node.ip} 29665/ + /peer 1 id Device1/ + + for i in [0..10]: + with p1: + # Create blob with (i * 1000) bytes + send "store blob" + for j in [1 .. i * 10]: + # 100 bytes each line + send "123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789" + send "" + expect /store-done (blake2#[0-9a-f]*)/ capture ref + + send "test-message-send 1 $ref" + expect /test-message-send done/ + expect /test-message-received blob ${i*1000} $ref/ from p2 + + +test ManyStreams: + let services = "test" + + spawn as p1 + spawn as p2 + send "create-identity Device1" to p1 + send "create-identity Device2" to p2 + send "start-server services $services" to p1 + send "start-server services $services" to p2 + expect from p1: + /peer 1 addr ${p2.node.ip} 29665/ + /peer 1 id Device2/ + expect from p2: + /peer 1 addr ${p1.node.ip} 29665/ + /peer 1 id Device1/ + + for i in [0..100]: + with p1: + # Create blob with 1000 bytes + decimal i + send "store blob" + for j in [1 .. 10]: + # 100 bytes each line + send "123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789" + send "$i" + send "" + expect /store-done (blake2#[0-9a-f]*)/ capture ref + + send "test-message-send 1 $ref" + expect /test-message-send done/ + expect /test-message-received blob 100[2-4] $ref/ from p2 + + +test ServiceStreams: + let services = "test" + + spawn as p1 + spawn as p2 + send "create-identity Device1" to p1 + send "create-identity Device2" to p2 + send "start-server services $services test-log" to p1 + send "start-server services $services test-log" to p2 + expect from p1: + /peer 1 addr ${p2.node.ip} 29665/ + /peer 1 id Device2/ + expect from p2: + /peer 1 addr ${p1.node.ip} 29665/ + /peer 1 id Device1/ + + send "test-stream-open 1" to p1 + expect /test-stream-open-done 1 ([0-9]+)/ from p1 capture stream1 + expect /test-stream-open-from 1 $stream1/ from p2 + + expect /net-ostream-open ${p2.node.ip} 29665 1 1/ from p1 + + send "test-stream-send 1 $stream1 hello" to p1 + expect /test-stream-send-done 1 $stream1/ from p1 + expect /test-stream-received 1 $stream1 0 hello/ from p2 + + send "test-stream-close 1 $stream1" to p1 + expect /test-stream-close-done 1 $stream1/ from p1 + expect /test-stream-closed-from 1 $stream1 1/ from p2 + + expect /net-ostream-close-send ${p2.node.ip} 29665 1/ from p1 + expect /net-ostream-close-ack ${p2.node.ip} 29665 1 0/ from p1 + + send "test-stream-open 1 8" to p2 + expect /test-stream-open-done 1 ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)/ from p2 capture stream2_1, stream2_2, stream2_3, stream2_4, stream2_5, stream2_6, stream2_7, stream2_8 + expect /test-stream-open-from 1 $stream2_1 $stream2_2 $stream2_3 $stream2_4 $stream2_5 $stream2_6 $stream2_7 $stream2_8/ from p1 + + let streams2 = [ stream2_1, stream2_2, stream2_3, stream2_4, stream2_5, stream2_6, stream2_7, stream2_8 ] + with p2: + expect /net-ostream-open ${p1.node.ip} 29665 . 8/ + flush matching /net-ostream-open ${p1.node.ip} 29665.*/ + + for i in [ 1..20 ]: + for s in streams2: + send "test-stream-send 1 $s hello$i" + for i in [ 1..20 ]: + for s in streams2: + expect /test-stream-send-done 1 $s/ + for s in streams2: + send "test-stream-close 1 $s" + for s in streams2: + expect /test-stream-close-done 1 $s/ + + expect /net-ostream-close-ack ${p1.node.ip} 29665 . 0/ + flush matching /net-ostream-close-[a-z]* ${p1.node.ip} 29665.*/ + with p1: + for i in [ 1..20 ]: + for s in streams2: + expect /test-stream-received 1 $s ${i-1} hello$i/ + for s in streams2: + expect /test-stream-closed-from 1 $s 20/ + + +test MultipleServiceRefs: + let services = "test" + + spawn as p1 + spawn as p2 + send "create-identity Device1" to p1 + send "create-identity Device2" to p2 + send "start-server services $services" to p1 + send "start-server services $services" to p2 + expect from p1: + /peer 1 addr ${p2.node.ip} 29665/ + /peer 1 id Device2/ + expect from p2: + /peer 1 addr ${p1.node.ip} 29665/ + /peer 1 id Device1/ + + let kbytes = 2 + + with p1: + send "store blob" + send "A" + send "" + expect /store-done (blake2#[0-9a-f]*)/ capture ref_a + + # Create blobs with (kbytes * 1000) bytes each + + send "store blob" + send "B" + for j in [1 .. kbytes * 10]: + # 100 bytes each line + send "123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789" + send "" + expect /store-done (blake2#[0-9a-f]*)/ capture ref_b + + send "store blob" + send "C" + for j in [1 .. kbytes * 10]: + # 100 bytes each line + send "123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789" + send "" + expect /store-done (blake2#[0-9a-f]*)/ capture ref_c + + send "store blob" + send "D" + for j in [1 .. kbytes * 10]: + # 100 bytes each line + send "123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789" + send "" + expect /store-done (blake2#[0-9a-f]*)/ capture ref_d + + send "test-message-send 1 $ref_a $ref_b $ref_c $ref_d" + expect /test-message-send done/ + expect /test-message-received blob [0-9]+ $ref_a/ from p2 + expect /test-message-received blob [0-9]+ $ref_b/ from p2 + expect /test-message-received blob [0-9]+ $ref_c/ from p2 + expect /test-message-received blob [0-9]+ $ref_d/ from p2 + + +test Reconnection: + let services = "test" + + spawn as p1 + with p1: + send "create-identity Device1" + send "start-server services $services" + + node n + local: + spawn as p2 on n + send "create-identity Device2" to p2 + send "start-server services $services" to p2 + + expect from p1: + /peer 1 addr ${p2.node.ip} 29665/ + /peer 1 id Device2/ + expect from p2: + /peer 1 addr ${p1.node.ip} 29665/ + /peer 1 id Device1/ + + with p1: + send "store blob" + send "message1" + send "" + expect /store-done (blake2#[0-9a-f]*)/ capture message + + send "test-message-send 1 $message" + expect /test-message-send done/ + expect /test-message-received blob [0-9]+ $message/ from p2 + + send "peer-list" + expect /peer-list-item 1 addr ${p2.node.ip} 29665 id Device2/ + local: + expect /peer-list-(.*)/ capture done + guard (done == "done") + + # Restart process on node 'n' + local: + spawn as p2 on n + send "start-server services $services" to p2 + send "peer-add ${p1.node.ip}" to p2 + + expect from p2: + /peer 1 addr ${p1.node.ip} 29665/ + /peer 1 id Device1/ + + with p1: + send "store blob" + send "message2" + send "" + expect /store-done (blake2#[0-9a-f]*)/ capture message + + send "test-message-send 1 $message" + expect /test-message-send done/ + expect /test-message-received blob [0-9]+ $message/ from p2 + + # Drop and re-add peer p2: + with p1: + send "peer-list" + expect /peer-list-item 1 addr ${p2.node.ip} 29665 id Device2/ + local: + expect /peer-list-(.*)/ capture done + guard (done == "done") + + send "peer-drop 1" + send "peer-list" + local: + expect /peer-list-(.*)/ capture done + guard (done == "done") + + send "peer-add ${p2.node.ip}" + expect /peer 2 addr ${p2.node.ip} 29665/ + expect /peer 2 id Device2/ + + send "peer-list" + expect /peer-list-item 2 addr ${p2.node.ip} 29665 id Device2/ + local: + expect /peer-list-(.*)/ capture done + guard (done == "done") + + send "store blob" + send "message3" + send "" + expect /store-done (blake2#[0-9a-f]*)/ capture message + + send "test-message-send 2 $message" + expect /test-message-send done/ + expect /test-message-received blob [0-9]+ $message/ from p2 + + # Drop on both sides and re-add: + with p2: + send "peer-list" + expect /peer-list-item 1 addr ${p1.node.ip} 29665 id Device1/ + local: + expect /peer-list-(.*)/ capture done + guard (done == "done") + + send "peer-drop 1" + send "peer-list" + local: + expect /peer-list-(.*)/ capture done + guard (done == "done") + + with p1: + send "peer-list" + expect /peer-list-item 2 addr ${p2.node.ip} 29665 id Device2/ + local: + expect /peer-list-(.*)/ capture done + guard (done == "done") + + send "peer-drop 2" + send "peer-list" + local: + expect /peer-list-(.*)/ capture done + guard (done == "done") + + send "peer-add ${p1.node.ip}" to p2 + + with p2: + expect /peer 2 addr ${p1.node.ip} 29665/ from p2 + expect /peer 2 id Device1/ from p2 + + send "peer-list" + expect /peer-list-item 2 addr ${p1.node.ip} 29665 id Device1/ + local: + expect /peer-list-(.*)/ capture done + guard (done == "done") + + send "store blob" + send "message4" + send "" + expect /store-done (blake2#[0-9a-f]*)/ capture message + + send "test-message-send 2 $message" + expect /test-message-send done/ + + with p1: + expect /peer 3 addr ${p2.node.ip} 29665/ + expect /peer 3 id Device2/ + + send "peer-list" + expect /peer-list-item 3 addr ${p2.node.ip} 29665 id Device2/ + local: + expect /peer-list-(.*)/ capture done + guard (done == "done") + + expect /test-message-received blob [0-9]+ $message/ + + +test SendUnknownObjectType: + let services = "test" + let refpat = /blake2#[0-9a-f]*/ + + spawn as p1 + spawn as p2 + + with p1: + send "create-identity Device1" + send "start-server services $services" + with p2: + send "create-identity Device2" + send "start-server services $services" + + expect from p1: + /peer 1 addr ${p2.node.ip} 29665/ + /peer 1 id Device2/ + expect from p2: + /peer 1 addr ${p1.node.ip} 29665/ + /peer 1 id Device1/ + + with p1: + send: + "store test-unknown" + "TEST" + "" + expect /store-done ($refpat)/ capture r1 + + send: + "store rec" + "test:unknown TEST" + "" + expect /store-done ($refpat)/ capture r2 + + send "test-message-send 1 $r1" + expect /test-message-send done/ + + with p2: + expect /test-message-received test-unknown [0-9]+ $r1/ + + send "load $r1" + expect /load-type test-unknown 5/ + expect /load-line TEST/ + local: + expect /load-(.*)/ capture done + guard (done == "done") + + send "test-message-send 1 $r2" + expect /test-message-send done/ + + with p2: + expect /test-message-received rec [0-9]+ $r2/ + + send "load $r2" + expect /load-type rec [0-9]+/ + expect /load-line test:unknown TEST/ + local: + expect /load-(.*)/ capture done + guard (done == "done") diff --git a/network.test b/network.test deleted file mode 100644 index a670f35..0000000 --- a/network.test +++ /dev/null @@ -1,514 +0,0 @@ -test Discovery: - spawn as p1 - spawn as p2 - send "create-identity Device1 Owner" to p1 - send "create-identity Device2" to p2 - send "start-server" to p1 - send "start-server" to p2 - expect from p1: - /peer 1 addr ${p2.node.ip} 29665/ - /peer 1 id Device2/ - expect from p2: - /peer 1 addr ${p1.node.ip} 29665/ - /peer 1 id Device1 Owner/ - - send "update-local-identity Device1A" to p1 - expect /peer 1 id Device1A Owner/ from p2 - - send "update-shared-identity OwnerA" to p1 - expect /peer 1 id Device1A OwnerA/ from p2 - - send "update-local-identity Device1B" to p1 - expect /peer 1 id Device1B OwnerA/ from p2 - - send "update-shared-identity OwnerB" to p1 - expect /peer 1 id Device1B OwnerB/ from p2 - - with p2: - send "stop-server" - expect /stop-server-done/ - - send "update-shared-identity OwnerC" to p1 - - with p1: - send "stop-server" - expect /stop-server-done/ - - spawn as p3 - spawn as p4 - spawn as p5 - spawn as p6 - send "create-identity Device3" to p3 - send "create-identity Device4" to p4 - send "create-identity Device5" to p5 - send "create-identity Device6" to p6 - - for p in [ p1, p2, p3, p4, p5, p6 ]: - send "start-server" to p - - expect from p1: - /peer ([0-9]+) addr ${p2.node.ip} 29665/ capture peer1_2 - /peer $peer1_2 id Device2/ - /peer ([0-9]+) addr ${p3.node.ip} 29665/ capture peer1_3 - /peer $peer1_3 id Device3/ - /peer ([0-9]+) addr ${p4.node.ip} 29665/ capture peer1_4 - /peer $peer1_4 id Device4/ - /peer ([0-9]+) addr ${p5.node.ip} 29665/ capture peer1_5 - /peer $peer1_5 id Device5/ - /peer ([0-9]+) addr ${p6.node.ip} 29665/ capture peer1_6 - /peer $peer1_6 id Device6/ - - expect from p2: - /peer ([0-9]+) addr ${p1.node.ip} 29665/ capture peer2_1 - /peer $peer2_1 id Device1B OwnerC/ - /peer ([0-9]+) addr ${p3.node.ip} 29665/ capture peer2_3 - /peer $peer2_3 id Device3/ - /peer ([0-9]+) addr ${p4.node.ip} 29665/ capture peer2_4 - /peer $peer2_4 id Device4/ - /peer ([0-9]+) addr ${p5.node.ip} 29665/ capture peer2_5 - /peer $peer2_5 id Device5/ - /peer ([0-9]+) addr ${p6.node.ip} 29665/ capture peer2_6 - /peer $peer2_6 id Device6/ - - expect from p3: - /peer ([0-9]+) addr ${p1.node.ip} 29665/ capture peer3_1 - /peer $peer3_1 id Device1B OwnerC/ - /peer ([0-9]+) addr ${p2.node.ip} 29665/ capture peer3_2 - /peer $peer3_2 id Device2/ - /peer ([0-9]+) addr ${p4.node.ip} 29665/ capture peer3_4 - /peer $peer3_4 id Device4/ - /peer ([0-9]+) addr ${p5.node.ip} 29665/ capture peer3_5 - /peer $peer3_5 id Device5/ - /peer ([0-9]+) addr ${p6.node.ip} 29665/ capture peer3_6 - /peer $peer3_6 id Device6/ - - expect from p4: - /peer ([0-9]+) addr ${p1.node.ip} 29665/ capture peer4_1 - /peer $peer4_1 id Device1B OwnerC/ - /peer ([0-9]+) addr ${p2.node.ip} 29665/ capture peer4_2 - /peer $peer4_2 id Device2/ - /peer ([0-9]+) addr ${p3.node.ip} 29665/ capture peer4_3 - /peer $peer4_3 id Device3/ - /peer ([0-9]+) addr ${p5.node.ip} 29665/ capture peer4_5 - /peer $peer4_5 id Device5/ - /peer ([0-9]+) addr ${p6.node.ip} 29665/ capture peer4_6 - /peer $peer4_6 id Device6/ - - expect from p5: - /peer ([0-9]+) addr ${p1.node.ip} 29665/ capture peer5_1 - /peer $peer5_1 id Device1B OwnerC/ - /peer ([0-9]+) addr ${p2.node.ip} 29665/ capture peer5_2 - /peer $peer5_2 id Device2/ - /peer ([0-9]+) addr ${p3.node.ip} 29665/ capture peer5_3 - /peer $peer5_3 id Device3/ - /peer ([0-9]+) addr ${p4.node.ip} 29665/ capture peer5_4 - /peer $peer5_4 id Device4/ - /peer ([0-9]+) addr ${p6.node.ip} 29665/ capture peer5_6 - /peer $peer5_6 id Device6/ - - expect from p6: - /peer ([0-9]+) addr ${p1.node.ip} 29665/ capture peer6_1 - /peer $peer6_1 id Device1B OwnerC/ - /peer ([0-9]+) addr ${p2.node.ip} 29665/ capture peer6_2 - /peer $peer6_2 id Device2/ - /peer ([0-9]+) addr ${p3.node.ip} 29665/ capture peer6_3 - /peer $peer6_3 id Device3/ - /peer ([0-9]+) addr ${p4.node.ip} 29665/ capture peer6_4 - /peer $peer6_4 id Device4/ - /peer ([0-9]+) addr ${p5.node.ip} 29665/ capture peer6_5 - /peer $peer6_5 id Device5/ - - -test LargeData: - let services = "test" - - spawn as p1 - spawn as p2 - send "create-identity Device1" to p1 - send "create-identity Device2" to p2 - send "start-server services $services" to p1 - send "start-server services $services" to p2 - expect from p1: - /peer 1 addr ${p2.node.ip} 29665/ - /peer 1 id Device2/ - expect from p2: - /peer 1 addr ${p1.node.ip} 29665/ - /peer 1 id Device1/ - - for i in [0..10]: - with p1: - # Create blob with (i * 1000) bytes - send "store blob" - for j in [1 .. i * 10]: - # 100 bytes each line - send "123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789" - send "" - expect /store-done (blake2#[0-9a-f]*)/ capture ref - - send "test-message-send 1 $ref" - expect /test-message-send done/ - expect /test-message-received blob ${i*1000} $ref/ from p2 - - -test ManyStreams: - let services = "test" - - spawn as p1 - spawn as p2 - send "create-identity Device1" to p1 - send "create-identity Device2" to p2 - send "start-server services $services" to p1 - send "start-server services $services" to p2 - expect from p1: - /peer 1 addr ${p2.node.ip} 29665/ - /peer 1 id Device2/ - expect from p2: - /peer 1 addr ${p1.node.ip} 29665/ - /peer 1 id Device1/ - - for i in [0..100]: - with p1: - # Create blob with 1000 bytes + decimal i - send "store blob" - for j in [1 .. 10]: - # 100 bytes each line - send "123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789" - send "$i" - send "" - expect /store-done (blake2#[0-9a-f]*)/ capture ref - - send "test-message-send 1 $ref" - expect /test-message-send done/ - expect /test-message-received blob 100[2-4] $ref/ from p2 - - -test ServiceStreams: - let services = "test" - - spawn as p1 - spawn as p2 - send "create-identity Device1" to p1 - send "create-identity Device2" to p2 - send "start-server services $services test-log" to p1 - send "start-server services $services test-log" to p2 - expect from p1: - /peer 1 addr ${p2.node.ip} 29665/ - /peer 1 id Device2/ - expect from p2: - /peer 1 addr ${p1.node.ip} 29665/ - /peer 1 id Device1/ - - send "test-stream-open 1" to p1 - expect /test-stream-open-done 1 ([0-9]+)/ from p1 capture stream1 - expect /test-stream-open-from 1 $stream1/ from p2 - - expect /net-ostream-open ${p2.node.ip} 29665 1 1/ from p1 - - send "test-stream-send 1 $stream1 hello" to p1 - expect /test-stream-send-done 1 $stream1/ from p1 - expect /test-stream-received 1 $stream1 0 hello/ from p2 - - send "test-stream-close 1 $stream1" to p1 - expect /test-stream-close-done 1 $stream1/ from p1 - expect /test-stream-closed-from 1 $stream1 1/ from p2 - - expect /net-ostream-close-send ${p2.node.ip} 29665 1/ from p1 - expect /net-ostream-close-ack ${p2.node.ip} 29665 1 0/ from p1 - - send "test-stream-open 1 8" to p2 - expect /test-stream-open-done 1 ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)/ from p2 capture stream2_1, stream2_2, stream2_3, stream2_4, stream2_5, stream2_6, stream2_7, stream2_8 - expect /test-stream-open-from 1 $stream2_1 $stream2_2 $stream2_3 $stream2_4 $stream2_5 $stream2_6 $stream2_7 $stream2_8/ from p1 - - let streams2 = [ stream2_1, stream2_2, stream2_3, stream2_4, stream2_5, stream2_6, stream2_7, stream2_8 ] - with p2: - expect /net-ostream-open ${p1.node.ip} 29665 . 8/ - flush matching /net-ostream-open ${p1.node.ip} 29665.*/ - - for i in [ 1..20 ]: - for s in streams2: - send "test-stream-send 1 $s hello$i" - for i in [ 1..20 ]: - for s in streams2: - expect /test-stream-send-done 1 $s/ - for s in streams2: - send "test-stream-close 1 $s" - for s in streams2: - expect /test-stream-close-done 1 $s/ - - expect /net-ostream-close-ack ${p1.node.ip} 29665 . 0/ - flush matching /net-ostream-close-[a-z]* ${p1.node.ip} 29665.*/ - with p1: - for i in [ 1..20 ]: - for s in streams2: - expect /test-stream-received 1 $s ${i-1} hello$i/ - for s in streams2: - expect /test-stream-closed-from 1 $s 20/ - - -test MultipleServiceRefs: - let services = "test" - - spawn as p1 - spawn as p2 - send "create-identity Device1" to p1 - send "create-identity Device2" to p2 - send "start-server services $services" to p1 - send "start-server services $services" to p2 - expect from p1: - /peer 1 addr ${p2.node.ip} 29665/ - /peer 1 id Device2/ - expect from p2: - /peer 1 addr ${p1.node.ip} 29665/ - /peer 1 id Device1/ - - let kbytes = 2 - - with p1: - send "store blob" - send "A" - send "" - expect /store-done (blake2#[0-9a-f]*)/ capture ref_a - - # Create blobs with (kbytes * 1000) bytes each - - send "store blob" - send "B" - for j in [1 .. kbytes * 10]: - # 100 bytes each line - send "123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789" - send "" - expect /store-done (blake2#[0-9a-f]*)/ capture ref_b - - send "store blob" - send "C" - for j in [1 .. kbytes * 10]: - # 100 bytes each line - send "123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789" - send "" - expect /store-done (blake2#[0-9a-f]*)/ capture ref_c - - send "store blob" - send "D" - for j in [1 .. kbytes * 10]: - # 100 bytes each line - send "123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789" - send "" - expect /store-done (blake2#[0-9a-f]*)/ capture ref_d - - send "test-message-send 1 $ref_a $ref_b $ref_c $ref_d" - expect /test-message-send done/ - expect /test-message-received blob [0-9]+ $ref_a/ from p2 - expect /test-message-received blob [0-9]+ $ref_b/ from p2 - expect /test-message-received blob [0-9]+ $ref_c/ from p2 - expect /test-message-received blob [0-9]+ $ref_d/ from p2 - - -test Reconnection: - let services = "test" - - spawn as p1 - with p1: - send "create-identity Device1" - send "start-server services $services" - - node n - local: - spawn as p2 on n - send "create-identity Device2" to p2 - send "start-server services $services" to p2 - - expect from p1: - /peer 1 addr ${p2.node.ip} 29665/ - /peer 1 id Device2/ - expect from p2: - /peer 1 addr ${p1.node.ip} 29665/ - /peer 1 id Device1/ - - with p1: - send "store blob" - send "message1" - send "" - expect /store-done (blake2#[0-9a-f]*)/ capture message - - send "test-message-send 1 $message" - expect /test-message-send done/ - expect /test-message-received blob [0-9]+ $message/ from p2 - - send "peer-list" - expect /peer-list-item 1 addr ${p2.node.ip} 29665 id Device2/ - local: - expect /peer-list-(.*)/ capture done - guard (done == "done") - - # Restart process on node 'n' - local: - spawn as p2 on n - send "start-server services $services" to p2 - send "peer-add ${p1.node.ip}" to p2 - - expect from p2: - /peer 1 addr ${p1.node.ip} 29665/ - /peer 1 id Device1/ - - with p1: - send "store blob" - send "message2" - send "" - expect /store-done (blake2#[0-9a-f]*)/ capture message - - send "test-message-send 1 $message" - expect /test-message-send done/ - expect /test-message-received blob [0-9]+ $message/ from p2 - - # Drop and re-add peer p2: - with p1: - send "peer-list" - expect /peer-list-item 1 addr ${p2.node.ip} 29665 id Device2/ - local: - expect /peer-list-(.*)/ capture done - guard (done == "done") - - send "peer-drop 1" - send "peer-list" - local: - expect /peer-list-(.*)/ capture done - guard (done == "done") - - send "peer-add ${p2.node.ip}" - expect /peer 2 addr ${p2.node.ip} 29665/ - expect /peer 2 id Device2/ - - send "peer-list" - expect /peer-list-item 2 addr ${p2.node.ip} 29665 id Device2/ - local: - expect /peer-list-(.*)/ capture done - guard (done == "done") - - send "store blob" - send "message3" - send "" - expect /store-done (blake2#[0-9a-f]*)/ capture message - - send "test-message-send 2 $message" - expect /test-message-send done/ - expect /test-message-received blob [0-9]+ $message/ from p2 - - # Drop on both sides and re-add: - with p2: - send "peer-list" - expect /peer-list-item 1 addr ${p1.node.ip} 29665 id Device1/ - local: - expect /peer-list-(.*)/ capture done - guard (done == "done") - - send "peer-drop 1" - send "peer-list" - local: - expect /peer-list-(.*)/ capture done - guard (done == "done") - - with p1: - send "peer-list" - expect /peer-list-item 2 addr ${p2.node.ip} 29665 id Device2/ - local: - expect /peer-list-(.*)/ capture done - guard (done == "done") - - send "peer-drop 2" - send "peer-list" - local: - expect /peer-list-(.*)/ capture done - guard (done == "done") - - send "peer-add ${p1.node.ip}" to p2 - - with p2: - expect /peer 2 addr ${p1.node.ip} 29665/ from p2 - expect /peer 2 id Device1/ from p2 - - send "peer-list" - expect /peer-list-item 2 addr ${p1.node.ip} 29665 id Device1/ - local: - expect /peer-list-(.*)/ capture done - guard (done == "done") - - send "store blob" - send "message4" - send "" - expect /store-done (blake2#[0-9a-f]*)/ capture message - - send "test-message-send 2 $message" - expect /test-message-send done/ - - with p1: - expect /peer 3 addr ${p2.node.ip} 29665/ - expect /peer 3 id Device2/ - - send "peer-list" - expect /peer-list-item 3 addr ${p2.node.ip} 29665 id Device2/ - local: - expect /peer-list-(.*)/ capture done - guard (done == "done") - - expect /test-message-received blob [0-9]+ $message/ - - -test SendUnknownObjectType: - let services = "test" - let refpat = /blake2#[0-9a-f]*/ - - spawn as p1 - spawn as p2 - - with p1: - send "create-identity Device1" - send "start-server services $services" - with p2: - send "create-identity Device2" - send "start-server services $services" - - expect from p1: - /peer 1 addr ${p2.node.ip} 29665/ - /peer 1 id Device2/ - expect from p2: - /peer 1 addr ${p1.node.ip} 29665/ - /peer 1 id Device1/ - - with p1: - send: - "store test-unknown" - "TEST" - "" - expect /store-done ($refpat)/ capture r1 - - send: - "store rec" - "test:unknown TEST" - "" - expect /store-done ($refpat)/ capture r2 - - send "test-message-send 1 $r1" - expect /test-message-send done/ - - with p2: - expect /test-message-received test-unknown [0-9]+ $r1/ - - send "load $r1" - expect /load-type test-unknown 5/ - expect /load-line TEST/ - local: - expect /load-(.*)/ capture done - guard (done == "done") - - send "test-message-send 1 $r2" - expect /test-message-send done/ - - with p2: - expect /test-message-received rec [0-9]+ $r2/ - - send "load $r2" - expect /load-type rec [0-9]+/ - expect /load-line test:unknown TEST/ - local: - expect /load-(.*)/ capture done - guard (done == "done") diff --git a/storage.et b/storage.et new file mode 100644 index 0000000..2230eac --- /dev/null +++ b/storage.et @@ -0,0 +1,523 @@ +test Storage: + spawn as p1 + + # Root finding + ############### + + # Diamond history + send to p1: + "store rec" + "text:t First root" + "" + expect from p1: + /store-done (blake2#[0-9a-f]*)/ capture r1 + guard (r1 == "blake2#c4a8c69fbc8398acf76a2ec1e5a191f339c4d03c3eb425af19d6d7d5efac6b8e") + + send to p1: + "store rec" + "PREV:r $r1" + "" + expect from p1: + /store-done (blake2#[0-9a-f]*)/ capture r2 + + send to p1: + "store rec" + "text:t Second branch" + "PREV:r $r1" + "" + expect from p1: + /store-done (blake2#[0-9a-f]*)/ capture r3 + + send to p1: + "store rec" + "PREV:r $r2" + "PREV:r $r3" + "" + expect from p1: + /store-done (blake2#[0-9a-f]*)/ capture r4 + + send to p1 "stored-generation $r1" + expect from p1 /stored-generation $r1 0/ + + send to p1 "stored-generation $r2" + expect from p1 /stored-generation $r2 1/ + + send to p1 "stored-generation $r3" + expect from p1 /stored-generation $r3 1/ + + send to p1 "stored-generation $r4" + expect from p1 /stored-generation $r4 2/ + + send to p1 "stored-roots $r1" + expect from p1 /stored-roots $r1 $r1/ + + send to p1 "stored-roots $r2" + expect from p1 /stored-roots $r2 $r1/ + + send to p1 "stored-roots $r3" + expect from p1 /stored-roots $r3 $r1/ + + send to p1 "stored-roots $r4" + expect from p1 /stored-roots $r4 $r1/ + + # Attach second root + send to p1: + "store rec" + "text:t Second root" + "" + expect from p1: + /store-done (blake2#[0-9a-f]*)/ capture r2_1 + + send to p1: + "store rec" + "PREV:r $r2_1" + "" + expect from p1: + /store-done (blake2#[0-9a-f]*)/ capture r2_2 + + send to p1: + "store rec" + "PREV:r $r2_2" + "PREV:r $r4" + "" + expect from p1: + /store-done (blake2#[0-9a-f]*)/ capture r2_3 + + send to p1 "stored-generation $r2_3" + expect from p1 /stored-generation $r2_3 3/ + + send to p1 "stored-generation $r2_2" + expect from p1 /stored-generation $r2_2 1/ + + send to p1 "stored-roots $r2_3" + expect from p1 /stored-roots $r2_3 $r2_1 $r1/ + + send to p1 "stored-roots $r2_2" + expect from p1 /stored-roots $r2_2 $r2_1/ + + + # Set + ##### + + send to p1 "stored-set-add $r1" + expect from p1 /stored-set-add (blake2#[0-9a-f]*)/ capture s1 + send to p1 "stored-set-add $r2 $s1" + expect from p1 /stored-set-add (blake2#[0-9a-f]*)/ capture s2 + send to p1 "stored-set-add $r3 $s2" + expect from p1 /stored-set-add (blake2#[0-9a-f]*)/ capture s3 + send to p1 "stored-set-add $r4 $s3" + expect from p1 /stored-set-add (blake2#[0-9a-f]*)/ capture s4 + + send to p1 "stored-set-list $s1" + expect from p1: + /stored-set-item $r1/ + /stored-set-(.*)/ capture done1 + guard (done1 == "done") + + send to p1 "stored-set-list $s2" + expect from p1: + /stored-set-item $r2/ + /stored-set-(.*)/ capture done2 + guard (done2 == "done") + + send to p1 "stored-set-list $s3" + expect from p1: + /stored-set-item $r2 $r3/ + /stored-set-(.*)/ capture done3 + guard (done3 == "done") + + send to p1 "stored-set-list $s4" + expect from p1: + /stored-set-item $r4/ + /stored-set-(.*)/ capture done4 + guard (done4 == "done") + + + send to p1 "stored-set-add $r2_2 $s4" + expect from p1 /stored-set-add (blake2#[0-9a-f]*)/ capture s5 + send to p1 "stored-set-add $r2_3 $s5" + expect from p1 /stored-set-add (blake2#[0-9a-f]*)/ capture s6 + + send to p1 "stored-set-list $s5" + expect from p1: + /stored-set-item $r4/ + /stored-set-item $r2_2/ + /stored-set-(.*)/ capture done5 + guard (done5 == "done") + + send to p1 "stored-set-list $s6" + expect from p1: + /stored-set-item $r2_3/ + /stored-set-(.*)/ capture done6 + guard (done6 == "done") + + +test StorageWatcher: + spawn as p1 + spawn as p2 on p1.node + + send to p1: + "store rec" + "text:n 1" + "" + expect from p1: + /store-done (blake2#[0-9a-f]*)/ capture r1 + + send to p1: + "store rec" + "text:n 2" + "" + expect from p1: + /store-done (blake2#[0-9a-f]*)/ capture r2 + + send to p1: + "store rec" + "text:n 3" + "" + expect from p1: + /store-done (blake2#[0-9a-f]*)/ capture r3 + + send to p1: + "store rec" + "text:n 4" + "" + expect from p1: + /store-done (blake2#[0-9a-f]*)/ capture r4 + + let tid1 = "00000000-0000-0000-0000-000000000001" + let tid2 = "00000000-0000-0000-0000-000000000002" + + # Watch head from multiple processes + + send "head-create $tid1 $r1" to p1 + expect /head-create-done $tid1 ([0-9a-f-]+)/ from p1 capture hid1 + + send "head-watch $tid1 $hid1" to p1 + send "head-watch $tid1 $hid1" to p2 + + expect /head-watch-done $tid1 $hid1 ([0-9]+)/ from p1 capture w1_1 + expect /head-watch-done $tid1 $hid1 ([0-9]+)/ from p2 capture w2_1 + + local: + expect /head-watch-cb $w1_1 (blake2#[0-9a-f]+)/ from p1 capture new + guard (new == r1) + + local: + expect /head-watch-cb $w2_1 (blake2#[0-9a-f]+)/ from p2 capture new + guard (new == r1) + + send "head-replace $tid1 $hid1 $r2 $r1" to p1 + expect /head-replace-fail $tid1 $hid1 $r2 $r1 $r1/ from p1 + + send "head-replace $tid1 $hid1 $r1 $r2" to p1 + expect /head-replace-done $tid1 $hid1 $r1 $r2/ from p1 + + local: + expect /head-watch-cb $w1_1 (blake2#[0-9a-f]+)/ from p1 capture new + guard (new == r2) + + local: + expect /head-watch-cb $w2_1 (blake2#[0-9a-f]+)/ from p2 capture new + guard (new == r2) + + # Watch distinct heads and head types + + send "head-create $tid1 $r1" to p1 + expect /head-create-done $tid1 ([0-9a-f-]+)/ from p1 capture hid1_2 + + send "head-create $tid2 $r2" to p1 + expect /head-create-done $tid2 ([0-9a-f-]+)/ from p1 capture hid2 + + send "head-watch $tid1 $hid1_2" to p1 + send "head-watch $tid1 $hid1_2" to p2 + send "head-watch $tid2 $hid2" to p1 + send "head-watch $tid2 $hid2" to p2 + + expect /head-watch-done $tid1 $hid1_2 ([0-9]+)/ from p1 capture w1_1_2 + expect /head-watch-done $tid1 $hid1_2 ([0-9]+)/ from p2 capture w2_1_2 + expect /head-watch-done $tid2 $hid2 ([0-9]+)/ from p1 capture w1_2 + expect /head-watch-done $tid2 $hid2 ([0-9]+)/ from p2 capture w2_2 + + local: + expect /head-watch-cb $w1_1_2 (blake2#[0-9a-f]+)/ from p1 capture new + guard (new == r1) + + local: + expect /head-watch-cb $w2_1_2 (blake2#[0-9a-f]+)/ from p2 capture new + guard (new == r1) + + local: + expect /head-watch-cb $w1_2 (blake2#[0-9a-f]+)/ from p1 capture new + guard (new == r2) + + local: + expect /head-watch-cb $w2_2 (blake2#[0-9a-f]+)/ from p2 capture new + guard (new == r2) + + send "head-replace $tid1 $hid1_2 $r1 $r2" to p1 + expect /head-replace-done $tid1 $hid1_2 $r1 $r2/ from p1 + + local: + expect /head-watch-cb ([0-9]+) (blake2#[0-9a-f]+)/ from p1 capture w, new + guard (w == w1_1_2) + guard (new == r2) + + local: + expect /head-watch-cb ([0-9]+) (blake2#[0-9a-f]+)/ from p2 capture w, new + guard (w == w2_1_2) + guard (new == r2) + + send "head-replace $tid2 $hid2 $r2 $r3" to p1 + expect /head-replace-done $tid2 $hid2 $r2 $r3/ from p1 + + local: + expect /head-watch-cb ([0-9]+) (blake2#[0-9a-f]+)/ from p1 capture w, new + guard (w == w1_2) + guard (new == r3) + + local: + expect /head-watch-cb ([0-9]+) (blake2#[0-9a-f]+)/ from p2 capture w, new + guard (w == w2_2) + guard (new == r3) + + # Unwatch head + + send "head-unwatch $w1_1_2" to p1 + expect /head-unwatch-done $w1_1_2/ from p1 + + send "head-unwatch $w1_2" to p1 + expect /head-unwatch-done $w1_2/ from p1 + + send "head-replace $tid2 $hid2 $r3 $r4" to p1 + expect /head-replace-done $tid2 $hid2 $r3 $r4/ from p1 + + send "head-replace $tid1 $hid1_2 $r2 $r1" to p1 + expect /head-replace-done $tid1 $hid1_2 $r2 $r1/ from p1 + + send "head-replace $tid1 $hid1 $r2 $r3" to p1 + expect /head-replace-done $tid1 $hid1 $r2 $r3/ from p1 + + local: + expect /head-watch-cb $w2_2 (blake2#[0-9a-f]+)/ from p2 capture new + guard (new == r4) + + local: + expect /head-watch-cb $w2_1_2 (blake2#[0-9a-f]+)/ from p2 capture new + guard (new == r1) + + local: + expect /head-watch-cb $w2_1 (blake2#[0-9a-f]+)/ from p2 capture new + guard (new == r3) + + local: + expect /head-watch-cb ([0-9]+) (blake2#[0-9a-f]+)/ from p1 capture w, new + guard (w == w1_1) + guard (new == r3) + + # Multiple watchers on the same head + + send "head-watch $tid1 $hid1" to p1 + expect /head-watch-done $tid1 $hid1 ([0-9]+)/ from p1 capture w1_1b + + local: + expect /head-watch-cb $w1_1b (blake2#[0-9a-f]+)/ from p1 capture new + guard (new == r3) + + send "head-watch $tid1 $hid1" to p1 + expect /head-watch-done $tid1 $hid1 ([0-9]+)/ from p1 capture w1_1c + + local: + expect /head-watch-cb $w1_1c (blake2#[0-9a-f]+)/ from p1 capture new + guard (new == r3) + + send "head-replace $tid1 $hid1 $r3 $r4" to p1 + expect /head-replace-done $tid1 $hid1 $r3 $r4/ from p1 + + local: + expect /head-watch-cb $w1_1 (blake2#[0-9a-f]+)/ from p1 capture new + guard (new == r4) + + local: + expect /head-watch-cb $w1_1b (blake2#[0-9a-f]+)/ from p1 capture new + guard (new == r4) + + local: + expect /head-watch-cb $w1_1c (blake2#[0-9a-f]+)/ from p1 capture new + guard (new == r4) + + local: + expect /head-watch-cb $w2_1 (blake2#[0-9a-f]+)/ from p2 capture new + guard (new == r4) + + for w in [ w1_1, w1_1c ]: + send "head-unwatch $w" to p1 + expect /head-unwatch-done $w/ from p1 + + send "head-replace $tid1 $hid1 $r4 $r1" to p1 + expect /head-replace-done $tid1 $hid1 $r4 $r1/ from p1 + + send "head-replace $tid1 $hid1 $r1 $r2" to p1 + expect /head-replace-done $tid1 $hid1 $r1 $r2/ from p1 + + local: + expect /head-watch-cb ([0-9]+) (blake2#[0-9a-f]+)/ from p2 capture w, new + guard (w == w2_1) + guard (new == r1) + + local: + expect /head-watch-cb ([0-9]+) (blake2#[0-9a-f]+)/ from p2 capture w, new + guard (w == w2_1) + guard (new == r2) + + local: + expect /head-watch-cb ([0-9]+) (blake2#[0-9a-f]+)/ from p1 capture w, new + guard (w == w1_1b) + guard (new == r1) + + local: + expect /head-watch-cb ([0-9]+) (blake2#[0-9a-f]+)/ from p1 capture w, new + guard (w == w1_1b) + guard (new == r2) + + +test SharedStateWatcher: + let services = "attach,sync" + + spawn as p1 + spawn as p2 + send "create-identity Device1 Owner" to p1 + send "create-identity Device2" to p2 + send "watch-local-identity" to p1 + send "watch-local-identity" to p2 + send "start-server services $services" to p1 + send "start-server services $services" to p2 + expect from p1: + /local-identity Device1 Owner/ + /peer 1 addr ${p2.node.ip} 29665/ + /peer 1 id Device2/ + expect from p2: + /local-identity Device2/ + /peer 1 addr ${p1.node.ip} 29665/ + /peer 1 id Device1 Owner/ + + local: + send "attach-to 1" to p2 + expect /attach-request 1 ([0-9]*)/ from p1 capture code1 + expect /attach-response 1 ([0-9]*)/ from p2 capture code2 + guard (code1 == code2) + + send "attach-accept 1" to p1 + send "attach-accept 1" to p2 + expect /attach-request-done 1/ from p1 + expect /attach-response-done 1/ from p2 + expect /local-identity Device2 Owner/ from p2 + expect /peer 1 id Device2 Owner/ from p1 + + for i in [1..5]: + send "update-local-identity Owner2" to p1 + send "shared-state-get" to p1 + expect /shared-state-get (.*)/ from p1 capture s1 + + send "shared-state-wait $s1" to p2 + expect /shared-state-wait $s1/ from p2 + + send "update-local-identity Owner1" to p1 + send "shared-state-get" to p1 + expect /shared-state-get (.*)/ from p1 capture s2 + + send "shared-state-wait $s1" to p2 + send "shared-state-wait $s2" to p2 + expect /shared-state-wait $s1/ from p2 + expect /shared-state-wait $s2/ from p2 + + +test LocalStateKeepUnknown: + let refpat = /blake2#[0-9a-f]*/ + + spawn as p + with p: + send "create-identity Device" + send "watch-local-identity" + expect /local-identity Device/ + + send "local-state-get" + expect /local-state-get ($refpat)/ capture s1 + send "load $s1" + + expect /load-type rec [0-9]*/ + expect /load-line id:r ($refpat)/ capture id1 + local: + expect /load-(.*)/ capture done + guard (done == "done") + + send: + "store rec" + "id:r $id1" + "TEST:i 123" + "" + expect /store-done ($refpat)/ capture s2 + send "local-state-replace $s1 $s2" + expect /local-state-replace-done/ + + send "local-state-get" + expect /local-state-get $s2/ + + send "update-local-identity Device2" + expect /local-identity Device2/ + + send "local-state-get" + expect /local-state-get ($refpat)/ capture s3 + send "load $s3" + + expect /load-type rec [0-9]*/ + expect /load-line PREV:w $s2/ + expect /load-line id:r ($refpat)/ capture id2 + guard (id1 /= id2) + expect /load-line TEST:i 123/ + local: + expect /load-(.*)/ capture done + guard (done == "done") + + +test UnknownObjectType: + let refpat = /blake2#[0-9a-f]*/ + + spawn as p + spawn as p2 on p.node + + with p: + send: + "store test-unknown" + "TEST" + "" + expect /store-done ($refpat)/ capture r1 + + with p2: + send "load $r1" + expect /load-type test-unknown 5/ + expect /load-line TEST/ + local: + expect /load-(.*)/ capture done + guard (done == "done") + + +test UnknownRecordItemType: + let refpat = /blake2#[0-9a-f]*/ + + spawn as p + spawn as p2 on p.node + + with p: + send: + "store rec" + "test:unknown TEST" + "" + expect /store-done ($refpat)/ capture r1 + + with p2: + send "load $r1" + expect /load-type rec [0-9]+/ + expect /load-line test:unknown TEST/ + local: + expect /load-(.*)/ capture done + guard (done == "done") diff --git a/storage.test b/storage.test deleted file mode 100644 index 2230eac..0000000 --- a/storage.test +++ /dev/null @@ -1,523 +0,0 @@ -test Storage: - spawn as p1 - - # Root finding - ############### - - # Diamond history - send to p1: - "store rec" - "text:t First root" - "" - expect from p1: - /store-done (blake2#[0-9a-f]*)/ capture r1 - guard (r1 == "blake2#c4a8c69fbc8398acf76a2ec1e5a191f339c4d03c3eb425af19d6d7d5efac6b8e") - - send to p1: - "store rec" - "PREV:r $r1" - "" - expect from p1: - /store-done (blake2#[0-9a-f]*)/ capture r2 - - send to p1: - "store rec" - "text:t Second branch" - "PREV:r $r1" - "" - expect from p1: - /store-done (blake2#[0-9a-f]*)/ capture r3 - - send to p1: - "store rec" - "PREV:r $r2" - "PREV:r $r3" - "" - expect from p1: - /store-done (blake2#[0-9a-f]*)/ capture r4 - - send to p1 "stored-generation $r1" - expect from p1 /stored-generation $r1 0/ - - send to p1 "stored-generation $r2" - expect from p1 /stored-generation $r2 1/ - - send to p1 "stored-generation $r3" - expect from p1 /stored-generation $r3 1/ - - send to p1 "stored-generation $r4" - expect from p1 /stored-generation $r4 2/ - - send to p1 "stored-roots $r1" - expect from p1 /stored-roots $r1 $r1/ - - send to p1 "stored-roots $r2" - expect from p1 /stored-roots $r2 $r1/ - - send to p1 "stored-roots $r3" - expect from p1 /stored-roots $r3 $r1/ - - send to p1 "stored-roots $r4" - expect from p1 /stored-roots $r4 $r1/ - - # Attach second root - send to p1: - "store rec" - "text:t Second root" - "" - expect from p1: - /store-done (blake2#[0-9a-f]*)/ capture r2_1 - - send to p1: - "store rec" - "PREV:r $r2_1" - "" - expect from p1: - /store-done (blake2#[0-9a-f]*)/ capture r2_2 - - send to p1: - "store rec" - "PREV:r $r2_2" - "PREV:r $r4" - "" - expect from p1: - /store-done (blake2#[0-9a-f]*)/ capture r2_3 - - send to p1 "stored-generation $r2_3" - expect from p1 /stored-generation $r2_3 3/ - - send to p1 "stored-generation $r2_2" - expect from p1 /stored-generation $r2_2 1/ - - send to p1 "stored-roots $r2_3" - expect from p1 /stored-roots $r2_3 $r2_1 $r1/ - - send to p1 "stored-roots $r2_2" - expect from p1 /stored-roots $r2_2 $r2_1/ - - - # Set - ##### - - send to p1 "stored-set-add $r1" - expect from p1 /stored-set-add (blake2#[0-9a-f]*)/ capture s1 - send to p1 "stored-set-add $r2 $s1" - expect from p1 /stored-set-add (blake2#[0-9a-f]*)/ capture s2 - send to p1 "stored-set-add $r3 $s2" - expect from p1 /stored-set-add (blake2#[0-9a-f]*)/ capture s3 - send to p1 "stored-set-add $r4 $s3" - expect from p1 /stored-set-add (blake2#[0-9a-f]*)/ capture s4 - - send to p1 "stored-set-list $s1" - expect from p1: - /stored-set-item $r1/ - /stored-set-(.*)/ capture done1 - guard (done1 == "done") - - send to p1 "stored-set-list $s2" - expect from p1: - /stored-set-item $r2/ - /stored-set-(.*)/ capture done2 - guard (done2 == "done") - - send to p1 "stored-set-list $s3" - expect from p1: - /stored-set-item $r2 $r3/ - /stored-set-(.*)/ capture done3 - guard (done3 == "done") - - send to p1 "stored-set-list $s4" - expect from p1: - /stored-set-item $r4/ - /stored-set-(.*)/ capture done4 - guard (done4 == "done") - - - send to p1 "stored-set-add $r2_2 $s4" - expect from p1 /stored-set-add (blake2#[0-9a-f]*)/ capture s5 - send to p1 "stored-set-add $r2_3 $s5" - expect from p1 /stored-set-add (blake2#[0-9a-f]*)/ capture s6 - - send to p1 "stored-set-list $s5" - expect from p1: - /stored-set-item $r4/ - /stored-set-item $r2_2/ - /stored-set-(.*)/ capture done5 - guard (done5 == "done") - - send to p1 "stored-set-list $s6" - expect from p1: - /stored-set-item $r2_3/ - /stored-set-(.*)/ capture done6 - guard (done6 == "done") - - -test StorageWatcher: - spawn as p1 - spawn as p2 on p1.node - - send to p1: - "store rec" - "text:n 1" - "" - expect from p1: - /store-done (blake2#[0-9a-f]*)/ capture r1 - - send to p1: - "store rec" - "text:n 2" - "" - expect from p1: - /store-done (blake2#[0-9a-f]*)/ capture r2 - - send to p1: - "store rec" - "text:n 3" - "" - expect from p1: - /store-done (blake2#[0-9a-f]*)/ capture r3 - - send to p1: - "store rec" - "text:n 4" - "" - expect from p1: - /store-done (blake2#[0-9a-f]*)/ capture r4 - - let tid1 = "00000000-0000-0000-0000-000000000001" - let tid2 = "00000000-0000-0000-0000-000000000002" - - # Watch head from multiple processes - - send "head-create $tid1 $r1" to p1 - expect /head-create-done $tid1 ([0-9a-f-]+)/ from p1 capture hid1 - - send "head-watch $tid1 $hid1" to p1 - send "head-watch $tid1 $hid1" to p2 - - expect /head-watch-done $tid1 $hid1 ([0-9]+)/ from p1 capture w1_1 - expect /head-watch-done $tid1 $hid1 ([0-9]+)/ from p2 capture w2_1 - - local: - expect /head-watch-cb $w1_1 (blake2#[0-9a-f]+)/ from p1 capture new - guard (new == r1) - - local: - expect /head-watch-cb $w2_1 (blake2#[0-9a-f]+)/ from p2 capture new - guard (new == r1) - - send "head-replace $tid1 $hid1 $r2 $r1" to p1 - expect /head-replace-fail $tid1 $hid1 $r2 $r1 $r1/ from p1 - - send "head-replace $tid1 $hid1 $r1 $r2" to p1 - expect /head-replace-done $tid1 $hid1 $r1 $r2/ from p1 - - local: - expect /head-watch-cb $w1_1 (blake2#[0-9a-f]+)/ from p1 capture new - guard (new == r2) - - local: - expect /head-watch-cb $w2_1 (blake2#[0-9a-f]+)/ from p2 capture new - guard (new == r2) - - # Watch distinct heads and head types - - send "head-create $tid1 $r1" to p1 - expect /head-create-done $tid1 ([0-9a-f-]+)/ from p1 capture hid1_2 - - send "head-create $tid2 $r2" to p1 - expect /head-create-done $tid2 ([0-9a-f-]+)/ from p1 capture hid2 - - send "head-watch $tid1 $hid1_2" to p1 - send "head-watch $tid1 $hid1_2" to p2 - send "head-watch $tid2 $hid2" to p1 - send "head-watch $tid2 $hid2" to p2 - - expect /head-watch-done $tid1 $hid1_2 ([0-9]+)/ from p1 capture w1_1_2 - expect /head-watch-done $tid1 $hid1_2 ([0-9]+)/ from p2 capture w2_1_2 - expect /head-watch-done $tid2 $hid2 ([0-9]+)/ from p1 capture w1_2 - expect /head-watch-done $tid2 $hid2 ([0-9]+)/ from p2 capture w2_2 - - local: - expect /head-watch-cb $w1_1_2 (blake2#[0-9a-f]+)/ from p1 capture new - guard (new == r1) - - local: - expect /head-watch-cb $w2_1_2 (blake2#[0-9a-f]+)/ from p2 capture new - guard (new == r1) - - local: - expect /head-watch-cb $w1_2 (blake2#[0-9a-f]+)/ from p1 capture new - guard (new == r2) - - local: - expect /head-watch-cb $w2_2 (blake2#[0-9a-f]+)/ from p2 capture new - guard (new == r2) - - send "head-replace $tid1 $hid1_2 $r1 $r2" to p1 - expect /head-replace-done $tid1 $hid1_2 $r1 $r2/ from p1 - - local: - expect /head-watch-cb ([0-9]+) (blake2#[0-9a-f]+)/ from p1 capture w, new - guard (w == w1_1_2) - guard (new == r2) - - local: - expect /head-watch-cb ([0-9]+) (blake2#[0-9a-f]+)/ from p2 capture w, new - guard (w == w2_1_2) - guard (new == r2) - - send "head-replace $tid2 $hid2 $r2 $r3" to p1 - expect /head-replace-done $tid2 $hid2 $r2 $r3/ from p1 - - local: - expect /head-watch-cb ([0-9]+) (blake2#[0-9a-f]+)/ from p1 capture w, new - guard (w == w1_2) - guard (new == r3) - - local: - expect /head-watch-cb ([0-9]+) (blake2#[0-9a-f]+)/ from p2 capture w, new - guard (w == w2_2) - guard (new == r3) - - # Unwatch head - - send "head-unwatch $w1_1_2" to p1 - expect /head-unwatch-done $w1_1_2/ from p1 - - send "head-unwatch $w1_2" to p1 - expect /head-unwatch-done $w1_2/ from p1 - - send "head-replace $tid2 $hid2 $r3 $r4" to p1 - expect /head-replace-done $tid2 $hid2 $r3 $r4/ from p1 - - send "head-replace $tid1 $hid1_2 $r2 $r1" to p1 - expect /head-replace-done $tid1 $hid1_2 $r2 $r1/ from p1 - - send "head-replace $tid1 $hid1 $r2 $r3" to p1 - expect /head-replace-done $tid1 $hid1 $r2 $r3/ from p1 - - local: - expect /head-watch-cb $w2_2 (blake2#[0-9a-f]+)/ from p2 capture new - guard (new == r4) - - local: - expect /head-watch-cb $w2_1_2 (blake2#[0-9a-f]+)/ from p2 capture new - guard (new == r1) - - local: - expect /head-watch-cb $w2_1 (blake2#[0-9a-f]+)/ from p2 capture new - guard (new == r3) - - local: - expect /head-watch-cb ([0-9]+) (blake2#[0-9a-f]+)/ from p1 capture w, new - guard (w == w1_1) - guard (new == r3) - - # Multiple watchers on the same head - - send "head-watch $tid1 $hid1" to p1 - expect /head-watch-done $tid1 $hid1 ([0-9]+)/ from p1 capture w1_1b - - local: - expect /head-watch-cb $w1_1b (blake2#[0-9a-f]+)/ from p1 capture new - guard (new == r3) - - send "head-watch $tid1 $hid1" to p1 - expect /head-watch-done $tid1 $hid1 ([0-9]+)/ from p1 capture w1_1c - - local: - expect /head-watch-cb $w1_1c (blake2#[0-9a-f]+)/ from p1 capture new - guard (new == r3) - - send "head-replace $tid1 $hid1 $r3 $r4" to p1 - expect /head-replace-done $tid1 $hid1 $r3 $r4/ from p1 - - local: - expect /head-watch-cb $w1_1 (blake2#[0-9a-f]+)/ from p1 capture new - guard (new == r4) - - local: - expect /head-watch-cb $w1_1b (blake2#[0-9a-f]+)/ from p1 capture new - guard (new == r4) - - local: - expect /head-watch-cb $w1_1c (blake2#[0-9a-f]+)/ from p1 capture new - guard (new == r4) - - local: - expect /head-watch-cb $w2_1 (blake2#[0-9a-f]+)/ from p2 capture new - guard (new == r4) - - for w in [ w1_1, w1_1c ]: - send "head-unwatch $w" to p1 - expect /head-unwatch-done $w/ from p1 - - send "head-replace $tid1 $hid1 $r4 $r1" to p1 - expect /head-replace-done $tid1 $hid1 $r4 $r1/ from p1 - - send "head-replace $tid1 $hid1 $r1 $r2" to p1 - expect /head-replace-done $tid1 $hid1 $r1 $r2/ from p1 - - local: - expect /head-watch-cb ([0-9]+) (blake2#[0-9a-f]+)/ from p2 capture w, new - guard (w == w2_1) - guard (new == r1) - - local: - expect /head-watch-cb ([0-9]+) (blake2#[0-9a-f]+)/ from p2 capture w, new - guard (w == w2_1) - guard (new == r2) - - local: - expect /head-watch-cb ([0-9]+) (blake2#[0-9a-f]+)/ from p1 capture w, new - guard (w == w1_1b) - guard (new == r1) - - local: - expect /head-watch-cb ([0-9]+) (blake2#[0-9a-f]+)/ from p1 capture w, new - guard (w == w1_1b) - guard (new == r2) - - -test SharedStateWatcher: - let services = "attach,sync" - - spawn as p1 - spawn as p2 - send "create-identity Device1 Owner" to p1 - send "create-identity Device2" to p2 - send "watch-local-identity" to p1 - send "watch-local-identity" to p2 - send "start-server services $services" to p1 - send "start-server services $services" to p2 - expect from p1: - /local-identity Device1 Owner/ - /peer 1 addr ${p2.node.ip} 29665/ - /peer 1 id Device2/ - expect from p2: - /local-identity Device2/ - /peer 1 addr ${p1.node.ip} 29665/ - /peer 1 id Device1 Owner/ - - local: - send "attach-to 1" to p2 - expect /attach-request 1 ([0-9]*)/ from p1 capture code1 - expect /attach-response 1 ([0-9]*)/ from p2 capture code2 - guard (code1 == code2) - - send "attach-accept 1" to p1 - send "attach-accept 1" to p2 - expect /attach-request-done 1/ from p1 - expect /attach-response-done 1/ from p2 - expect /local-identity Device2 Owner/ from p2 - expect /peer 1 id Device2 Owner/ from p1 - - for i in [1..5]: - send "update-local-identity Owner2" to p1 - send "shared-state-get" to p1 - expect /shared-state-get (.*)/ from p1 capture s1 - - send "shared-state-wait $s1" to p2 - expect /shared-state-wait $s1/ from p2 - - send "update-local-identity Owner1" to p1 - send "shared-state-get" to p1 - expect /shared-state-get (.*)/ from p1 capture s2 - - send "shared-state-wait $s1" to p2 - send "shared-state-wait $s2" to p2 - expect /shared-state-wait $s1/ from p2 - expect /shared-state-wait $s2/ from p2 - - -test LocalStateKeepUnknown: - let refpat = /blake2#[0-9a-f]*/ - - spawn as p - with p: - send "create-identity Device" - send "watch-local-identity" - expect /local-identity Device/ - - send "local-state-get" - expect /local-state-get ($refpat)/ capture s1 - send "load $s1" - - expect /load-type rec [0-9]*/ - expect /load-line id:r ($refpat)/ capture id1 - local: - expect /load-(.*)/ capture done - guard (done == "done") - - send: - "store rec" - "id:r $id1" - "TEST:i 123" - "" - expect /store-done ($refpat)/ capture s2 - send "local-state-replace $s1 $s2" - expect /local-state-replace-done/ - - send "local-state-get" - expect /local-state-get $s2/ - - send "update-local-identity Device2" - expect /local-identity Device2/ - - send "local-state-get" - expect /local-state-get ($refpat)/ capture s3 - send "load $s3" - - expect /load-type rec [0-9]*/ - expect /load-line PREV:w $s2/ - expect /load-line id:r ($refpat)/ capture id2 - guard (id1 /= id2) - expect /load-line TEST:i 123/ - local: - expect /load-(.*)/ capture done - guard (done == "done") - - -test UnknownObjectType: - let refpat = /blake2#[0-9a-f]*/ - - spawn as p - spawn as p2 on p.node - - with p: - send: - "store test-unknown" - "TEST" - "" - expect /store-done ($refpat)/ capture r1 - - with p2: - send "load $r1" - expect /load-type test-unknown 5/ - expect /load-line TEST/ - local: - expect /load-(.*)/ capture done - guard (done == "done") - - -test UnknownRecordItemType: - let refpat = /blake2#[0-9a-f]*/ - - spawn as p - spawn as p2 on p.node - - with p: - send: - "store rec" - "test:unknown TEST" - "" - expect /store-done ($refpat)/ capture r1 - - with p2: - send "load $r1" - expect /load-type rec [0-9]+/ - expect /load-line test:unknown TEST/ - local: - expect /load-(.*)/ capture done - guard (done == "done") diff --git a/sync.et b/sync.et new file mode 100644 index 0000000..d465b11 --- /dev/null +++ b/sync.et @@ -0,0 +1,95 @@ +test: + let services = "attach,sync" + + spawn as p1 + spawn as p2 + send "create-identity Device1 Owner" to p1 + send "create-identity Device2" to p2 + send "watch-local-identity" to p1 + send "watch-local-identity" to p2 + send "watch-shared-identity" to p1 + send "watch-shared-identity" to p2 + send "start-server services $services" to p1 + send "start-server services $services" to p2 + expect from p1: + /local-identity Device1 Owner/ + /shared-identity Owner/ + /peer 1 addr ${p2.node.ip} 29665/ + /peer 1 id Device2/ + expect from p2: + /local-identity Device2/ + /peer 1 addr ${p1.node.ip} 29665/ + /peer 1 id Device1 Owner/ + + send "attach-to 1" to p2 + local: + expect /attach-request 1 ([0-9]*)/ from p1 capture code1 + expect /attach-response 1 ([0-9]*)/ from p2 capture code2 + guard (code1 == code2) + + send "attach-accept 1" to p1 + send "attach-accept 1" to p2 + expect /attach-request-done 1/ from p1 + expect /attach-response-done 1/ from p2 + expect /local-identity Device2 Owner/ from p2 + expect /shared-identity Owner/ from p2 + expect /peer 1 id Device2 Owner/ from p1 + + send "update-shared-identity NewOwner" to p1 + expect /shared-identity NewOwner/ from p1 + expect /shared-identity NewOwner/ from p2 + + send "update-shared-identity NewOwner2" to p2 + expect /shared-identity NewOwner2/ from p1 + expect /shared-identity NewOwner2/ from p2 + + send "update-shared-identity NewOwner3" to p1 + expect /shared-identity NewOwner3/ from p1 + expect /shared-identity NewOwner3/ from p2 + + send "shared-state-get" to p1 + expect /shared-state-get (.*)/ from p1 capture p1state + send "shared-state-wait $p1state" to p2 + expect /shared-state-wait $p1state/ from p2 + + subnet s + spawn on s as p3 + + with p3: + send "create-identity Device3" + send "watch-local-identity" + send "watch-shared-identity" + send "start-server services $services" + + send "peer-add ${p1.node.ip}" + + expect: + /local-identity Device3/ + /peer 1 addr ${p1.node.ip} 29665/ + /peer 1 id Device1 NewOwner3/ + + expect from p1: + /peer 2 addr ${p3.node.ip} 29665/ + /peer 2 id Device3/ + + send "attach-to 1" to p3 + local: + expect /attach-request 2 ([0-9]*)/ from p1 capture code1 + expect /attach-response 1 ([0-9]*)/ from p3 capture code2 + guard (code1 == code2) + + send "attach-accept 2" to p1 + send "attach-accept 1" to p3 + + expect /local-identity Device3 NewOwner3/ from p3 + expect /shared-identity NewOwner3/ from p3 + + send "update-shared-identity NewOwner4" to p3 + expect /shared-identity NewOwner4/ from p1 + expect /shared-identity NewOwner4/ from p2 + expect /shared-identity NewOwner4/ from p3 + + send "update-shared-identity NewOwner5" to p2 + expect /shared-identity NewOwner5/ from p1 + expect /shared-identity NewOwner5/ from p2 + expect /shared-identity NewOwner5/ from p3 diff --git a/sync.test b/sync.test deleted file mode 100644 index d465b11..0000000 --- a/sync.test +++ /dev/null @@ -1,95 +0,0 @@ -test: - let services = "attach,sync" - - spawn as p1 - spawn as p2 - send "create-identity Device1 Owner" to p1 - send "create-identity Device2" to p2 - send "watch-local-identity" to p1 - send "watch-local-identity" to p2 - send "watch-shared-identity" to p1 - send "watch-shared-identity" to p2 - send "start-server services $services" to p1 - send "start-server services $services" to p2 - expect from p1: - /local-identity Device1 Owner/ - /shared-identity Owner/ - /peer 1 addr ${p2.node.ip} 29665/ - /peer 1 id Device2/ - expect from p2: - /local-identity Device2/ - /peer 1 addr ${p1.node.ip} 29665/ - /peer 1 id Device1 Owner/ - - send "attach-to 1" to p2 - local: - expect /attach-request 1 ([0-9]*)/ from p1 capture code1 - expect /attach-response 1 ([0-9]*)/ from p2 capture code2 - guard (code1 == code2) - - send "attach-accept 1" to p1 - send "attach-accept 1" to p2 - expect /attach-request-done 1/ from p1 - expect /attach-response-done 1/ from p2 - expect /local-identity Device2 Owner/ from p2 - expect /shared-identity Owner/ from p2 - expect /peer 1 id Device2 Owner/ from p1 - - send "update-shared-identity NewOwner" to p1 - expect /shared-identity NewOwner/ from p1 - expect /shared-identity NewOwner/ from p2 - - send "update-shared-identity NewOwner2" to p2 - expect /shared-identity NewOwner2/ from p1 - expect /shared-identity NewOwner2/ from p2 - - send "update-shared-identity NewOwner3" to p1 - expect /shared-identity NewOwner3/ from p1 - expect /shared-identity NewOwner3/ from p2 - - send "shared-state-get" to p1 - expect /shared-state-get (.*)/ from p1 capture p1state - send "shared-state-wait $p1state" to p2 - expect /shared-state-wait $p1state/ from p2 - - subnet s - spawn on s as p3 - - with p3: - send "create-identity Device3" - send "watch-local-identity" - send "watch-shared-identity" - send "start-server services $services" - - send "peer-add ${p1.node.ip}" - - expect: - /local-identity Device3/ - /peer 1 addr ${p1.node.ip} 29665/ - /peer 1 id Device1 NewOwner3/ - - expect from p1: - /peer 2 addr ${p3.node.ip} 29665/ - /peer 2 id Device3/ - - send "attach-to 1" to p3 - local: - expect /attach-request 2 ([0-9]*)/ from p1 capture code1 - expect /attach-response 1 ([0-9]*)/ from p3 capture code2 - guard (code1 == code2) - - send "attach-accept 2" to p1 - send "attach-accept 1" to p3 - - expect /local-identity Device3 NewOwner3/ from p3 - expect /shared-identity NewOwner3/ from p3 - - send "update-shared-identity NewOwner4" to p3 - expect /shared-identity NewOwner4/ from p1 - expect /shared-identity NewOwner4/ from p2 - expect /shared-identity NewOwner4/ from p3 - - send "update-shared-identity NewOwner5" to p2 - expect /shared-identity NewOwner5/ from p1 - expect /shared-identity NewOwner5/ from p2 - expect /shared-identity NewOwner5/ from p3 -- cgit v1.2.3 From f956fb158325f19c91d3e531332beb5538d1ae34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sat, 2 Aug 2025 13:50:08 +0200 Subject: (test) Function to compute symmetric difference between stored histories --- graph.et | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 graph.et diff --git a/graph.et b/graph.et new file mode 100644 index 0000000..38ec3c4 --- /dev/null +++ b/graph.et @@ -0,0 +1,111 @@ +module graph + +test StoredDifference: + spawn as p1 + with p1: + # ref names: r_ + + send: + "store rec" + "num:i 1" + "" + expect /store-done (blake2#[0-9a-f]*)/ capture r1_1 + + send: + "store rec" + "PREV:r $r1_1" + "" + expect /store-done (blake2#[0-9a-f]*)/ capture r2_1 + + send "stored-difference $r2_1 |" + expect /stored-difference-item $r1_1/ + expect /stored-difference-item $r2_1/ + local: + expect /stored-difference-(.*)/ capture done + guard (done == "done") + + send: + "store rec" + "PREV:r $r2_1" + "num:i 1" + "" + expect /store-done (blake2#[0-9a-f]*)/ capture r3_1 + + send "stored-difference $r1_1 | $r3_1" + expect /stored-difference-item $r2_1/ + expect /stored-difference-item $r3_1/ + local: + expect /stored-difference-(.*)/ capture done + guard (done == "done") + + send: + "store rec" + "PREV:r $r2_1" + "num:i 2" + "" + expect /store-done (blake2#[0-9a-f]*)/ capture r3_2 + + send: + "store rec" + "PREV:r $r3_1" + "num:i 1" + "" + expect /store-done (blake2#[0-9a-f]*)/ capture r4_1 + + send: + "store rec" + "PREV:r $r3_2" + "num:i 2" + "" + expect /store-done (blake2#[0-9a-f]*)/ capture r4_2 + + send "stored-difference $r4_1 | $r4_2" + expect /stored-difference-item $r3_1/ + expect /stored-difference-item $r3_2/ + expect /stored-difference-item $r4_1/ + expect /stored-difference-item $r4_2/ + local: + expect /stored-difference-(.*)/ capture done + guard (done == "done") + + + send: + "store rec" + "PREV:r $r2_1" + "num:i 3" + "" + expect /store-done (blake2#[0-9a-f]*)/ capture r3_3 + + send: + "store rec" + "PREV:r $r3_2" + "PREV:r $r3_3" + "num:i 3" + "" + expect /store-done (blake2#[0-9a-f]*)/ capture r4_3 + + send: + "store rec" + "PREV:r $r3_3" + "num:i 4" + "" + expect /store-done (blake2#[0-9a-f]*)/ capture r4_4 + + send "stored-difference $r4_1 $r4_2 | $r4_3 $r4_4" + expect /stored-difference-item $r3_1/ + expect /stored-difference-item $r3_3/ + expect /stored-difference-item $r4_1/ + expect /stored-difference-item $r4_2/ + expect /stored-difference-item $r4_3/ + expect /stored-difference-item $r4_4/ + local: + expect /stored-difference-(.*)/ capture done + guard (done == "done") + + send "stored-difference $r1_1 $r2_1 $r3_2 $r3_3 | $r4_1 $r4_3" + expect /stored-difference-item $r3_1/ + expect /stored-difference-item $r4_1/ + expect /stored-difference-item $r4_3/ + local: + expect /stored-difference-(.*)/ capture done + guard (done == "done") -- cgit v1.2.3 From bcee677fe74dc4772cefe059527a07dcb8107468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sat, 2 Aug 2025 18:57:56 +0200 Subject: (test) Watch direct messages using local state diffs Changelog: API: Replaced `watchReceivedDirectMessages` with `watchDirectMessageThreads` --- message.et | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/message.et b/message.et index 2990d0f..acdfc27 100644 --- a/message.et +++ b/message.et @@ -28,16 +28,20 @@ test DirectMessage: for i in [1..2]: send "dm-send-peer $peer1_2 hello$i" to p1 + expect /dm-sent from Owner1 text hello$i/ from p1 expect /dm-received from Owner1 text hello$i/ from p2 for i in [1..2]: send "dm-send-peer $peer2_1 hi$i" to p2 + expect /dm-sent from Owner2 text hi$i/ from p2 expect /dm-received from Owner2 text hi$i/ from p1 for i in [3..4]: send "dm-send-peer $peer1_2 hello$i" to p1 + expect /dm-sent from Owner1 text hello$i/ from p1 expect /dm-received from Owner1 text hello$i/ from p2 send "dm-send-peer $peer2_1 hi$i" to p2 + expect /dm-sent from Owner2 text hi$i/ from p2 expect /dm-received from Owner2 text hi$i/ from p1 # Create contacts @@ -67,16 +71,20 @@ test DirectMessage: for i in [1..2]: send "dm-send-contact $c1_2 hello_c_$i" to p1 + expect /dm-sent from Owner1 text hello_c_$i/ from p1 expect /dm-received from Owner1 text hello_c_$i/ from p2 for i in [1..2]: send "dm-send-contact $c2_1 hi_c_$i" to p2 + expect /dm-sent from Owner2 text hi_c_$i/ from p2 expect /dm-received from Owner2 text hi_c_$i/ from p1 for i in [3..4]: send "dm-send-contact $c1_2 hello_c_$i" to p1 + expect /dm-sent from Owner1 text hello_c_$i/ from p1 expect /dm-received from Owner1 text hello_c_$i/ from p2 send "dm-send-contact $c2_1 hi_c_$i" to p2 + expect /dm-sent from Owner2 text hi_c_$i/ from p2 expect /dm-received from Owner2 text hi_c_$i/ from p1 send "dm-list-contact $c1_2" to p1 @@ -135,6 +143,7 @@ test DirectMessage: send "start-server services $services" to p2 send "dm-send-contact $c1_2 while_offline" to p1 + expect /dm-sent from Owner1 text while_offline/ from p1 send "start-server services $services" to p1 expect /dm-received from Owner1 text while_offline/ from p2 @@ -148,8 +157,7 @@ test DirectMessage: send "start-server services $services" to p1 send "dm-send-contact $c1_2 while_peer_offline" to p1 - # TODO: sync from p1 on peer p2 discovery not ensured without addition wait - #wait + expect /dm-sent from Owner1 text while_peer_offline/ from p1 send "start-server services $services" to p2 expect /dm-received from Owner1 text while_peer_offline/ from p2 -- cgit v1.2.3