From e81aea0fc96a2eb44e09d3aa0aad1e7d11878cae Mon Sep 17 00:00:00 2001 From: dec05eba <0xdec05eba@gmail.com> Date: Sun, 21 Oct 2018 08:52:53 +0200 Subject: Fix concurrent connection to the same address --- tests/main.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests') 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; } -- cgit v1.2.3