aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-10-21 08:52:53 +0200
committerdec05eba <dec05eba@protonmail.com>2020-08-18 22:56:48 +0200
commit40510daeca17b3db2cad0c9101d8f513df7127d1 (patch)
tree608232662f9f0c8abbff1af1aa4bfb0ef1a84282 /tests
parent980312b2a6e96c6d301d30d38922f8a2cc315c92 (diff)
Fix concurrent connection to the same address
Diffstat (limited to 'tests')
-rw-r--r--tests/main.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/main.cpp b/tests/main.cpp
index d6c37e2..e262e02 100644
--- a/tests/main.cpp
+++ b/tests/main.cpp
@@ -11,6 +11,7 @@ const int PORT = 35231;
int main()
{
const sibs::PubsubKey key("abcdefghijklmnopqrstuvxyz0123456789", 35);
+ const sibs::PubsubKey key2("zbcdefghcjklmn3pqrs5uvx2z0123F56789", 35);
sibs::BootstrapNode boostrapNode(sibs::Ipv4(nullptr, PORT));
sibs::BootstrapConnection connection1(sibs::Ipv4("127.0.0.1", PORT));
@@ -36,9 +37,26 @@ int main()
gotAsdf2 = true;
return true;
});
+
+ bool gotListen = false;
+ connection1.listen(key2, [&gotListen](const sibs::DirectConnectionPeer *peer, const void *data, const sibs::usize size)
+ {
+ if(size == 14 && strncmp((const char*)data, "secondListener", 14) == 0)
+ gotListen = true;
+ return true;
+ });
+
+ bool gotListen2 = false;
+ connection2.listen(key2, [&gotListen2](const sibs::DirectConnectionPeer *peer, const void *data, const sibs::usize size)
+ {
+ if(size == 14 && strncmp((const char*)data, "secondListener", 14) == 0)
+ gotListen2 = true;
+ return true;
+ });
connection1.put(key, "hello", 5);
connection2.put(key, "asdf", 4);
+ connection1.put(key2, "secondListener", 14);
std::this_thread::sleep_for(std::chrono::seconds(6));
REQUIRE(gotData1);
@@ -46,5 +64,8 @@ int main()
REQUIRE(gotData2);
REQUIRE(gotAsdf2);
+ REQUIRE(gotListen);
+ REQUIRE(gotListen2);
+
return 0;
}