diff options
Diffstat (limited to 'test/bbackupd/testbbackupd.cpp')
-rw-r--r-- | test/bbackupd/testbbackupd.cpp | 71 |
1 files changed, 37 insertions, 34 deletions
diff --git a/test/bbackupd/testbbackupd.cpp b/test/bbackupd/testbbackupd.cpp index dd50b862..cc602f22 100644 --- a/test/bbackupd/testbbackupd.cpp +++ b/test/bbackupd/testbbackupd.cpp @@ -361,8 +361,8 @@ bool configure_bbackupd(BackupDaemon& bbackupd, const std::string& config_file) // Stop bbackupd initialisation from changing the console logging level // and the program name tag. Logger& console(Logging::GetConsole()); - Logger::LevelGuard guard(console, console.GetLevel()); - Logging::Tagger(); + Logger::LevelGuard undo_log_level_change(console, console.GetLevel()); + Logging::Tagger undo_program_name_change; std::vector<std::string> args; size_t last_arg_start = 0; @@ -2277,9 +2277,8 @@ bool test_read_only_dirs_can_be_restored() { { #ifdef WIN32 - // Cygwin chmod changes Windows file attributes - TEST_THAT(::system("chmod 0555 testfiles/" - "TestDir1/x1") == 0); + TEST_THAT(::system("attrib +r testfiles\\TestDir1\\x1") + == 0); #else TEST_THAT(chmod("testfiles/TestDir1/x1", 0555) == 0); @@ -2303,12 +2302,12 @@ bool test_read_only_dirs_can_be_restored() // put the permissions back to sensible values #ifdef WIN32 - TEST_THAT(::system("chmod 0755 testfiles/" - "TestDir1/x1") == 0); - TEST_THAT(::system("chmod 0755 testfiles/" - "restore1/x1") == 0); - TEST_THAT(::system("chmod 0755 testfiles/" - "restore-test/Test1/x1") == 0); + TEST_THAT(::system("attrib -r testfiles\\TestDir1\\x1") + == 0); + TEST_THAT(::system("attrib -r testfiles\\restore1\\x1") + == 0); + TEST_THAT(::system("attrib -r testfiles\\restore-test\\" + "Test1\\x1") == 0); #else TEST_THAT(chmod("testfiles/TestDir1/x1", 0755) == 0); @@ -2723,9 +2722,6 @@ bool test_store_error_reporting() // TODO FIXME dedent { - // Check that store errors are reported neatly - TEST_THAT(system("rm -f testfiles/notifyran.backup-error.*") == 0); - // Break the store. We need a write lock on the account // while we do this, otherwise housekeeping might be running // and might rewrite the info files when it finishes, @@ -3146,11 +3142,11 @@ bool test_upload_very_old_files() { // in the archive, it's read only #ifdef WIN32 - TEST_THAT(::system("chmod 0777 testfiles" - "/TestDir1/sub23/rand.h") == 0); + TEST_THAT(::system("attrib -r " + "testfiles\\TestDir\\sub23\\rand.h") == 0); #else - TEST_THAT(chmod("testfiles/TestDir1/sub23" - "/rand.h", 0777) == 0); + TEST_THAT(chmod("testfiles/TestDir1/sub23/rand.h", + 0777) == 0); #endif FILE *f = fopen("testfiles/TestDir1/sub23/rand.h", @@ -3393,7 +3389,7 @@ bool test_delete_dir_change_attribute() #endif // Change attributes on an existing file. #ifdef WIN32 - TEST_EQUAL(0, system("chmod 0423 testfiles/TestDir1/df9834.dsf")); + TEST_EQUAL(0, system("attrib +r testfiles\\TestDir1\\df9834.dsf")); #else TEST_THAT(::chmod("testfiles/TestDir1/df9834.dsf", 0423) == 0); #endif @@ -3578,8 +3574,14 @@ bool test_sync_new_files() // OpenBSD's tar interprets the "-m" option quite differently: // it sets the time to epoch zero (1 Jan 1970) instead of the // current time, which doesn't help us. So reset the timestamp - // on a file with the touch command, so it won't be backed up. - TEST_RETURN(::system("touch testfiles/TestDir1/chsh"), 0); + // on a file by touching it, so it won't be backed up. + { +#ifndef WIN32 + TEST_THAT(chmod("testfiles/TestDir1/chsh", 0755) == 0); +#endif + FileStream fs("testfiles/TestDir1/chsh", O_WRONLY); + fs.Write("a", 1); + } // At least one file is too new to be backed up on the first run. bbackupd.RunSyncNow(); @@ -3673,6 +3675,7 @@ bool test_changing_client_store_marker_pauses_daemon() box_time_t sync_start_time = GetCurrentBoxTime(); sync_and_wait(); box_time_t sync_time = GetCurrentBoxTime() - sync_start_time; + BOX_INFO("Sync takes " << BOX_FORMAT_MICROSECONDS(sync_time)); // Time how long a compare takes. On NetBSD it's 3 seconds, and that // interferes with test timing unless we account for it. @@ -3680,7 +3683,7 @@ bool test_changing_client_store_marker_pauses_daemon() // There should be no differences right now (yet). TEST_COMPARE(Compare_Same); box_time_t compare_time = GetCurrentBoxTime() - compare_start_time; - BOX_TRACE("Compare takes " << BOX_FORMAT_MICROSECONDS(compare_time)); + BOX_INFO("Compare takes " << BOX_FORMAT_MICROSECONDS(compare_time)); // Wait for the end of another sync, to give us ~3 seconds to change // the client store marker. @@ -3746,35 +3749,35 @@ bool test_changing_client_store_marker_pauses_daemon() // Test that there *are* differences still, i.e. that bbackupd // didn't successfully run a backup during that time. - BOX_TRACE("Compare starting, expecting differences"); + BOX_INFO("Compare starting, expecting differences"); TEST_COMPARE(Compare_Different); BOX_TRACE("Compare finished, expected differences"); // Wait out the expected delay in bbackupd. This is quite // time-sensitive, so we use sub-second precision. - box_time_t wait = + box_time_t wait = SecondsToBoxTime(BACKUP_ERROR_DELAY_SHORTENED - 1) - compare_time * 2; - BOX_TRACE("Waiting for " << BOX_FORMAT_MICROSECONDS(wait) << - " (plus another compare taking " << - BOX_FORMAT_MICROSECONDS(compare_time) << ") until " - "just before bbackupd recovers"); + BOX_INFO("Waiting for " << BOX_FORMAT_MICROSECONDS(wait) << " " + "until just before bbackupd recovers"); ShortSleep(wait, true); // bbackupd should not have recovered yet, so there should // still be differences. - BOX_TRACE("Compare starting, expecting differences"); + BOX_INFO("Compare starting, expecting differences"); TEST_COMPARE(Compare_Different); BOX_TRACE("Compare finished, expected differences"); - // Now wait for it to recover and finish a sync, and check - // that the differences are gone (successful backup). - wait = sync_time + SecondsToBoxTime(2); - BOX_TRACE("Waiting for " << BOX_FORMAT_MICROSECONDS(wait) << + // Now wait for it to recover and finish a sync, and check that + // the differences are gone (successful backup). Wait until ~2 + // seconds after we expect the sync to have finished, to reduce + // the risk of random failure on AppVeyor when heavily loaded. + wait = sync_time + SecondsToBoxTime(6); + BOX_INFO("Waiting for " << BOX_FORMAT_MICROSECONDS(wait) << " until just after bbackupd recovers and finishes a sync"); ShortSleep(wait, true); - BOX_TRACE("Compare starting, expecting no differences"); + BOX_INFO("Compare starting, expecting no differences"); TEST_COMPARE(Compare_Same); BOX_TRACE("Compare finished, expected no differences"); } |