Skip to content

Commit 34bb8b6

Browse files
committed
[net] Use TempFileName() in testParallelMergingFile
1 parent 7b4ab4a commit 34bb8b6

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

net/net/test/testParallelMergingFile.cxx

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static void Server(std::unique_ptr<TServerSocket> ss, const std::string &outFile
6767
msg->ReadTString(filename);
6868
msg->ReadLong64(length);
6969

70-
// XXX: this lock is here to work around https://github.com/root-project/root/issues/20641
70+
// NOTE: this lock is here to work around https://github.com/root-project/root/issues/20641
7171
// Note that we don't care about minimizing its scope since we are not testing multithreaded scaling here
7272
// and it's fine if the client's and server's operations get serialized by the mutexes.
7373
std::scoped_lock<std::mutex> lock(gMutex);
@@ -94,28 +94,34 @@ static void Server(std::unique_ptr<TServerSocket> ss, const std::string &outFile
9494

9595
TEST(TParallelMergingFile, UploadAndResetNonTObject)
9696
{
97-
constexpr auto sockPath = "/tmp/parallelMergeTest.sock";
97+
TString sockPath = "parallelMergeTest";
98+
FILE *dummy = gSystem->TempFileName(sockPath);
99+
if (!dummy) {
100+
Error("fastMergeServer", "Cannot create temporary file for socket\n");
101+
return;
102+
}
103+
std::string socketPath(sockPath.View());
104+
gSystem->Unlink(socketPath.c_str());
105+
fclose(dummy);
98106

99107
// Start server
100-
gSystem->Unlink(sockPath);
101-
auto ss = std::make_unique<TServerSocket>(sockPath);
108+
auto ss = std::make_unique<TServerSocket>(socketPath.c_str());
102109
ASSERT_TRUE(ss->IsValid());
103110

104111
struct Cleanup {
105112
const char *fSockPath;
106113
Cleanup(const char *sockPath) : fSockPath(sockPath) {}
107114
~Cleanup() { gSystem->Unlink(fSockPath); }
108-
} cleanup(sockPath);
115+
} cleanup(socketPath.c_str());
109116

110117
ROOT::TestSupport::FileRaii fileGuardMerged("parallelFileMerged.root");
111118

112119
std::thread serverThread(Server, std::move(ss), fileGuardMerged.GetPath());
113120

114121
// Create "client-side" file
115122
auto *file = dynamic_cast<TParallelMergingFile *>(
116-
TFile::Open((std::string("parallelMergeTest.root?pmerge=") + sockPath).c_str(), "RECREATE"));
123+
TFile::Open((std::string("parallelMergeTest.root?pmerge=") + socketPath).c_str(), "RECREATE"));
117124
ASSERT_NE(file, nullptr);
118-
file->SetCacheWrite(nullptr);
119125

120126
ROOT::TestSupport::CheckDiagsRAII diags;
121127
diags.optionalDiag(kWarning, "TParallelMergingFile::ResetObjects", "can not be ResetAfterMerge", false);
@@ -168,16 +174,14 @@ TEST(TParallelMergingFile, UploadAndResetNonTObject)
168174

169175
serverThread.join();
170176

171-
{
172-
auto reader = ROOT::RNTupleReader::Open("ntpl", fileGuardMerged.GetPath());
173-
EXPECT_EQ(reader->GetNEntries(), kNEntries);
174-
175-
auto px = reader->GetModel().GetDefaultEntry().GetPtr<float>("px");
176-
auto py = reader->GetModel().GetDefaultEntry().GetPtr<float>("py");
177-
for (auto idx : reader->GetEntryRange()) {
178-
reader->LoadEntry(idx);
179-
EXPECT_FLOAT_EQ(*px, idx);
180-
EXPECT_FLOAT_EQ(*py, 2 * idx);
181-
}
177+
auto reader = ROOT::RNTupleReader::Open("ntpl", fileGuardMerged.GetPath());
178+
EXPECT_EQ(reader->GetNEntries(), kNEntries);
179+
180+
auto px = reader->GetModel().GetDefaultEntry().GetPtr<float>("px");
181+
auto py = reader->GetModel().GetDefaultEntry().GetPtr<float>("py");
182+
for (auto idx : reader->GetEntryRange()) {
183+
reader->LoadEntry(idx);
184+
EXPECT_FLOAT_EQ(*px, idx);
185+
EXPECT_FLOAT_EQ(*py, 2 * idx);
182186
}
183187
}

0 commit comments

Comments
 (0)