Skip to content

Commit 4372675

Browse files
authored
Stop test runtime as soon as stop condition is satisfied (#7887)
1 parent 5e698ae commit 4372675

File tree

4 files changed

+47
-9
lines changed

4 files changed

+47
-9
lines changed

ydb/core/quoter/kesus_quoter_ut.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ Y_UNIT_TEST_SUITE(KesusProxyTest) {
237237
return setup.GetPipeFactory().GetPipesCreatedCount() >= 2;
238238
};
239239
setup.GetRuntime().DispatchEvents(reconnected);
240+
241+
// Dispatch some events to let poison pill reach the mock
242+
setup.GetRuntime().SimulateSleep(TDuration::Zero());
240243
}
241244

242245
Y_UNIT_TEST(ReconnectsWithKesusWhenPipeDestroyed) {
@@ -249,6 +252,9 @@ Y_UNIT_TEST_SUITE(KesusProxyTest) {
249252
setup.SendDestroyed(pipeMock);
250253

251254
setup.WaitPipesCreated(2);
255+
256+
// Dispatch some events to let poison pill reach the mock
257+
setup.GetRuntime().SimulateSleep(TDuration::Zero());
252258
}
253259

254260
Y_UNIT_TEST(RejectsNotCanonizedResourceName) {
@@ -391,6 +397,9 @@ Y_UNIT_TEST_SUITE(KesusProxyTest) {
391397
setup.WaitEvent<NKesus::TEvKesus::TEvUpdateConsumptionState>();
392398
setup.SendCloseSession("res", 42);
393399
setup.WaitEvent<TEvQuota::TEvProxyCloseSession>();
400+
401+
// Dispatch some events to let pending events reach their destinations
402+
setup.GetRuntime().SimulateSleep(TDuration::Zero());
394403
}
395404

396405
void SendsProxySessionOnce(bool onSuccess) {

ydb/core/tx/datashard/datashard_ut_volatile.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,8 +1224,12 @@ Y_UNIT_TEST_SUITE(DataShardVolatile) {
12241224
"value: [\n"
12251225
" 2\n"
12261226
" ]\n");
1227+
}
1228+
1229+
SimulateSleep(runtime, TDuration::MilliSeconds(0));
12271230

1228-
msg = readResults.back()->Get<TEvDataShard::TEvReadResult>();
1231+
{
1232+
auto* msg = readResults.back()->Get<TEvDataShard::TEvReadResult>();
12291233
UNIT_ASSERT_VALUES_EQUAL(msg->Record.GetStatus().GetCode(), Ydb::StatusIds::SUCCESS);
12301234
UNIT_ASSERT_VALUES_EQUAL(msg->Record.GetFinished(), true);
12311235
}

ydb/library/actors/testlib/test_runtime.cpp

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,26 @@ namespace NActors {
11661166
tempEdgeEventsCaptor.Reset(new TTempEdgeEventsCaptor(*this));
11671167
}
11681168

1169+
auto checkStopConditions = [&](bool perMessage = false) -> bool {
1170+
// Note: too many tests expect unrelated messages to be
1171+
// processed before simulation is stopped.
1172+
if (!perMessage) {
1173+
if (localContext.FinalEventFound) {
1174+
return true;
1175+
}
1176+
1177+
if (!localContext.FoundNonEmptyMailboxes.empty()) {
1178+
return true;
1179+
}
1180+
}
1181+
1182+
if (options.CustomFinalCondition && options.CustomFinalCondition()) {
1183+
return true;
1184+
}
1185+
1186+
return false;
1187+
};
1188+
11691189
TEventMailBoxList& currentMailboxes = useRestrictedMailboxes ? restrictedMailboxes : Mailboxes;
11701190
while (!currentMailboxes.empty()) {
11711191
bool hasProgress = true;
@@ -1195,7 +1215,8 @@ namespace NActors {
11951215
isEmpty = true;
11961216
auto mboxIt = startWithMboxIt;
11971217
TDeque<TEventMailboxId> suspectedBoxes;
1198-
while (true) {
1218+
bool stopCondition = false;
1219+
while (!stopCondition) {
11991220
auto& mbox = *mboxIt;
12001221
bool isIgnored = true;
12011222
if (!mbox.second->IsEmpty()) {
@@ -1264,6 +1285,9 @@ namespace NActors {
12641285
case EEventAction::PROCESS:
12651286
UpdateFinalEventsStatsForEachContext(*ev);
12661287
SendInternal(ev.Release(), mbox.first.NodeId - FirstNodeId, false);
1288+
if (checkStopConditions(/* perMessage */ true)) {
1289+
stopCondition = true;
1290+
}
12671291
break;
12681292
case EEventAction::DROP:
12691293
// do nothing
@@ -1305,19 +1329,17 @@ namespace NActors {
13051329
currentMailboxes.erase(it);
13061330
}
13071331
}
1332+
1333+
if (stopCondition) {
1334+
return true;
1335+
}
13081336
}
13091337
}
13101338

1311-
if (localContext.FinalEventFound) {
1339+
if (checkStopConditions()) {
13121340
return true;
13131341
}
13141342

1315-
if (!localContext.FoundNonEmptyMailboxes.empty())
1316-
return true;
1317-
1318-
if (options.CustomFinalCondition && options.CustomFinalCondition())
1319-
return true;
1320-
13211343
if (options.FinalEvents.empty()) {
13221344
for (auto& mbox : currentMailboxes) {
13231345
if (!mbox.second->IsActive(TInstant::MicroSeconds(CurrentTimestamp)))

ydb/services/persqueue_v1/ut/partition_writer_cache_actor_fixture.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ void TPartitionWriterCacheActorFixture::WaitForPartitionWriterOps(const TWaitFor
188188
};
189189

190190
Ctx->Runtime->DispatchEvents(options);
191+
192+
// Tests rely on unrelated events processed after the condition is satisfied
193+
Ctx->Runtime->DispatchEvents({}, TInstant::Zero());
191194
}
192195

193196
void TPartitionWriterCacheActorFixture::AdvanceCurrentTime(TDuration d)

0 commit comments

Comments
 (0)