Add test case that loading a node doesn't modify time stamps

This commit is contained in:
Sebastian Messmer 2016-06-06 15:20:41 -07:00
parent 3ec52e94c7
commit 7708287fdd
3 changed files with 47 additions and 4 deletions

View File

@ -11,9 +11,11 @@
#include "FsppNodeTest_Stat.h"
#include "FsppNodeTest_Timestamps.h"
#include "FsppOpenFileTest.h"
#include "FsppDeviceTest_Timestamps.h"
#define FSPP_ADD_FILESYTEM_TESTS(FS_NAME, FIXTURE) \
INSTANTIATE_TYPED_TEST_CASE_P(FS_NAME, FsppDeviceTest, FIXTURE); \
INSTANTIATE_NODE_TEST_CASE( FS_NAME, FsppDeviceTest_Timestamps, FIXTURE); \
INSTANTIATE_TYPED_TEST_CASE_P(FS_NAME, FsppDirTest, FIXTURE); \
INSTANTIATE_TYPED_TEST_CASE_P(FS_NAME, FsppFileTest, FIXTURE); \
INSTANTIATE_TYPED_TEST_CASE_P(FS_NAME, FsppSymlinkTest, FIXTURE); \
@ -25,5 +27,4 @@
INSTANTIATE_TYPED_TEST_CASE_P(FS_NAME, FsppNodeTest_Stat_SymlinkOnly, FIXTURE); \
INSTANTIATE_TYPED_TEST_CASE_P(FS_NAME, FsppOpenFileTest, FIXTURE); \
#endif

View File

@ -0,0 +1,42 @@
#pragma once
#ifndef MESSMER_FSPP_FSTEST_FSPPDEVICETEST_TIMESTAMPS_H_
#define MESSMER_FSPP_FSTEST_FSPPDEVICETEST_TIMESTAMPS_H_
#include "testutils/TimestampTestUtils.h"
template<class ConcreteFileSystemTestFixture>
class FsppDeviceTest_Timestamps: public FsppNodeTest<ConcreteFileSystemTestFixture>, public TimestampTestUtils {
public:
void Test_Load_While_Loaded() {
auto file = this->CreateFile("/myfile");
auto operation = [this, &file] () {
this->device->Load("/myfile");
};
this->EXPECT_OPERATION_DOESNT_UPDATE_TIMESTAMPS(*file, operation);
}
void Test_Load_While_Not_Loaded() {
struct stat oldStat;
{
auto file = this->CreateFile("/myfile");
oldStat = stat(*file);
this->ensureNodeTimestampsAreOld(*file);
}
this->device->Load("/myfile");
auto file = this->device->Load("/myfile");
struct stat newStat = stat(*file.value());
EXPECT_EQ(oldStat.st_atim, newStat.st_atim);
EXPECT_EQ(oldStat.st_mtim, newStat.st_mtim);
EXPECT_EQ(oldStat.st_ctim, newStat.st_ctim);
}
};
REGISTER_NODE_TEST_CASE(FsppDeviceTest_Timestamps,
Load_While_Loaded,
Load_While_Not_Loaded
);
#endif

View File

@ -81,7 +81,7 @@ public:
struct stat newStat = stat(node);
EXPECT_EQ(oldStat.st_atim, newStat.st_atim);
EXPECT_EQ(oldStat.st_mtim, newStat.st_mtim);
EXPECT_LE(oldStat.st_ctim, newStat.st_ctim);
EXPECT_EQ(oldStat.st_ctim, newStat.st_ctim);
}
void EXPECT_OPERATION_ONLY_UPDATES_METADATACHANGE_TIMESTAMP(const fspp::Node &node, std::function<void()> operation) {
@ -113,8 +113,6 @@ public:
return result;
}
private:
void ensureNodeTimestampsAreOld(const fspp::Node &node) {
waitUntilClockProgresses();
EXPECT_LT(stat(node).st_atim, cpputils::time::now());
@ -122,6 +120,8 @@ private:
EXPECT_LT(stat(node).st_ctim, cpputils::time::now());
}
private:
void waitUntilClockProgresses() {
auto start = cpputils::time::now();
while (start == cpputils::time::now()) {