Skip to content

Commit

Permalink
add ut
Browse files Browse the repository at this point in the history
  • Loading branch information
sharpeye committed Mar 28, 2024
1 parent cd1a74f commit e4ce280
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4842,28 +4842,26 @@ NProto::TError TDiskRegistryState::UpdateCmsHostState(
}

NProto::TError result;
if (timeout == TDuration::Zero()) {
result = MakeError(S_OK);
cmsTs = TInstant::Zero();
} else {
result = MakeError(
E_TRY_AGAIN,
TStringBuilder() << "time remaining: " << timeout);
}

// Agent can return from 'unavailable' state only when it is reconnected to
// the cluster.
if (agent->GetState() == NProto::AGENT_STATE_UNAVAILABLE &&
newState == NProto::AGENT_STATE_ONLINE)
{
result = MakeError(E_TRY_AGAIN, "agent currently unavailable");
timeout = cmsTs + CMS_UPDATE_STATE_TO_ONLINE_TIMEOUT - now;

if (!timeout) {
result.SetCode(E_INVALID_STATE);
}
}

if (timeout) {
result = MakeError(
E_TRY_AGAIN,
TStringBuilder() << "time remaining: " << timeout);
} else {
cmsTs = TInstant::Zero();
}

if (dryRun) {
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
#include <util/datetime/base.h>
#include <util/generic/size_literals.h>

#include <chrono>

namespace NCloud::NBlockStore::NStorage {

using namespace NActors;
using namespace NKikimr;
using namespace NDiskRegistryTest;
using namespace std::chrono_literals;

namespace {

Expand Down Expand Up @@ -1112,6 +1115,94 @@ Y_UNIT_TEST_SUITE(TDiskRegistryTest)
UNIT_ASSERT_VALUES_EQUAL(0, timeout);
}
}

Y_UNIT_TEST(ShouldRejectAddHostForUnavailableAgent)
{
const TVector agents{CreateAgentConfig(
"agent-1",
{Device("dev-1", "uuid-1", "rack-1", 10_GB),
Device("dev-2", "uuid-2", "rack-1", 10_GB)})};

auto runtime = TTestRuntimeBuilder().WithAgents(agents).Build();

TDiskRegistryClient diskRegistry(*runtime);
diskRegistry.SetWritableState(true);
diskRegistry.WaitReady();
diskRegistry.UpdateConfig(CreateRegistryConfig(0, agents));

RegisterAgents(*runtime, 1);
WaitForAgents(*runtime, 1);
WaitForSecureErase(*runtime, agents);

{
auto [error, timeout] = RemoveHost(diskRegistry, "agent-1");

UNIT_ASSERT_VALUES_EQUAL(S_OK, error.GetCode());
UNIT_ASSERT_VALUES_EQUAL(0, timeout);
}

runtime->AdvanceCurrentTime(15min);

diskRegistry.ChangeAgentState(
"agent-1",
NProto::EAgentState::AGENT_STATE_UNAVAILABLE);

runtime->AdvanceCurrentTime(15min);

{
auto [error, timeout] = AddHost(diskRegistry, "agent-1");

UNIT_ASSERT_VALUES_EQUAL(E_TRY_AGAIN, error.GetCode());
UNIT_ASSERT_VALUES_EQUAL(
TDuration{5min},
TDuration::Seconds(timeout));
}

runtime->AdvanceCurrentTime(2min);

{
auto [error, timeout] = AddHost(diskRegistry, "agent-1");

UNIT_ASSERT_VALUES_EQUAL(E_TRY_AGAIN, error.GetCode());
UNIT_ASSERT_LE(TDuration::Seconds(timeout), TDuration{3min});
UNIT_ASSERT_GT(TDuration::Seconds(timeout), TDuration{2min});
}

runtime->AdvanceCurrentTime(10min);

{
auto [error, timeout] = AddHost(diskRegistry, "agent-1");

UNIT_ASSERT_VALUES_EQUAL(E_INVALID_STATE, error.GetCode());
UNIT_ASSERT_VALUES_EQUAL(0, timeout);
}

runtime->AdvanceCurrentTime(10min);

{
auto [error, timeout] = AddHost(diskRegistry, "agent-1");

UNIT_ASSERT_VALUES_EQUAL(E_TRY_AGAIN, error.GetCode());
UNIT_ASSERT_VALUES_EQUAL(
TDuration{5min},
TDuration::Seconds(timeout));
}

runtime->AdvanceCurrentTime(1min);

diskRegistry.ChangeAgentState(
"agent-1",
NProto::EAgentState::AGENT_STATE_WARNING);

runtime->AdvanceCurrentTime(1min);

{
auto [error, timeout] = AddHost(diskRegistry, "agent-1");

UNIT_ASSERT_VALUES_EQUAL(S_OK, error.GetCode());
UNIT_ASSERT_VALUES_EQUAL(0, timeout);
}
}
}

} // namespace NCloud::NBlockStore::NStorage

0 comments on commit e4ce280

Please sign in to comment.