mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-26 07:30:54 +00:00
Make sure GetUniqueID releated tests run on "regular" storage
Summary: With the use of tmpfs or ramfs, unit tests related to GetUniqueID() failed because of the failure from ioctl, which doesn't work with these fancy file systems at all. I fixed this issue and make sure all related tests run on the "regular" storage (disk or flash). Test Plan: TEST_TMPDIR=/dev/shm make check -j32 Reviewers: igor, dhruba CC: leveldb Differential Revision: https://reviews.facebook.net/D16593
This commit is contained in:
parent
ecb1ffa2a8
commit
abeee9f2cb
|
@ -7,6 +7,7 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <unordered_set>
|
||||
|
@ -191,6 +192,15 @@ bool IsSingleVarint(const std::string& s) {
|
|||
}
|
||||
|
||||
#ifdef OS_LINUX
|
||||
// To make sure the Env::GetUniqueId() related tests work correctly, The files
|
||||
// should be stored in regular storage like "hard disk" or "flash device".
|
||||
// Otherwise we cannot get the correct id.
|
||||
//
|
||||
// The following function act as the replacement of test::TmpDir() that may be
|
||||
// customized by user to be on a storage that doesn't work with GetUniqueId().
|
||||
//
|
||||
// TODO(kailiu) This function still assumes /tmp/<test-dir> reside in regular
|
||||
// storage system.
|
||||
bool IsUniqueIDValid(const std::string& s) {
|
||||
return !s.empty() && !IsSingleVarint(s);
|
||||
}
|
||||
|
@ -198,11 +208,21 @@ bool IsUniqueIDValid(const std::string& s) {
|
|||
const size_t MAX_ID_SIZE = 100;
|
||||
char temp_id[MAX_ID_SIZE];
|
||||
|
||||
std::string GetOnDiskTestDir() {
|
||||
char base[100];
|
||||
snprintf(base, sizeof(base), "/tmp/rocksdbtest-%d",
|
||||
static_cast<int>(geteuid()));
|
||||
// Directory may already exist
|
||||
Env::Default()->CreateDirIfMissing(base);
|
||||
|
||||
return base;
|
||||
}
|
||||
|
||||
// Only works in linux platforms
|
||||
TEST(EnvPosixTest, RandomAccessUniqueID) {
|
||||
// Create file.
|
||||
const EnvOptions soptions;
|
||||
std::string fname = test::TmpDir() + "/" + "testfile";
|
||||
std::string fname = GetOnDiskTestDir() + "/" + "testfile";
|
||||
unique_ptr<WritableFile> wfile;
|
||||
ASSERT_OK(env_->NewWritableFile(fname, &wfile, soptions));
|
||||
|
||||
|
@ -261,7 +281,7 @@ TEST(EnvPosixTest, RandomAccessUniqueIDConcurrent) {
|
|||
// Create the files
|
||||
std::vector<std::string> fnames;
|
||||
for (int i = 0; i < 1000; ++i) {
|
||||
fnames.push_back(test::TmpDir() + "/" + "testfile" + std::to_string(i));
|
||||
fnames.push_back(GetOnDiskTestDir() + "/" + "testfile" + std::to_string(i));
|
||||
|
||||
// Create file.
|
||||
unique_ptr<WritableFile> wfile;
|
||||
|
@ -294,7 +314,8 @@ TEST(EnvPosixTest, RandomAccessUniqueIDConcurrent) {
|
|||
// Only works in linux platforms
|
||||
TEST(EnvPosixTest, RandomAccessUniqueIDDeletes) {
|
||||
const EnvOptions soptions;
|
||||
std::string fname = test::TmpDir() + "/" + "testfile";
|
||||
|
||||
std::string fname = GetOnDiskTestDir() + "/" + "testfile";
|
||||
|
||||
// Check that after file is deleted we don't get same ID again in a new file.
|
||||
std::unordered_set<std::string> ids;
|
||||
|
|
Loading…
Reference in a new issue