Skip to content

Commit 929e8f5

Browse files
authored
Use new test helper TBlockEvents (#7783)
1 parent 1253e8c commit 929e8f5

File tree

3 files changed

+13
-24
lines changed

3 files changed

+13
-24
lines changed

ydb/core/testlib/actors/block_events.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace NActors {
2727
* Unblocks up to count events at the front of the deque, allowing them
2828
* to be handled by the destination actor.
2929
*/
30-
TBlockEvents& Unblock(size_t count = -1) {
30+
TBlockEvents& Unblock(size_t count = Max<size_t>()) {
3131
while (!this->empty() && count > 0) {
3232
auto& ev = this->front();
3333
if (!Stopped) {
@@ -36,6 +36,7 @@ namespace NActors {
3636
}
3737
ui32 nodeId = ev->GetRecipientRewrite().NodeId();
3838
ui32 nodeIdx = nodeId - Runtime.GetFirstNodeId();
39+
Cerr << "TBlockEvents::Unblock " << typeid(TEvType).name() << " from " << Runtime.FindActorName(ev->Sender) << " to " << Runtime.FindActorName(ev->GetRecipientRewrite()) << Endl;
3940
Runtime.Send(ev.Release(), nodeIdx, /* viaActorSystem */ true);
4041
this->pop_front();
4142
--count;
@@ -67,6 +68,7 @@ namespace NActors {
6768
return;
6869
}
6970

71+
Cerr << "TBlockEvents::Block " << typeid(TEvType).name() << " from " << Runtime.FindActorName(ev->Sender) << " to " << Runtime.FindActorName(ev->GetRecipientRewrite()) << Endl;
7072
this->emplace_back(std::move(ev));
7173
}
7274

ydb/core/tx/datashard/datashard_ut_build_index.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <ydb/core/tx/schemeshard/schemeshard.h>
77
#include <ydb/core/tx/tx_proxy/proxy.h>
88
#include <ydb/core/tx/tx_proxy/upload_rows.h>
9+
#include <ydb/core/testlib/actors/block_events.h>
910

1011
#include <ydb/library/yql/public/issue/yql_issue_message.h>
1112

@@ -167,11 +168,8 @@ Y_UNIT_TEST_SUITE(TTxDataShardBuildIndexScan) {
167168

168169
CreateShardedTableForIndex(server, sender, "/Root", "table-2", 1, false);
169170

170-
auto observer = runtime.AddObserver<TEvDataShard::TEvCompactBorrowed>([&](TEvDataShard::TEvCompactBorrowed::TPtr& event) {
171-
Cerr << "Captured TEvDataShard::TEvCompactBorrowed from " << runtime.FindActorName(event->Sender) << " to " << runtime.FindActorName(event->GetRecipientRewrite()) << Endl;
172-
if (runtime.FindActorName(event->Sender) == "FLAT_SCHEMESHARD_ACTOR") {
173-
event.Reset();
174-
}
171+
TBlockEvents<TEvDataShard::TEvCompactBorrowed> block(runtime, [&](TEvDataShard::TEvCompactBorrowed::TPtr& event) {
172+
return runtime.FindActorName(event->Sender) == "FLAT_SCHEMESHARD_ACTOR";
175173
});
176174

177175
auto snapshot = CreateVolatileSnapshot(server, { "/Root/table-1" });

ydb/core/tx/datashard/datashard_ut_stats.cpp

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <ydb/core/tx/datashard/ut_common/datashard_ut_common.h>
22
#include <ydb/core/tablet_flat/shared_sausagecache.h>
33
#include <ydb/core/tablet_flat/test/libs/table/test_make.h>
4+
#include <ydb/core/testlib/actors/block_events.h>
45

56
namespace NKikimr {
67

@@ -441,28 +442,16 @@ Y_UNIT_TEST_SUITE(DataShardStats) {
441442
const auto shard1 = GetTableShards(server, sender, "/Root/table-1").at(0);
442443

443444
UpsertRows(server, sender);
444-
445-
bool captured = false;
446-
auto observer = runtime.AddObserver<NSharedCache::TEvResult>([&](NSharedCache::TEvResult::TPtr& event) {
447-
Cerr << "Captured NSharedCache::TEvResult from " << runtime.FindActorName(event->Sender) << " to " << runtime.FindActorName(event->GetRecipientRewrite()) << Endl;
448-
if (runtime.FindActorName(event->GetRecipientRewrite()) == "DATASHARD_STATS_BUILDER") {
449-
auto& message = *event->Get();
450-
event.Reset(static_cast<TEventHandle<NSharedCache::TEvResult> *>(
451-
new IEventHandle(event->Recipient, event->Sender,
452-
new NSharedCache::TEvResult(message.Origin, message.Cookie, NKikimrProto::NODATA))));
453-
captured = true;
454-
}
445+
446+
TBlockEvents<NSharedCache::TEvResult> block(runtime, [&](NSharedCache::TEvResult::TPtr& event) {
447+
return runtime.FindActorName(event->GetRecipientRewrite()) == "DATASHARD_STATS_BUILDER";
455448
});
456449

457450
CompactTable(runtime, shard1, tableId1, false);
458451

459-
for (int i = 0; i < 5 && !captured; ++i) {
460-
TDispatchOptions options;
461-
options.CustomFinalCondition = [&]() { return captured; };
462-
runtime.DispatchEvents(options, TDuration::Seconds(5));
463-
}
464-
UNIT_ASSERT(captured);
465-
observer.Remove();
452+
runtime.WaitFor("blocked read", [&]{ return block.size(); });
453+
454+
block.Stop().Unblock();
466455

467456
{
468457
Cerr << "Waiting stats.." << Endl;

0 commit comments

Comments
 (0)