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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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_;
|
||||
|
||||
Reference in New Issue
Block a user