Skip to content

Commit 0046f6c

Browse files
authored
Made SchemeShard tests robust to changing of PathIds (#19992)
1 parent 7e24464 commit 0046f6c

File tree

11 files changed

+198
-73
lines changed

11 files changed

+198
-73
lines changed

ydb/core/tx/schemeshard/ut_cdc_stream/ut_cdc_stream.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,9 @@ Y_UNIT_TEST_SUITE(TCdcStreamTests) {
10831083
)");
10841084
env.TestWaitNotification(runtime, txId);
10851085

1086+
const auto describeResult = DescribePath(runtime, "/MyRoot/Shared");
1087+
const auto subDomainPathId = describeResult.GetPathId();
1088+
10861089
TestAlterExtSubDomain(runtime, ++txId, "/MyRoot", R"(
10871090
Name: "Shared"
10881091
StoragePools {
@@ -1107,9 +1110,9 @@ Y_UNIT_TEST_SUITE(TCdcStreamTests) {
11071110
Name: "Serverless"
11081111
ResourcesDomainKey {
11091112
SchemeShard: %lu
1110-
PathId: 2
1113+
PathId: %lu
11111114
}
1112-
)", TTestTxConfig::SchemeShard));
1115+
)", TTestTxConfig::SchemeShard, subDomainPathId));
11131116
env.TestWaitNotification(runtime, txId);
11141117

11151118
TestAlterExtSubDomain(runtime, ++txId, "/MyRoot", R"(
@@ -1928,6 +1931,9 @@ Y_UNIT_TEST_SUITE(TCdcStreamWithInitialScanTests) {
19281931
)");
19291932
env.TestWaitNotification(runtime, txId);
19301933

1934+
const auto describeResult = DescribePath(runtime, "/MyRoot/Shared");
1935+
const auto subDomainPathId = describeResult.GetPathId();
1936+
19311937
TestAlterExtSubDomain(runtime, ++txId, "/MyRoot", R"(
19321938
Name: "Shared"
19331939
StoragePools {
@@ -1958,9 +1964,9 @@ Y_UNIT_TEST_SUITE(TCdcStreamWithInitialScanTests) {
19581964
Name: "Serverless"
19591965
ResourcesDomainKey {
19601966
SchemeShard: %lu
1961-
PathId: 2
1967+
PathId: %lu
19621968
}
1963-
)", TTestTxConfig::SchemeShard), attrs);
1969+
)", TTestTxConfig::SchemeShard, subDomainPathId), attrs);
19641970
env.TestWaitNotification(runtime, txId);
19651971

19661972
TestAlterExtSubDomain(runtime, ++txId, "/MyRoot", R"(
@@ -2042,14 +2048,14 @@ Y_UNIT_TEST_SUITE(TCdcStreamWithInitialScanTests) {
20422048
runtime.DispatchEvents(opts);
20432049
}
20442050

2045-
UNIT_ASSERT_STRINGS_EQUAL(meteringRecord, TBillRecord()
2051+
auto expectedBill = TBillRecord()
20462052
.Id("cdc_stream_scan-72075186233409549-3-72075186233409549-4")
20472053
.CloudId("CLOUD_ID_VAL")
20482054
.FolderId("FOLDER_ID_VAL")
20492055
.ResourceId("DATABASE_ID_VAL")
20502056
.SourceWt(TInstant::FromValue(0))
2051-
.Usage(TBillRecord::RequestUnits(1, TInstant::FromValue(0)))
2052-
.ToString());
2057+
.Usage(TBillRecord::RequestUnits(1, TInstant::FromValue(0)));
2058+
MeteringDataEqual(meteringRecord, expectedBill.ToString());
20532059
} else {
20542060
for (int i = 0; i < 10; ++i) {
20552061
env.SimulateSleep(runtime, TDuration::Seconds(1));

ydb/core/tx/schemeshard/ut_column_build/ut_column_build.cpp

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Y_UNIT_TEST_SUITE(ColumnBuildTest) {
1919
"Name: \"ResourceDB\"");
2020
env.TestWaitNotification(runtime, txId);
2121

22+
const auto describeResult = DescribePath(runtime, "/MyRoot/ResourceDB");
23+
const auto subDomainPathId = describeResult.GetPathId();
24+
2225
TestAlterExtSubDomain(runtime, ++txId, "/MyRoot",
2326
"StoragePools { "
2427
" Name: \"pool-1\" "
@@ -46,9 +49,9 @@ Y_UNIT_TEST_SUITE(ColumnBuildTest) {
4649
Name: "ServerLessDB"
4750
ResourcesDomainKey {
4851
SchemeShard: %lu
49-
PathId: 2
52+
PathId: %lu
5053
}
51-
)", TTestTxConfig::SchemeShard), attrs);
54+
)", TTestTxConfig::SchemeShard, subDomainPathId), attrs);
5255
env.TestWaitNotification(runtime, txId);
5356

5457
TString alterData = TStringBuilder()
@@ -125,6 +128,9 @@ Y_UNIT_TEST_SUITE(ColumnBuildTest) {
125128
"Name: \"ResourceDB\"");
126129
env.TestWaitNotification(runtime, txId);
127130

131+
const auto describeResult = DescribePath(runtime, "/MyRoot/ResourceDB");
132+
const auto subDomainPathId = describeResult.GetPathId();
133+
128134
TestAlterExtSubDomain(runtime, ++txId, "/MyRoot",
129135
"StoragePools { "
130136
" Name: \"pool-1\" "
@@ -152,9 +158,9 @@ Y_UNIT_TEST_SUITE(ColumnBuildTest) {
152158
Name: "ServerLessDB"
153159
ResourcesDomainKey {
154160
SchemeShard: %lu
155-
PathId: 2
161+
PathId: %lu
156162
}
157-
)", TTestTxConfig::SchemeShard), attrs);
163+
)", TTestTxConfig::SchemeShard, subDomainPathId), attrs);
158164
env.TestWaitNotification(runtime, txId);
159165

160166
TString alterData = TStringBuilder()
@@ -219,7 +225,7 @@ Y_UNIT_TEST_SUITE(ColumnBuildTest) {
219225
defaultValue.mutable_value()->set_uint64_value(1111); // TODO: check invalid value
220226

221227
TestBuildColumn(runtime, ++txId, tenantSchemeShard, "/MyRoot/ServerLessDB", "/MyRoot/ServerLessDB/Table", "ColumnValue", defaultValue, Ydb::StatusIds::SUCCESS);
222-
228+
223229
auto listing = TestListBuildIndex(runtime, tenantSchemeShard, "/MyRoot/ServerLessDB");
224230
Y_ASSERT(listing.EntriesSize() == 1);
225231

@@ -238,6 +244,9 @@ Y_UNIT_TEST_SUITE(ColumnBuildTest) {
238244
"Name: \"ResourceDB\"");
239245
env.TestWaitNotification(runtime, txId);
240246

247+
const auto describeResult = DescribePath(runtime, "/MyRoot/ResourceDB");
248+
const auto subDomainPathId = describeResult.GetPathId();
249+
241250
TestAlterExtSubDomain(runtime, ++txId, "/MyRoot",
242251
"StoragePools { "
243252
" Name: \"pool-1\" "
@@ -265,9 +274,9 @@ Y_UNIT_TEST_SUITE(ColumnBuildTest) {
265274
Name: "ServerLessDB"
266275
ResourcesDomainKey {
267276
SchemeShard: %lu
268-
PathId: 2
277+
PathId: %lu
269278
}
270-
)", TTestTxConfig::SchemeShard), attrs);
279+
)", TTestTxConfig::SchemeShard, subDomainPathId), attrs);
271280
env.TestWaitNotification(runtime, txId);
272281

273282
TString alterData = TStringBuilder()
@@ -379,7 +388,7 @@ Y_UNIT_TEST_SUITE(ColumnBuildTest) {
379388
for (const auto& ev: delayedUpsertRows) {
380389
runtime.Send(ev);
381390
}
382-
391+
383392
enabledCapture = false;
384393

385394
auto listing = TestListBuildIndex(runtime, tenantSchemeShard, "/MyRoot/ServerLessDB");
@@ -388,7 +397,7 @@ Y_UNIT_TEST_SUITE(ColumnBuildTest) {
388397
env.TestWaitNotification(runtime, txId, tenantSchemeShard);
389398

390399
auto descr = TestGetBuildIndex(runtime, tenantSchemeShard, "/MyRoot/ServerLessDB", txId);
391-
Y_ASSERT(descr.GetIndexBuild().GetState() == Ydb::Table::IndexBuildState::STATE_DONE);
400+
Y_ASSERT(descr.GetIndexBuild().GetState() == Ydb::Table::IndexBuildState::STATE_DONE);
392401

393402
for (ui32 delta = 50; delta < 101; ++delta) {
394403
UNIT_ASSERT(CheckLocalRowExists(runtime, TTestTxConfig::FakeHiveTablets + 6, "__user__Table", "key", 1 + delta));
@@ -408,6 +417,9 @@ Y_UNIT_TEST_SUITE(ColumnBuildTest) {
408417
"Name: \"ResourceDB\"");
409418
env.TestWaitNotification(runtime, txId);
410419

420+
const auto describeResult = DescribePath(runtime, "/MyRoot/ResourceDB");
421+
const auto subDomainPathId = describeResult.GetPathId();
422+
411423
TestAlterExtSubDomain(runtime, ++txId, "/MyRoot",
412424
"StoragePools { "
413425
" Name: \"pool-1\" "
@@ -435,9 +447,9 @@ Y_UNIT_TEST_SUITE(ColumnBuildTest) {
435447
Name: "ServerLessDB"
436448
ResourcesDomainKey {
437449
SchemeShard: %lu
438-
PathId: 2
450+
PathId: %lu
439451
}
440-
)", TTestTxConfig::SchemeShard), attrs);
452+
)", TTestTxConfig::SchemeShard, subDomainPathId), attrs);
441453
env.TestWaitNotification(runtime, txId);
442454

443455
TString alterData = TStringBuilder()

ydb/core/tx/schemeshard/ut_compaction/ut_compaction.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,9 @@ ui64 TestServerless(
454454
)");
455455
env.TestWaitNotification(runtime, txId);
456456

457+
const auto describeResult = DescribePath(runtime, "/MyRoot/Shared");
458+
const auto subDomainPathId = describeResult.GetPathId();
459+
457460
TestAlterExtSubDomain(runtime, ++txId, "/MyRoot", R"(
458461
PlanResolution: 50
459462
Coordinators: 1
@@ -482,9 +485,9 @@ ui64 TestServerless(
482485
Name: "User"
483486
ResourcesDomainKey {
484487
SchemeShard: %lu
485-
PathId: 2
488+
PathId: %lu
486489
}
487-
)", schemeshardId), attrs);
490+
)", schemeshardId, subDomainPathId), attrs);
488491
env.TestWaitNotification(runtime, txId);
489492

490493
TestAlterExtSubDomain(runtime, ++txId, "/MyRoot", R"(

ydb/core/tx/schemeshard/ut_helpers/helpers.cpp

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,13 @@ namespace NSchemeShardUT_Private {
14291429
};
14301430
}
14311431

1432+
TLocalPathId GetNextLocalPathId(TTestActorRuntime& runtime, ui64& txId) {
1433+
TestMkDir(runtime, ++txId, "/MyRoot", "test42");
1434+
TLocalPathId res = DescribePath(runtime, "/MyRoot/test42").GetPathId() + 1;
1435+
TestRmDir(runtime, ++txId, "/MyRoot", "test42");
1436+
return res;
1437+
}
1438+
14321439
TString SetAllowLogBatching(TTestActorRuntime& runtime, ui64 tabletId, bool v) {
14331440
NTabletFlatScheme::TSchemeChanges scheme;
14341441
TString errStr;
@@ -2738,6 +2745,9 @@ namespace NSchemeShardUT_Private {
27382745
TestCreateExtSubDomain(runtime, ++txId, "/MyRoot", "Name: \"ResourceDB\"");
27392746
env.TestWaitNotification(runtime, txId);
27402747

2748+
const auto describeResult = DescribePath(runtime, "/MyRoot/ResourceDB");
2749+
const auto subDomainPathId = describeResult.GetPathId();
2750+
27412751
TestAlterExtSubDomain(runtime, ++txId, "/MyRoot", R"(
27422752
StoragePools {
27432753
Name: "pool-1"
@@ -2765,9 +2775,9 @@ namespace NSchemeShardUT_Private {
27652775
Name: "ServerLessDB"
27662776
ResourcesDomainKey {
27672777
SchemeShard: %lu
2768-
PathId: 2
2778+
PathId: %lu
27692779
}
2770-
)", TTestTxConfig::SchemeShard), attrs);
2780+
)", TTestTxConfig::SchemeShard, subDomainPathId), attrs);
27712781
env.TestWaitNotification(runtime, txId);
27722782

27732783
TString alterData = R"(
@@ -2792,4 +2802,54 @@ namespace NSchemeShardUT_Private {
27922802
NLs::ExtractTenantSchemeshard(&tenantSchemeShard)});
27932803
}
27942804

2805+
void MeteringDataEqual(const TString& leftMsg, const TString& rightMsg) {
2806+
const auto leftMeteringData = NJson::ReadJsonFastTree(leftMsg);
2807+
const auto rightMeteringData = NJson::ReadJsonFastTree(rightMsg);
2808+
2809+
const auto leftIdParts = SplitString(leftMeteringData["id"].GetString(), "-");
2810+
const auto rightIdParts = SplitString(rightMeteringData["id"].GetString(), "-");
2811+
UNIT_ASSERT_VALUES_EQUAL(leftIdParts.size(), rightIdParts.size());
2812+
2813+
size_t localPathIdIndex = 2;
2814+
if (leftMeteringData["source_id"] == "sless-docapi-ydb-storage") {
2815+
localPathIdIndex = 1;
2816+
}
2817+
2818+
for (size_t i = 0; i < leftIdParts.size(); ++i) {
2819+
if (i != localPathIdIndex) { // no need to compare localPathIds
2820+
UNIT_ASSERT_VALUES_EQUAL(leftIdParts[i], rightIdParts[i]);
2821+
}
2822+
}
2823+
2824+
const auto& leftUsage = leftMeteringData["usage"];
2825+
const auto& rightUsage = rightMeteringData["usage"];
2826+
for (const auto& field : {"quantity", "unit", "type"}) {
2827+
Cerr << field << ": " << leftUsage[field] << ", " << rightUsage[field] << Endl;
2828+
UNIT_ASSERT_VALUES_EQUAL(leftUsage[field], rightUsage[field]);
2829+
}
2830+
2831+
for (const auto& field : {"version", "schema", "cloud_id", "folder_id", "resource_id", "source_id"}) {
2832+
UNIT_ASSERT_VALUES_EQUAL(leftMeteringData[field], rightMeteringData[field]);
2833+
}
2834+
2835+
const auto& leftTags = leftMeteringData["tags"].GetMap();
2836+
const auto& rightTags = rightMeteringData["tags"].GetMap();
2837+
UNIT_ASSERT_VALUES_EQUAL(leftTags.size(), rightTags.size());
2838+
2839+
for (const auto& [tag, value] : leftTags) {
2840+
auto it = rightTags.find(tag);
2841+
UNIT_ASSERT(it != rightTags.end());
2842+
UNIT_ASSERT_VALUES_EQUAL(value, it->second);
2843+
}
2844+
2845+
const auto& leftLabels = leftMeteringData["labels"].GetMap();
2846+
const auto& rightLabels = rightMeteringData["labels"].GetMap();
2847+
UNIT_ASSERT_VALUES_EQUAL(leftLabels.size(), rightLabels.size());
2848+
2849+
for (const auto& [label, value] : leftLabels) {
2850+
auto it = rightLabels.find(label);
2851+
UNIT_ASSERT(it != rightLabels.end());
2852+
UNIT_ASSERT_VALUES_EQUAL(value, it->second);
2853+
}
2854+
}
27952855
}

ydb/core/tx/schemeshard/ut_helpers/helpers.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,8 @@ namespace NSchemeShardUT_Private {
486486
TVector<ui64> GetTableShards(TTestActorRuntime& runtime, ui64 schemeShard, const TString& path);
487487
NLs::TCheckFunc ShardsIsReady(TTestActorRuntime& runtime);
488488

489+
TLocalPathId GetNextLocalPathId(TTestActorRuntime& runtime, ui64& txId);
490+
489491
template <typename TCreateFunc>
490492
void CreateWithIntermediateDirs(TCreateFunc func) {
491493
TTestWithReboots t;
@@ -508,8 +510,14 @@ namespace NSchemeShardUT_Private {
508510
void CreateWithIntermediateDirsForceDrop(TCreateFunc func) {
509511
TTestWithReboots t;
510512
t.Run([&](TTestActorRuntime& runtime, bool& activeZone) {
513+
TLocalPathId nextPathId;
514+
{
515+
TInactiveZone inactive(activeZone);
516+
nextPathId = GetNextLocalPathId(runtime, t.TxId);
517+
}
518+
511519
func(runtime, ++t.TxId, "/MyRoot");
512-
AsyncForceDropUnsafe(runtime, ++t.TxId, 3);
520+
AsyncForceDropUnsafe(runtime, ++t.TxId, nextPathId);
513521
t.TestEnv->TestWaitNotification(runtime, {t.TxId - 1, t.TxId});
514522

515523
{
@@ -667,4 +675,6 @@ namespace NSchemeShardUT_Private {
667675

668676
void TestCreateServerLessDb(TTestActorRuntime& runtime, TTestEnv& env, ui64& txId, ui64& tenantSchemeShard);
669677

678+
void MeteringDataEqual(const TString& leftMsg, const TString& rightMsg);
679+
670680
} //NSchemeShardUT_Private

ydb/core/tx/schemeshard/ut_index_build/ut_index_build.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ Y_UNIT_TEST_SUITE(IndexBuildTest) {
248248

249249
const TString meteringData = R"({"usage":{"start":0,"quantity":179,"finish":0,"unit":"request_unit","type":"delta"},"tags":{},"id":"106-72075186233409549-2-0-0-0-0-101-101-1818-1818","cloud_id":"CLOUD_ID_VAL","source_wt":0,"source_id":"sless-docapi-ydb-ss","resource_id":"DATABASE_ID_VAL","schema":"ydb.serverless.requests.v1","folder_id":"FOLDER_ID_VAL","version":"1.0.0"})";
250250

251-
UNIT_ASSERT_NO_DIFF(meteringMessages, meteringData + "\n");
251+
MeteringDataEqual(meteringMessages, meteringData);
252252

253253
TestDescribeResult(DescribePath(runtime, tenantSchemeShard, "/MyRoot/ServerLessDB/Table"),
254254
{NLs::PathExist,

ydb/core/tx/schemeshard/ut_index_build/ut_vector_index_build.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ Y_UNIT_TEST_SUITE (VectorIndexBuildTest) {
567567
.SourceWt(TInstant::Seconds(10))
568568
.Usage(TBillRecord::RequestUnits(130, TInstant::Seconds(0), TInstant::Seconds(10)));
569569
UNIT_ASSERT_VALUES_EQUAL(meteringBlocker.size(), 1);
570-
UNIT_ASSERT_VALUES_EQUAL(meteringBlocker[0]->Get()->MeteringJson, expectedBill.ToString());
570+
MeteringDataEqual(meteringBlocker[0]->Get()->MeteringJson, expectedBill.ToString());
571571
previousBillId = newBillId;
572572
meteringBlocker.Unblock();
573573
}
@@ -638,7 +638,7 @@ Y_UNIT_TEST_SUITE (VectorIndexBuildTest) {
638638
.SourceWt(TInstant::Seconds(10))
639639
.Usage(TBillRecord::RequestUnits(336, TInstant::Seconds(10), TInstant::Seconds(10)));
640640
UNIT_ASSERT_VALUES_EQUAL(meteringBlocker.size(), 1);
641-
UNIT_ASSERT_VALUES_EQUAL(meteringBlocker[0]->Get()->MeteringJson, expectedBill.ToString());
641+
MeteringDataEqual(meteringBlocker[0]->Get()->MeteringJson, expectedBill.ToString());
642642
previousBillId = newBillId;
643643
meteringBlocker.Stop().Unblock();
644644
}

0 commit comments

Comments
 (0)