Skip to content

Commit

Permalink
issue-1377: remove mutable endpoint storage & add unit tests (#1466)
Browse files Browse the repository at this point in the history
Issue: #1377

Refactoring: Remove TFileMutableEndpointStorage implementation, use production implementation of FileEndpointStorage in the tests and use TTempDir to create/cleanup endpoints directory.

New tests for fs endpoint storage:

remove existing/non-existing endpoints
adding endpoint twice
  • Loading branch information
antonmyagkov authored Jul 2, 2024
1 parent 44a623c commit dc18d70
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 338 deletions.
18 changes: 6 additions & 12 deletions cloud/blockstore/libs/endpoints/endpoint_manager_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include <cloud/storage/core/libs/diagnostics/logging.h>
#include <cloud/storage/core/libs/diagnostics/monitoring.h>
#include <cloud/storage/core/libs/endpoints/fs/fs_endpoints.h>
#include <cloud/storage/core/libs/endpoints/fs/fs_endpoints_test.h>

#include <library/cpp/testing/unittest/registar.h>

Expand Down Expand Up @@ -270,23 +269,18 @@ struct TBootstrap
IServerStatsPtr ServerStats = CreateServerStatsStub();
ISessionManagerPtr SessionManager;
IEndpointStoragePtr EndpointStorage = CreateFileEndpointStorage(DirPath);
IMutableEndpointStoragePtr MutableStorage = CreateFileMutableEndpointStorage(DirPath);
TTempDir EndpointsDir = TTempDir(DirPath);
THashMap<NProto::EClientIpcType, IEndpointListenerPtr> EndpointListeners;
NBD::IDeviceFactoryPtr NbdDeviceFactory;
IEndpointEventProxyPtr EndpointEventHandler = CreateEndpointEventProxy();
TEndpointManagerOptions Options;
IEndpointManagerPtr EndpointManager;

TBootstrap()
{
MutableStorage->Init();
}
TBootstrap() = default;

~TBootstrap()
{
Stop();

MutableStorage->Remove();
}

void Start()
Expand Down Expand Up @@ -1675,10 +1669,10 @@ Y_UNIT_TEST_SUITE(TEndpointManagerTest)
auto [str, error] = SerializeEndpoint(request);
UNIT_ASSERT_C(!HasError(error), error);

auto keyOrError = bootstrap.MutableStorage->AddEndpoint(
auto ret = bootstrap.EndpointStorage->AddEndpoint(
request.GetUnixSocketPath(),
str);
UNIT_ASSERT_C(!HasError(keyOrError), keyOrError.GetError());
UNIT_ASSERT_EQUAL_C(S_OK, ret.GetCode(), ret.GetMessage());
}

NMonitoring::TDynamicCountersPtr counters = new NMonitoring::TDynamicCounters();
Expand Down Expand Up @@ -1754,10 +1748,10 @@ Y_UNIT_TEST_SUITE(TEndpointManagerTest)
auto [str, error] = SerializeEndpoint(request);
UNIT_ASSERT_C(!HasError(error), error);

auto keyOrError = bootstrap.MutableStorage->AddEndpoint(
auto ret = bootstrap.EndpointStorage->AddEndpoint(
request.GetUnixSocketPath(),
str);
UNIT_ASSERT_C(!HasError(keyOrError), keyOrError.GetError());
UNIT_ASSERT_EQUAL_C(S_OK, ret.GetCode(), ret.GetMessage());
}

NMonitoring::TDynamicCountersPtr counters = new NMonitoring::TDynamicCounters();
Expand Down
62 changes: 6 additions & 56 deletions cloud/blockstore/libs/endpoints/service_endpoint_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <cloud/storage/core/libs/diagnostics/logging.h>
#include <cloud/storage/core/libs/endpoints/keyring/keyring_endpoints.h>
#include <cloud/storage/core/libs/endpoints/fs/fs_endpoints.h>
#include <cloud/storage/core/libs/endpoints/fs/fs_endpoints_test.h>

#include <library/cpp/monlib/dynamic_counters/counters.h>
#include <library/cpp/testing/unittest/registar.h>
Expand Down Expand Up @@ -234,16 +233,8 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest)
auto keyringId = 13;
const TString dirPath = "./" + CreateGuidAsString();
auto endpointStorage = CreateFileEndpointStorage(dirPath);
auto mutableStorage = CreateFileMutableEndpointStorage(dirPath);

auto initError = mutableStorage->Init();
UNIT_ASSERT_C(!HasError(initError), initError);

Y_DEFER {
auto error = mutableStorage->Remove();
UNIT_ASSERT_C(!HasError(error), error);
};

TTempDir endpointsDir(dirPath);
TTempDir dir;
TString unixSocket = (dir.Path() / "testSocket").GetPath();
TString diskId = "testDiskId";
Expand Down Expand Up @@ -322,16 +313,7 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest)
{
const TString dirPath = "./" + CreateGuidAsString();
auto endpointStorage = CreateFileEndpointStorage(dirPath);
auto mutableStorage = CreateFileMutableEndpointStorage(dirPath);

auto initError = mutableStorage->Init();
UNIT_ASSERT_C(!HasError(initError), initError);

Y_DEFER {
auto error = mutableStorage->Remove();
UNIT_ASSERT_C(!HasError(error), error);
};

TTempDir endpointsDir(dirPath);
auto logging = CreateLoggingService("console");

auto scheduler = CreateScheduler();
Expand Down Expand Up @@ -510,15 +492,7 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest)

const TString dirPath = "./" + CreateGuidAsString();
auto endpointStorage = CreateFileEndpointStorage(dirPath);
auto mutableStorage = CreateFileMutableEndpointStorage(dirPath);

auto initError = mutableStorage->Init();
UNIT_ASSERT_C(!HasError(initError), initError);

Y_DEFER {
auto error = mutableStorage->Remove();
UNIT_ASSERT_C(!HasError(error), error);
};
TTempDir endpointsDir(dirPath);

size_t counter = 0;
size_t wrongDataCount = 3;
Expand Down Expand Up @@ -679,15 +653,7 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest)

const TString dirPath = "./" + CreateGuidAsString();
auto endpointStorage = CreateFileEndpointStorage(dirPath);
auto mutableStorage = CreateFileMutableEndpointStorage(dirPath);

auto initError = mutableStorage->Init();
UNIT_ASSERT_C(!HasError(initError), initError);

Y_DEFER {
auto error = mutableStorage->Remove();
UNIT_ASSERT_C(!HasError(error), error);
};
TTempDir endpointsDir(dirPath);

TTempDir dir;
size_t endpointCount = 5;
Expand Down Expand Up @@ -754,15 +720,7 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest)
{
const TString dirPath = "./" + CreateGuidAsString();
auto endpointStorage = CreateFileEndpointStorage(dirPath);
auto mutableStorage = CreateFileMutableEndpointStorage(dirPath);

auto initError = mutableStorage->Init();
UNIT_ASSERT_C(!HasError(initError), initError);

Y_DEFER {
auto error = mutableStorage->Remove();
UNIT_ASSERT_C(!HasError(error), error);
};
TTempDir endpointsDir(dirPath);

TTempDir dir;
ui32 endpointCount = 42;
Expand Down Expand Up @@ -1030,15 +988,7 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest)
auto keyringId = 13;
const TString dirPath = "./" + CreateGuidAsString();
auto endpointStorage = CreateFileEndpointStorage(dirPath);
auto mutableStorage = CreateFileMutableEndpointStorage(dirPath);

auto initError = mutableStorage->Init();
UNIT_ASSERT_C(!HasError(initError), initError);

Y_DEFER {
auto error = mutableStorage->Remove();
UNIT_ASSERT_C(!HasError(error), error);
};
TTempDir endpointsDir(dirPath);

TAtomic trigger = 0;
TManualEvent event;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <cloud/storage/core/libs/diagnostics/histogram.h>
#include <cloud/storage/core/libs/diagnostics/logging.h>
#include <cloud/storage/core/libs/endpoints/iface/endpoints.h>
#include <cloud/storage/core/libs/endpoints/fs/fs_endpoints_test.h>
#include <cloud/storage/core/libs/endpoints/fs/fs_endpoints.h>

#include <library/cpp/json/json_writer.h>
#include <library/cpp/protobuf/json/proto2json.h>
Expand Down Expand Up @@ -103,7 +103,7 @@ TLoadTestRunner::TLoadTestRunner(
{
const auto& endpointStorageDir = ClientFactory.GetEndpointStorageDir();
if (endpointStorageDir) {
EndpointStorage = CreateFileMutableEndpointStorage(endpointStorageDir);
EndpointStorage = CreateFileEndpointStorage(endpointStorageDir);
}
}

Expand Down Expand Up @@ -258,8 +258,8 @@ void TLoadTestRunner::SetupTest(
<< ", endpointsDir: " << ClientFactory.GetEndpointStorageDir());

if (EndpointStorage) {
auto error = EndpointStorage->Init();
Y_ABORT_UNLESS(!HasError(error));
EndpointsDir = std::make_unique<TTempDir>(
ClientFactory.GetEndpointStorageDir());

auto strOrError = SerializeEndpoint(*request);
Y_ABORT_UNLESS(!HasError(strOrError));
Expand Down Expand Up @@ -538,6 +538,7 @@ void TLoadTestRunner::TeardownTest(
if (EndpointStorage) {
auto error = EndpointStorage->RemoveEndpoint(EndpointSocketPath);
Y_ABORT_UNLESS(!HasError(error));
EndpointsDir.reset();
}

WaitForCompletion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class TLoadTestRunner
IVolumeStatsPtr VolumeStats;
IClientFactory& ClientFactory;
TTestContext& TestContext;
IMutableEndpointStoragePtr EndpointStorage;
IEndpointStoragePtr EndpointStorage;
std::unique_ptr<TTempDir> EndpointsDir;

TString EndpointSocketPath;

Expand Down
37 changes: 5 additions & 32 deletions cloud/filestore/libs/endpoint/service_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <cloud/storage/core/libs/common/scheduler_test.h>
#include <cloud/storage/core/libs/diagnostics/logging.h>
#include <cloud/storage/core/libs/endpoints/fs/fs_endpoints.h>
#include <cloud/storage/core/libs/endpoints/fs/fs_endpoints_test.h>

#include <library/cpp/testing/unittest/registar.h>

Expand All @@ -16,6 +15,7 @@
#include <util/generic/guid.h>
#include <util/generic/scope.h>
#include <util/system/sysstat.h>
#include <util/folder/tempdir.h>

namespace NCloud::NFileStore::NServer {

Expand Down Expand Up @@ -159,16 +159,7 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest)

const TString dirPath = "./" + CreateGuidAsString();
auto endpointStorage = CreateFileEndpointStorage(dirPath);
auto mutableStorage = CreateFileMutableEndpointStorage(dirPath);

auto initError = mutableStorage->Init();
UNIT_ASSERT_C(!HasError(initError), initError);

Y_DEFER {
auto error = mutableStorage->Remove();
UNIT_ASSERT_C(!HasError(error), error);
};

TTempDir endpointDir(dirPath);
auto endpoint = std::make_shared<TTestEndpoint>(*config, false);
auto listener = std::make_shared<TTestEndpointListener>();
listener->CreateEndpointHandler =
Expand Down Expand Up @@ -240,16 +231,7 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest)

const TString dirPath = "./" + CreateGuidAsString();
auto endpointStorage = CreateFileEndpointStorage(dirPath);
auto mutableStorage = CreateFileMutableEndpointStorage(dirPath);

auto initError = mutableStorage->Init();
UNIT_ASSERT_C(!HasError(initError), initError);

Y_DEFER {
auto error = mutableStorage->Remove();
UNIT_ASSERT_C(!HasError(error), error);
};

TTempDir endpointDir(dirPath);
auto endpoint = std::make_shared<TTestEndpoint>(*config, false);
auto listener = std::make_shared<TTestEndpointListener>();
listener->CreateEndpointHandler =
Expand Down Expand Up @@ -295,7 +277,7 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest)

// change endpoint settings

mutableStorage->RemoveEndpoint(id);
endpointStorage->RemoveEndpoint(id);

{
NProto::TStartEndpointRequest start;
Expand Down Expand Up @@ -360,16 +342,7 @@ Y_UNIT_TEST_SUITE(TServiceEndpointTest)

const TString dirPath = "./" + CreateGuidAsString();
auto endpointStorage = CreateFileEndpointStorage(dirPath);
auto mutableStorage = CreateFileMutableEndpointStorage(dirPath);

auto initError = mutableStorage->Init();
UNIT_ASSERT_C(!HasError(initError), initError);

Y_DEFER {
auto error = mutableStorage->Remove();
UNIT_ASSERT_C(!HasError(error), error);
};

TTempDir endpointDir(dirPath);
auto endpoint = std::make_shared<TTestEndpoint>(*config, false);
endpoint->Start.SetValue(NProto::TError{});

Expand Down
76 changes: 0 additions & 76 deletions cloud/storage/core/libs/endpoints/fs/fs_endpoints_test.cpp

This file was deleted.

14 changes: 0 additions & 14 deletions cloud/storage/core/libs/endpoints/fs/fs_endpoints_test.h

This file was deleted.

Loading

0 comments on commit dc18d70

Please sign in to comment.