提交 b6b64db0 编写于 作者: S superjom

fix test unstable with try recursive make tmp

some time should wait between read service and get item
上级 c0a975e8
......@@ -7,13 +7,16 @@ namespace visualdl {
struct ScalarTestHelper {
ImHelper rim;
ImHelper wim;
const std::string dir = "./tmp/1.test";
const std::string dir = "./tmp/sdk_test.test";
void operator()(std::function<void()> read, std::function<void()> write) {
wim.StartWriteSerice(dir, 200);
write();
rim.StartReadService(dir, 200);
// should wait for the write service create log's path
std::this_thread::sleep_for(std::chrono::milliseconds(400));
rim.StartReadService(dir, 100);
// should wait for the read service to load "tag0" tablet into memory
std::this_thread::sleep_for(std::chrono::milliseconds(600));
read();
}
......
......@@ -44,7 +44,7 @@ void MemoryStorage::PersistToDisk(const std::string &dir) {
CHECK(!dir.empty());
storage_.set_dir(dir);
// make a directory if not exist
fs::TryMkdir(dir);
fs::TryRecurMkdir(dir);
// write storage out
LOG(INFO) << "to serize meta to dir " << dir;
fs::SerializeToFile(storage_, meta_path(dir));
......
......@@ -44,13 +44,26 @@ bool DeSerializeFromFile(T* proto, const std::string& path) {
}
void TryMkdir(const std::string& dir) {
VLOG(1) << "try to mkdir " << dir;
LOG(INFO) << "try to mkdir " << dir;
struct stat st = {0};
if (stat(dir.c_str(), &st) == -1) {
::mkdir(dir.c_str(), 0700);
}
}
// Create a path by recursively create directries
void TryRecurMkdir(const std::string& path) {
// split path by '/'
for (int i = 1; i < path.size() - 1; i++) {
if (path[i] == '/') {
auto dir = path.substr(0, i + 1);
TryMkdir(dir);
}
}
// the last level
TryMkdir(path);
}
inline void Write(const std::string& path,
const std::string& buffer,
std::ios::openmode open_mode = std::ios::binary) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册