TestReadAfterAIO: Use the local path instead of /tmp for temporal files

/tmp might be mounted as tmpfs (default in ArchLinux) which is incompatible with
O_DIRECT (https://lore.kernel.org/lkml/459D290B.1040703@tmr.com/t/), making the
test fail:

```
[ RUN      ] ReadBufferAIOTest.TestReadAfterAIO
unknown file: Failure
C++ exception with description "Cannot open file /tmp/filei6ZsCa/foo, errno: 22, strerror: Invalid argument" thrown in the test body.
[  FAILED  ] ReadBufferAIOTest.TestReadAfterAIO (0 ms)
```

Instead create the tmp folder in the local path and delete it at the end
This commit is contained in:
Raúl Marín 2021-05-15 02:13:45 +02:00
parent fa3ac3d7d2
commit 0ddfc3df84

View File

@ -6,6 +6,7 @@
#include <unistd.h>
#include <IO/ReadBufferAIO.h>
#include <Common/randomSeed.h>
#include <filesystem>
#include <fstream>
#include <string>
@ -14,7 +15,7 @@ namespace
{
std::string createTmpFileForEOFtest()
{
char pattern[] = "/tmp/fileXXXXXX";
char pattern[] = "./EOFtestFolderXXXXXX";
if (char * dir = ::mkdtemp(pattern); dir)
{
return std::string(dir) + "/foo";
@ -78,6 +79,11 @@ TEST(ReadBufferAIOTest, TestReadAfterAIO)
size_t read_after_eof_big = testbuf.read(repeatdata.data(), repeatdata.size());
EXPECT_EQ(read_after_eof_big, data.length());
EXPECT_TRUE(testbuf.eof());
if (file_path[0] != '/')
{
std::filesystem::remove_all(file_path.substr(0, file_path.size() - 4));
}
}
#endif