Skip to content

Commit

Permalink
NEBDUTY-500: use unique temp directories for unit tests data
Browse files Browse the repository at this point in the history
when running tests using `ya make` we have TMPDIR set to unique for each chunk of
unit tests.

In stable branch we still using `cmake` which doesn't pass unique TMPDIR and
therefore when running in parallel execution different tests can overwrite each
other data and fail.

This commit fixes this by using system unique tmpdir for each test.
  • Loading branch information
budevg committed Jan 31, 2024
1 parent 67d95ff commit db2850b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 32 deletions.
26 changes: 12 additions & 14 deletions cloud/blockstore/libs/service_local/storage_aio_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,6 @@ TFuture<NProto::TZeroBlocksResponse> ZeroBlocks(

}

TFsPath TryGetRamDrivePath()
{
auto p = GetRamDrivePath();
return !p
? GetSystemTempDir()
: p;
}

} // namespace

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -114,7 +106,8 @@ Y_UNIT_TEST_SUITE(TAioStorageTest)
{
const ui64 blockCount = 1024;
const ui64 startIndex = 10;
const auto filePath = TryGetRamDrivePath() / "test";
TTempDir dir;
const auto filePath = dir.Path() / "test";

TFile fileData(filePath, EOpenModeFlag::CreateAlways);
fileData.Resize(blockSize * (blockCount + startIndex));
Expand Down Expand Up @@ -223,7 +216,8 @@ Y_UNIT_TEST_SUITE(TAioStorageTest)
{
const ui32 blockSize = 4096;
const ui64 blockCount = 32_MB / blockSize;
const auto filePath = TryGetRamDrivePath() / "test";
TTempDir dir;
const auto filePath = dir.Path() / "test";

TFile fileData(filePath, EOpenModeFlag::CreateAlways);

Expand Down Expand Up @@ -332,7 +326,8 @@ Y_UNIT_TEST_SUITE(TAioStorageTest)
{
const ui32 blockSize = 4_KB;
const ui64 blockCount = 8_GB / blockSize;
const auto filePath = TryGetRamDrivePath() / "test";
TTempDir dir;
const auto filePath = dir.Path() / "test";

TFile fileData(filePath, EOpenModeFlag::CreateAlways);
fileData.Resize(blockSize * blockCount);
Expand Down Expand Up @@ -466,7 +461,8 @@ Y_UNIT_TEST_SUITE(TAioStorageTest)
{
const ui32 blockSize = 4_KB;
const ui64 blockCount = 32_MB / blockSize;
const auto filePath = TryGetRamDrivePath() / "test";
TTempDir dir;
const auto filePath = dir.Path() / "test";

TFile fileData(filePath, EOpenModeFlag::CreateAlways);
fileData.Resize(blockSize * blockCount);
Expand Down Expand Up @@ -531,7 +527,8 @@ Y_UNIT_TEST_SUITE(TAioStorageTest)
{
const ui32 blockSize = 4_KB;
const ui64 blockCount = 32_MB / blockSize;
const auto filePath = TryGetRamDrivePath() / "test";
TTempDir dir;
const auto filePath = dir.Path() / "test";

TFile fileData(filePath, EOpenModeFlag::CreateAlways);
fileData.Resize(blockSize * blockCount);
Expand Down Expand Up @@ -594,7 +591,8 @@ Y_UNIT_TEST_SUITE(TAioStorageTest)
{
const ui32 blockSize = 4_KB;
const ui64 blockCount = 32_MB / blockSize;
const auto filePath = TryGetRamDrivePath() / "test";
TTempDir dir;
const auto filePath = dir.Path() / "test";

TFile fileData(filePath, EOpenModeFlag::CreateAlways);
fileData.Resize(blockSize * blockCount);
Expand Down
3 changes: 2 additions & 1 deletion cloud/blockstore/libs/service_local/storage_aio_ut_large.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ Y_UNIT_TEST_SUITE(TAioStorageTest)
{
const ui32 blockSize = 4_KB;
const ui64 totalBlockCount = 5_GB / blockSize;
const auto filePath = TFsPath(GetSystemTempDir()) / "test";
TTempDir dir;
const auto filePath = dir.Path() / "test";

TFile fileData(filePath, EOpenModeFlag::CreateAlways);
fileData.Resize(blockSize * totalBlockCount);
Expand Down
29 changes: 14 additions & 15 deletions cloud/blockstore/libs/storage/disk_agent/disk_agent_actor_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@ NLWTrace::TQuery QueryFromString(const TString& text)
return query;
}

TFsPath TryGetRamDrivePath()
{
auto p = GetRamDrivePath();
return !p
? GetSystemTempDir()
: p;
}

} // namespace

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1333,7 +1325,8 @@ Y_UNIT_TEST_SUITE(TDiskAgentTest)

Y_UNIT_TEST(ShouldUpdateStats)
{
auto const workingDir = TryGetRamDrivePath();
TTempDir tempDir;
auto const workingDir = tempDir.Path();

TTestBasicRuntime runtime;

Expand Down Expand Up @@ -1600,7 +1593,8 @@ Y_UNIT_TEST_SUITE(TDiskAgentTest)
agentConfig.SetAcquireRequired(true);
agentConfig.SetEnabled(true);

auto const workingDir = TryGetRamDrivePath();
TTempDir tempDir;
auto const workingDir = tempDir.Path();

*agentConfig.AddFileDevices() = PrepareFileDevice(
workingDir / "test",
Expand Down Expand Up @@ -1781,7 +1775,8 @@ Y_UNIT_TEST_SUITE(TDiskAgentTest)
agentConfig.SetAcquireRequired(true);
agentConfig.SetEnabled(true);

const auto workingDir = TryGetRamDrivePath();
TTempDir tempDir;
const auto workingDir = tempDir.Path();
const auto filePath = workingDir / "test";

{
Expand Down Expand Up @@ -2044,7 +2039,8 @@ Y_UNIT_TEST_SUITE(TDiskAgentTest)
agentConfig.SetAgentId("agent-id");
agentConfig.SetEnabled(true);

auto const workingDir = TryGetRamDrivePath();
TTempDir tempDir;
auto const workingDir = tempDir.Path();

*agentConfig.AddFileDevices() = PrepareFileDevice(
workingDir / "test-1",
Expand Down Expand Up @@ -2211,7 +2207,8 @@ Y_UNIT_TEST_SUITE(TDiskAgentTest)
agentConfig.SetAgentId("agent-id");
agentConfig.SetEnabled(true);

auto const workingDir = TryGetRamDrivePath();
TTempDir tempDir;
auto const workingDir = tempDir.Path();

*agentConfig.AddFileDevices() = PrepareFileDevice(
workingDir / "test-1",
Expand All @@ -2237,7 +2234,8 @@ Y_UNIT_TEST_SUITE(TDiskAgentTest)
agentConfig.SetEnabled(true);
agentConfig.SetAcquireRequired(true);

auto const workingDir = TryGetRamDrivePath();
TTempDir tempDir;
auto const workingDir = tempDir.Path();

*agentConfig.AddFileDevices() = PrepareFileDevice(
workingDir / "test-1",
Expand Down Expand Up @@ -3221,7 +3219,8 @@ Y_UNIT_TEST_SUITE(TDiskAgentTest)
}
};

const auto workingDir = TryGetRamDrivePath();
TTempDir tempDir;
const auto workingDir = tempDir.Path();
TTestBasicRuntime runtime;
auto mockSp = new TMockStorageProvider();
std::shared_ptr<IStorageProvider> sp(mockSp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ Y_UNIT_TEST_SUITE(TDiskAgentLargeTest)
const ui32 blockSize = 4_KB;
const ui64 totalBlockCount = totalSize / blockSize;
const TString uuid = "FileDevice-1";
const auto filePath = TFsPath(GetSystemTempDir()) / "test";
TTempDir tempDir;
const auto filePath = tempDir.Path() / "test";

TFile fileData(filePath, EOpenModeFlag::CreateAlways);
fileData.Resize(totalSize);
Expand Down
4 changes: 3 additions & 1 deletion cloud/blockstore/vhost-server/server_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <library/cpp/testing/unittest/registar.h>
#include <library/cpp/threading/future/subscription/wait_all.h>

#include <util/folder/tempdir.h>
#include <util/generic/size_literals.h>
#include <util/system/file.h>

Expand Down Expand Up @@ -43,6 +44,7 @@ struct TFixture
NCloud::ILoggingServicePtr Logging;
std::shared_ptr<IServer> Server;
TVector<TFile> Files;
TTempDir TempDir;

TOptions Options {
.SocketPath = SocketPath,
Expand All @@ -65,7 +67,7 @@ struct TFixture
Files.reserve(ChunkCount);
for (ui32 i = 0; i != ChunkCount; ++i) {
auto& file = Files.emplace_back(
"nrd_" + ToString(i),
TempDir.Path() / ("nrd_" + ToString(i)),
EOpenModeFlag::CreateAlways);

Options.Layout.push_back({
Expand Down

0 comments on commit db2850b

Please sign in to comment.