Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions ydb/core/mind/hive/hive_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8229,6 +8229,69 @@ Y_UNIT_TEST_SUITE(THiveTest) {
}
}

Y_UNIT_TEST(TestReassignNonexistentTablet) {
TTestBasicRuntime runtime(1, false);
Setup(runtime, true);

const ui64 hiveTablet = MakeDefaultHiveID();
const ui64 testerTablet = MakeTabletID(false, 1);
const TActorId hiveActor = CreateTestBootstrapper(runtime, CreateTestTabletInfo(hiveTablet, TTabletTypes::Hive), &CreateDefaultHive);
runtime.EnableScheduleForActor(hiveActor);
MakeSureTabletIsUp(runtime, hiveTablet, 0);
TActorId sender = runtime.AllocateEdgeActor(0);

{
TDispatchOptions options;
options.FinalEvents.emplace_back(TEvLocal::EvSyncTablets);
runtime.DispatchEvents(options);
}

THolder<TEvHive::TEvCreateTablet> createTablet = MakeHolder<TEvHive::TEvCreateTablet>(testerTablet, 1, TTabletTypes::Dummy, BINDED_CHANNELS);
ui64 tablet = SendCreateTestTablet(runtime, hiveTablet, testerTablet, std::move(createTablet), 0, true);

MakeSureTabletIsUp(runtime, tablet, 0);

{
NActorsProto::TRemoteHttpInfo pb;
pb.SetMethod(HTTP_METHOD_POST);
pb.SetPath("/app");
auto* p1 = pb.AddQueryParams();
p1->SetKey("TabletID");
p1->SetValue(TStringBuilder() << hiveTablet);
auto* p2 = pb.AddQueryParams();
p2->SetKey("page");
p2->SetValue("ReassignTablet");
auto* p3 = pb.AddQueryParams();
p3->SetKey("tablet");
p3->SetValue("52");
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hardcoded tablet ID "52" could potentially collide with an existing tablet. Consider using a clearly non-existent ID similar to line 8214 (e.g., TStringBuilder() << 0xfa5e7ab1e7) or adding a comment explaining why this specific value is guaranteed to be non-existent.

Suggested change
p3->SetValue("52");
p3->SetValue(TStringBuilder() << 0xfa5e7ab1e7);

Copilot uses AI. Check for mistakes.
runtime.SendToPipe(hiveTablet, sender, new NMon::TEvRemoteHttpInfo(std::move(pb)), 0, GetPipeConfigWithRetries());

TAutoPtr<IEventHandle> handle;
auto resp = runtime.GrabEdgeEventRethrow<NMon::TEvRemoteJsonInfoRes>(handle);
Ctest << "Hive response: " << resp->Json << Endl;
NJson::TJsonValue value;
ReadJsonTree(resp->Json, &value, false);
UNIT_ASSERT_VALUES_EQUAL(value["total"].GetIntegerSafe(), 0);
}

// this must not block balancer

{
THolder<TEvHive::TEvTabletMetrics> metrics = MakeHolder<TEvHive::TEvTabletMetrics>();
NKikimrHive::TTabletMetrics* metric = metrics->Record.AddTabletMetrics();
metric->SetTabletID(tablet);
metric->MutableResourceUsage()->SetNetwork(9000);

runtime.SendToPipe(hiveTablet, sender, metrics.Release());
}
Comment on lines +8279 to +8286
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation: this opening brace uses 7 spaces instead of 8 spaces like the rest of the function. Should align with the opening brace on line 8254.

Suggested change
{
THolder<TEvHive::TEvTabletMetrics> metrics = MakeHolder<TEvHive::TEvTabletMetrics>();
NKikimrHive::TTabletMetrics* metric = metrics->Record.AddTabletMetrics();
metric->SetTabletID(tablet);
metric->MutableResourceUsage()->SetNetwork(9000);
runtime.SendToPipe(hiveTablet, sender, metrics.Release());
}
{
THolder<TEvHive::TEvTabletMetrics> metrics = MakeHolder<TEvHive::TEvTabletMetrics>();
NKikimrHive::TTabletMetrics* metric = metrics->Record.AddTabletMetrics();
metric->SetTabletID(tablet);
metric->MutableResourceUsage()->SetNetwork(9000);
runtime.SendToPipe(hiveTablet, sender, metrics.Release());
}

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation: this closing brace uses 7 spaces instead of 8 spaces like the rest of the function. Should align with the corresponding opening brace.

Suggested change
}
}

Copilot uses AI. Check for mistakes.

{
TDispatchOptions options;
options.FinalEvents.push_back(NHive::TEvPrivate::EvBalancerOut);
runtime.DispatchEvents(options);
}
Comment on lines +8279 to +8292
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation: this block uses 7 spaces instead of 8 spaces like the rest of the function. All lines in this block should be indented with 8 spaces to match the rest of the test function.

Suggested change
{
THolder<TEvHive::TEvTabletMetrics> metrics = MakeHolder<TEvHive::TEvTabletMetrics>();
NKikimrHive::TTabletMetrics* metric = metrics->Record.AddTabletMetrics();
metric->SetTabletID(tablet);
metric->MutableResourceUsage()->SetNetwork(9000);
runtime.SendToPipe(hiveTablet, sender, metrics.Release());
}
{
TDispatchOptions options;
options.FinalEvents.push_back(NHive::TEvPrivate::EvBalancerOut);
runtime.DispatchEvents(options);
}
{
THolder<TEvHive::TEvTabletMetrics> metrics = MakeHolder<TEvHive::TEvTabletMetrics>();
NKikimrHive::TTabletMetrics* metric = metrics->Record.AddTabletMetrics();
metric->SetTabletID(tablet);
metric->MutableResourceUsage()->SetNetwork(9000);
runtime.SendToPipe(hiveTablet, sender, metrics.Release());
}
{
TDispatchOptions options;
options.FinalEvents.push_back(NHive::TEvPrivate::EvBalancerOut);
runtime.DispatchEvents(options);
}

Copilot uses AI. Check for mistakes.
}

Y_UNIT_TEST(TestTabletsStartingCounter) {
TTestBasicRuntime runtime(1, false);
Setup(runtime, true);
Expand Down
Loading