Skip to content

Commit cfe18e9

Browse files
committed
Add common WaitFor helper to the test actor runtime
1 parent 86315c5 commit cfe18e9

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

ydb/core/testlib/actors/test_runtime.h

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,24 +69,40 @@ namespace NActors {
6969
void SimulateSleep(TDuration duration);
7070

7171
template<class TResult>
72-
inline TResult WaitFuture(NThreading::TFuture<TResult> f) {
72+
inline TResult WaitFuture(NThreading::TFuture<TResult> f, TDuration simTimeout = TDuration::Max()) {
7373
if (!f.HasValue() && !f.HasException()) {
7474
TDispatchOptions options;
7575
options.CustomFinalCondition = [&]() {
7676
return f.HasValue() || f.HasException();
7777
};
78-
options.FinalEvents.emplace_back([&](IEventHandle&) {
79-
return f.HasValue() || f.HasException();
80-
});
78+
// Quirk: non-empty FinalEvents enables full simulation
79+
options.FinalEvents.emplace_back([](IEventHandle&) { return false });
8180

82-
this->DispatchEvents(options);
81+
this->DispatchEvents(options, simTimeout);
8382

8483
Y_ABORT_UNLESS(f.HasValue() || f.HasException());
8584
}
8685

8786
return f.ExtractValue();
8887
}
8988

89+
template<class TCondition>
90+
inline void WaitFor(const TString& description, const TCondition& condition, TDuration simTimeout = TDuration::Max()) {
91+
if (!condition()) {
92+
TDispatchOptions options;
93+
options.CustomFinalCondition = [&]() {
94+
return condition();
95+
};
96+
// Quirk: non-empty FinalEvents enables full simulation
97+
options.FinalEvents.emplace_back([](IEventHandle&) { return false; });
98+
99+
Cerr << "... waiting for " << description << Endl;
100+
this->DispatchEvents(options, simTimeout);
101+
102+
Y_ABORT_UNLESS(condition(), "Timeout while waiting for %s", description.c_str());
103+
}
104+
}
105+
90106
void SendToPipe(ui64 tabletId, const TActorId& sender, IEventBase* payload, ui32 nodeIndex = 0,
91107
const NKikimr::NTabletPipe::TClientConfig& pipeConfig = NKikimr::NTabletPipe::TClientConfig(), TActorId clientId = TActorId(), ui64 cookie = 0, NWilson::TTraceId traceId = {});
92108
void SendToPipe(TActorId clientId, const TActorId& sender, IEventBase* payload,

0 commit comments

Comments
 (0)