Skip to content
Snippets Groups Projects
Commit a156179e authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Fix thread issue in peer_unit test

parent 7e4570f1
No related branches found
No related tags found
No related merge requests found
Pipeline #9715 passed
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
#include <memory> #include <memory>
//#include <map> //#include <map>
#include <tuple> #include <tuple>
#include <thread>
#include <chrono>
#include <ftl/net/peer.hpp> #include <ftl/net/peer.hpp>
#include <ftl/net/protocol.hpp> #include <ftl/net/protocol.hpp>
...@@ -19,6 +21,8 @@ ...@@ -19,6 +21,8 @@
using std::tuple; using std::tuple;
using std::get; using std::get;
using ftl::net::Peer; using ftl::net::Peer;
using std::this_thread::sleep_for;
using std::chrono::milliseconds;
#ifdef WIN32 #ifdef WIN32
#pragma comment(lib, "Ws2_32.lib") #pragma comment(lib, "Ws2_32.lib")
...@@ -157,6 +161,8 @@ TEST_CASE("Peer(int)", "[]") { ...@@ -157,6 +161,8 @@ TEST_CASE("Peer(int)", "[]") {
send_handshake(s); send_handshake(s);
s.mock_data(); s.mock_data();
sleep_for(milliseconds(50));
REQUIRE( s.status() == Peer::kConnected ); REQUIRE( s.status() == Peer::kConnected );
} }
...@@ -167,6 +173,8 @@ TEST_CASE("Peer(int)", "[]") { ...@@ -167,6 +173,8 @@ TEST_CASE("Peer(int)", "[]") {
send_handshake(s); send_handshake(s);
s.mock_data(); s.mock_data();
sleep_for(milliseconds(50));
REQUIRE( s.getFTLVersion() == (8 << 16) + (5 << 8) + 2 ); REQUIRE( s.getFTLVersion() == (8 << 16) + (5 << 8) + 2 );
} }
...@@ -183,6 +191,7 @@ TEST_CASE("Peer::call()", "[rpc]") { ...@@ -183,6 +191,7 @@ TEST_CASE("Peer::call()", "[rpc]") {
MockPeer s; MockPeer s;
send_handshake(s); send_handshake(s);
s.mock_data(); s.mock_data();
sleep_for(milliseconds(50));
SECTION("one argument call") { SECTION("one argument call") {
REQUIRE( s.isConnected() ); REQUIRE( s.isConnected() );
...@@ -199,6 +208,7 @@ TEST_CASE("Peer::call()", "[rpc]") { ...@@ -199,6 +208,7 @@ TEST_CASE("Peer::call()", "[rpc]") {
msgpack::pack(buf, res_obj); msgpack::pack(buf, res_obj);
fakedata[0] = buf.str(); fakedata[0] = buf.str();
s.mock_data(); s.mock_data();
sleep_for(milliseconds(50));
}); });
int res = s.call<int>("test1", 44); int res = s.call<int>("test1", 44);
...@@ -223,6 +233,7 @@ TEST_CASE("Peer::call()", "[rpc]") { ...@@ -223,6 +233,7 @@ TEST_CASE("Peer::call()", "[rpc]") {
msgpack::pack(buf, res_obj); msgpack::pack(buf, res_obj);
fakedata[0] = buf.str(); fakedata[0] = buf.str();
s.mock_data(); s.mock_data();
sleep_for(milliseconds(50));
}); });
int res = s.call<int>("test1"); int res = s.call<int>("test1");
...@@ -237,6 +248,7 @@ TEST_CASE("Peer::bind()", "[rpc]") { ...@@ -237,6 +248,7 @@ TEST_CASE("Peer::bind()", "[rpc]") {
MockPeer s; MockPeer s;
send_handshake(s); send_handshake(s);
s.mock_data(); s.mock_data();
sleep_for(milliseconds(50));
SECTION("no argument call") { SECTION("no argument call") {
bool done = false; bool done = false;
...@@ -247,6 +259,7 @@ TEST_CASE("Peer::bind()", "[rpc]") { ...@@ -247,6 +259,7 @@ TEST_CASE("Peer::bind()", "[rpc]") {
s.send("hello"); s.send("hello");
s.mock_data(); // Force it to read the fake send... s.mock_data(); // Force it to read the fake send...
sleep_for(milliseconds(50));
REQUIRE( done ); REQUIRE( done );
} }
...@@ -260,6 +273,7 @@ TEST_CASE("Peer::bind()", "[rpc]") { ...@@ -260,6 +273,7 @@ TEST_CASE("Peer::bind()", "[rpc]") {
s.send("hello", 55); s.send("hello", 55);
s.mock_data(); // Force it to read the fake send... s.mock_data(); // Force it to read the fake send...
sleep_for(milliseconds(50));
REQUIRE( (done == 55) ); REQUIRE( (done == 55) );
} }
...@@ -273,6 +287,7 @@ TEST_CASE("Peer::bind()", "[rpc]") { ...@@ -273,6 +287,7 @@ TEST_CASE("Peer::bind()", "[rpc]") {
s.send("hello", 55, "world"); s.send("hello", 55, "world");
s.mock_data(); // Force it to read the fake send... s.mock_data(); // Force it to read the fake send...
sleep_for(milliseconds(50));
REQUIRE( (done == "world") ); REQUIRE( (done == "world") );
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment