mirror of
https://github.com/falk-werner/webfuse-provider
synced 2024-10-27 20:44:10 +00:00
fix: fixed deadlock in tests (wait for client to connect, instead on relying on the server)
This commit is contained in:
parent
ed39db2d8d
commit
edcad5dc4c
@ -66,22 +66,21 @@ TEST(AdapterClient, Connect)
|
|||||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_GET_TLS_CONFIG, _)).Times(1);
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_GET_TLS_CONFIG, _)).Times(1);
|
||||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CLEANUP, nullptr)).Times(1);
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CLEANUP, nullptr)).Times(1);
|
||||||
|
|
||||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CONNECTED, nullptr)).Times(1);
|
bool connected = false;
|
||||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_DISCONNECTED, nullptr)).Times(1);
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CONNECTED, nullptr)).Times(1)
|
||||||
|
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { connected = true; }));
|
||||||
|
|
||||||
|
bool disconnected = false;
|
||||||
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_DISCONNECTED, nullptr)).Times(1)
|
||||||
|
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { disconnected = true; }));
|
||||||
|
|
||||||
AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), server.GetUrl());
|
AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), server.GetUrl());
|
||||||
|
|
||||||
client.Connect();
|
client.Connect();
|
||||||
while (!server.IsConnected())
|
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return connected; }));
|
||||||
{
|
|
||||||
watcher.check();
|
|
||||||
}
|
|
||||||
|
|
||||||
client.Disconnect();
|
client.Disconnect();
|
||||||
while (server.IsConnected())
|
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return disconnected; }));
|
||||||
{
|
|
||||||
watcher.check();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(AdapterClient, Authenticate)
|
TEST(AdapterClient, Authenticate)
|
||||||
@ -95,32 +94,32 @@ TEST(AdapterClient, Authenticate)
|
|||||||
|
|
||||||
MockAdapterClientCallback callback;
|
MockAdapterClientCallback callback;
|
||||||
EXPECT_CALL(callback, Invoke(_, _, _)).Times(AnyNumber());
|
EXPECT_CALL(callback, Invoke(_, _, _)).Times(AnyNumber());
|
||||||
|
|
||||||
|
bool connected = false;
|
||||||
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CONNECTED, nullptr)).Times(1)
|
||||||
|
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { connected = true; }));
|
||||||
|
|
||||||
|
bool disconnected = false;
|
||||||
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_DISCONNECTED, nullptr)).Times(1)
|
||||||
|
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { disconnected = true; }));
|
||||||
|
|
||||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_AUTHENTICATE_GET_CREDENTIALS, _)).Times(1)
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_AUTHENTICATE_GET_CREDENTIALS, _)).Times(1)
|
||||||
.WillOnce(Invoke(GetCredentials));
|
.WillOnce(Invoke(GetCredentials));
|
||||||
bool called = false;
|
|
||||||
|
bool authenticated = false;
|
||||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_AUTHENTICATED, nullptr)).Times(1)
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_AUTHENTICATED, nullptr)).Times(1)
|
||||||
.WillOnce(Invoke([&called] (wf_client *, int, void *) mutable {
|
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { authenticated = true; }));
|
||||||
called = true;
|
|
||||||
}));
|
|
||||||
|
|
||||||
AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), server.GetUrl());
|
AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), server.GetUrl());
|
||||||
|
|
||||||
client.Connect();
|
client.Connect();
|
||||||
while (!server.IsConnected())
|
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return connected; }));
|
||||||
{
|
|
||||||
watcher.check();
|
|
||||||
}
|
|
||||||
|
|
||||||
client.Authenticate();
|
client.Authenticate();
|
||||||
while (!called) {
|
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return authenticated; }));
|
||||||
watcher.check();
|
|
||||||
}
|
|
||||||
|
|
||||||
client.Disconnect();
|
client.Disconnect();
|
||||||
while (server.IsConnected())
|
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return disconnected; }));
|
||||||
{
|
|
||||||
watcher.check();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(AdapterClient, AuthenticateFailedWithoutConnect)
|
TEST(AdapterClient, AuthenticateFailedWithoutConnect)
|
||||||
@ -140,9 +139,7 @@ TEST(AdapterClient, AuthenticateFailedWithoutConnect)
|
|||||||
AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), "");
|
AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), "");
|
||||||
|
|
||||||
client.Authenticate();
|
client.Authenticate();
|
||||||
while (!called) {
|
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return called; }));
|
||||||
watcher.check();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(AdapterClient, AuthenticationFailed)
|
TEST(AdapterClient, AuthenticationFailed)
|
||||||
@ -156,8 +153,18 @@ TEST(AdapterClient, AuthenticationFailed)
|
|||||||
|
|
||||||
MockAdapterClientCallback callback;
|
MockAdapterClientCallback callback;
|
||||||
EXPECT_CALL(callback, Invoke(_, _, _)).Times(AnyNumber());
|
EXPECT_CALL(callback, Invoke(_, _, _)).Times(AnyNumber());
|
||||||
|
|
||||||
|
bool connected = false;
|
||||||
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CONNECTED, nullptr)).Times(1)
|
||||||
|
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { connected = true; }));
|
||||||
|
|
||||||
|
bool disconnected = false;
|
||||||
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_DISCONNECTED, nullptr)).Times(1)
|
||||||
|
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { disconnected = true; }));
|
||||||
|
|
||||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_AUTHENTICATE_GET_CREDENTIALS, _)).Times(1)
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_AUTHENTICATE_GET_CREDENTIALS, _)).Times(1)
|
||||||
.WillOnce(Invoke(GetCredentials));
|
.WillOnce(Invoke(GetCredentials));
|
||||||
|
|
||||||
bool called = false;
|
bool called = false;
|
||||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_AUTHENTICATION_FAILED, nullptr)).Times(1)
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_AUTHENTICATION_FAILED, nullptr)).Times(1)
|
||||||
.WillOnce(Invoke([&called] (wf_client *, int, void *) mutable {
|
.WillOnce(Invoke([&called] (wf_client *, int, void *) mutable {
|
||||||
@ -167,19 +174,11 @@ TEST(AdapterClient, AuthenticationFailed)
|
|||||||
AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), server.GetUrl());
|
AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), server.GetUrl());
|
||||||
|
|
||||||
client.Connect();
|
client.Connect();
|
||||||
while (!server.IsConnected())
|
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return connected; }));
|
||||||
{
|
|
||||||
watcher.check();
|
|
||||||
}
|
|
||||||
|
|
||||||
client.Authenticate();
|
client.Authenticate();
|
||||||
while (!called) {
|
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return called; }));
|
||||||
watcher.check();
|
|
||||||
}
|
|
||||||
|
|
||||||
client.Disconnect();
|
client.Disconnect();
|
||||||
while (server.IsConnected())
|
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return disconnected; }));
|
||||||
{
|
|
||||||
watcher.check();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "webfuse/utils/timeout_watcher.hpp"
|
#include "webfuse/utils/timeout_watcher.hpp"
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
using std::chrono::milliseconds;
|
using std::chrono::milliseconds;
|
||||||
using std::chrono::duration_cast;
|
using std::chrono::duration_cast;
|
||||||
@ -41,4 +42,17 @@ void TimeoutWatcher::check()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TimeoutWatcher::waitUntil(std::function<bool()> predicate)
|
||||||
|
{
|
||||||
|
bool result = predicate();
|
||||||
|
while ((!result) && (!isTimeout()))
|
||||||
|
{
|
||||||
|
std::this_thread::yield();
|
||||||
|
result = predicate();
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -2,6 +2,7 @@
|
|||||||
#define WF_TEST_TIMEOUT_WATCHER_HPP
|
#define WF_TEST_TIMEOUT_WATCHER_HPP
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
namespace webfuse_test
|
namespace webfuse_test
|
||||||
{
|
{
|
||||||
@ -15,6 +16,7 @@ public:
|
|||||||
~TimeoutWatcher();
|
~TimeoutWatcher();
|
||||||
bool isTimeout();
|
bool isTimeout();
|
||||||
void check();
|
void check();
|
||||||
|
bool waitUntil(std::function<bool()> predicate);
|
||||||
private:
|
private:
|
||||||
std::chrono::milliseconds startedAt;
|
std::chrono::milliseconds startedAt;
|
||||||
std::chrono::milliseconds timeout_;
|
std::chrono::milliseconds timeout_;
|
||||||
|
Loading…
Reference in New Issue
Block a user