diff --git a/test/async_progress_worker.cc b/test/async_progress_worker.cc index 3975bfbf4..7b14f6ca5 100644 --- a/test/async_progress_worker.cc +++ b/test/async_progress_worker.cc @@ -34,11 +34,16 @@ class TestWorker : public AsyncProgressWorker { SetError("test error"); } ProgressData data{0}; - std::unique_lock lock(_cvm); + for (int32_t idx = 0; idx < _times; idx++) { data.progress = idx; progress.Send(&data, 1); - _cv.wait(lock); + + { + std::unique_lock lk(_cvm); + _cv.wait(lk, [this] { return dataSent; }); + dataSent = false; + } } } @@ -48,7 +53,12 @@ class TestWorker : public AsyncProgressWorker { Number progress = Number::New(env, data->progress); _progress.MakeCallback(Receiver().Value(), {progress}); } - _cv.notify_one(); + + { + std::lock_guard lk(_cvm); + dataSent = true; + _cv.notify_one(); + } } private: @@ -59,6 +69,8 @@ class TestWorker : public AsyncProgressWorker { : AsyncProgressWorker(cb, resource_name, resource) { _progress.Reset(progress, 1); } + + bool dataSent = false; std::condition_variable _cv; std::mutex _cvm; int32_t _times;