17 #include <condition_variable> 20 #include <boost/filesystem.hpp> 30 using namespace folly;
39 fs::path tmpFilePath{tmpDir.
path() /
"file-poller"};
44 auto previous = std::chrono::system_clock::from_time_t(
45 boost::filesystem::last_write_time(fileName));
46 auto diff = std::chrono::seconds(10);
47 std::chrono::system_clock::time_point newTime;
49 newTime = previous +
diff;
51 newTime = previous -
diff;
54 time_t newTimet = std::chrono::system_clock::to_time_t(newTime);
55 boost::filesystem::last_write_time(fileName, newTimet);
62 FilePoller poller(std::chrono::milliseconds(1));
76 FilePoller poller(std::chrono::milliseconds(1));
90 remove(tmpFile.c_str());
91 FilePoller poller(std::chrono::milliseconds(1));
96 File(creat(tmpFile.c_str(), O_RDONLY));
103 bool updated =
false;
105 FilePoller poller(std::chrono::milliseconds(1));
110 remove(tmpFile.c_str());
117 std::condition_variable
cv;
121 std::unique_lock<std::mutex> lk(m);
127 std::unique_lock<std::mutex> lk(m);
128 cv.wait_for(lk, std::chrono::milliseconds(100), [&] {
return updated; });
136 TestFile(
bool exists, time_t mTime) : exists_(exists), modTime_(mTime) {}
139 std::unique_lock<std::mutex> lk(
m);
145 std::unique_lock<std::mutex> lk(
m);
166 return testFile_.toFileModData();
175 poller = std::make_unique<NoDiskPoller>(testFile);
176 poller->addFileToTrack(testFile.
name, [&] {
177 state.updateTriggered();
199 testFile.
update(
false, 0);
PollerWithState(TestFile &testFile)
static SingletonVault * singleton()
#define ASSERT_EQ(val1, val2)
NoDiskPoller(TestFile &testFile)
void waitForUpdate(bool expect=true)
TEST_F(TestInfoTest, Names)
#define EXPECT_EQ(val1, val2)
std::condition_variable cv
—— Concurrent Priority Queue Implementation ——
requires E e noexcept(noexcept(s.error(std::move(e))))
void updateModifiedTime(const std::string &fileName, bool forward=true)
FOLLY_ALWAYS_INLINE bool try_wait_for(const std::chrono::duration< Rep, Period > &timeout, const WaitOptions &opt=wait_options()) noexcept
void addFileToTrack(const std::string &fileName, Cob yCob, Cob nCob=nullptr, Condition condition=fileTouchedCondInternal)
TEST(GTestEnvVarTest, Dummy)
static map< string, int > m
void update(bool e, time_t t)
void expect(LineReader &lr, const char *expected)
uint64_t diff(uint64_t a, uint64_t b)
FilePoller::FileModificationData getFileModData(const std::string &path) noexceptoverride
void waitForUpdate(bool expect=true)
std::unique_ptr< FilePoller > poller
TestFile(bool exists, time_t mTime)
#define ASSERT_NO_FATAL_FAILURE(statement)
FilePoller::FileModificationData toFileModData()
#define ASSERT_FALSE(condition)
#define ASSERT_TRUE(condition)
const fs::path & path() const
TemporaryDirectory tmpDir