1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2026-03-02 04:09:18 +00:00

fix: fixed deadlock in tests (wait for client to connect, instead on relying on the server)

This commit is contained in:
Falk Werner
2020-06-13 23:47:52 +02:00
parent ed39db2d8d
commit edcad5dc4c
3 changed files with 54 additions and 39 deletions

View File

@@ -1,5 +1,6 @@
#include "webfuse/utils/timeout_watcher.hpp"
#include <stdexcept>
#include <thread>
using std::chrono::milliseconds;
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;
}
}

View File

@@ -2,6 +2,7 @@
#define WF_TEST_TIMEOUT_WATCHER_HPP
#include <chrono>
#include <functional>
namespace webfuse_test
{
@@ -15,6 +16,7 @@ public:
~TimeoutWatcher();
bool isTimeout();
void check();
bool waitUntil(std::function<bool()> predicate);
private:
std::chrono::milliseconds startedAt;
std::chrono::milliseconds timeout_;