fgerlits commented on a change in pull request #791: URL: https://github.com/apache/nifi-minifi-cpp/pull/791#discussion_r435325310
########## File path: libminifi/test/unit/FileUtilsTests.cpp ########## @@ -178,3 +179,157 @@ TEST_CASE("TestFileUtils::getFullPath", "[TestGetFullPath]") { REQUIRE(tempDir1 == utils::file::PathUtils::getFullPath(".\\test2\\..\\test1")); #endif } + +TEST_CASE("FileUtils::last_write_time works", "[last_write_time]") { + uint64_t timeBeforeWrite = getTimeMillis() / 1000; + + TestController testController; + + char format[] = "/tmp/gt.XXXXXX"; + std::string dir = testController.createTempDirectory(format); + + std::string test_file = dir + FileUtils::get_separator() + "test.txt"; + REQUIRE(FileUtils::last_write_time(test_file) == 0); + + std::ofstream test_file_stream(test_file); + test_file_stream << "foo\n"; + test_file_stream.flush(); + + uint64_t timeAfterFirstWrite = getTimeMillis() / 1000; + + uint64_t first_mtime = FileUtils::last_write_time(test_file); + REQUIRE(first_mtime >= timeBeforeWrite); + REQUIRE(first_mtime <= timeAfterFirstWrite); + + test_file_stream << "bar\n"; + test_file_stream.flush(); + + uint64_t timeAfterSecondWrite = getTimeMillis() / 1000; + + uint64_t second_mtime = FileUtils::last_write_time(test_file); + REQUIRE(second_mtime >= first_mtime); + REQUIRE(second_mtime >= timeAfterFirstWrite); + REQUIRE(second_mtime <= timeAfterSecondWrite); + + test_file_stream.close(); + uint64_t third_mtime = FileUtils::last_write_time(test_file); + REQUIRE(third_mtime == second_mtime); Review comment: There is no write to `test_file` between the two calls to `FileUtils::last_write_time` (and the stream was flushed earlier), so the mtimes should be identical, I think. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org