From 1556500604d988635b9623ec9aa0b4418ed5efe4 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Mon, 18 Sep 2017 07:35:44 +0100 Subject: [PATCH] Add extra refcount checks to test_server_housekeeping --- test/backupstore/testbackupstore.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/test/backupstore/testbackupstore.cpp b/test/backupstore/testbackupstore.cpp index 7e563c022..ed1578828 100644 --- a/test/backupstore/testbackupstore.cpp +++ b/test/backupstore/testbackupstore.cpp @@ -860,6 +860,7 @@ bool test_server_housekeeping() TEST_THAT(check_num_files(0, 0, 0, 1)); TEST_THAT(check_num_blocks(protocol, 0, 0, 0, root_dir_blocks, root_dir_blocks)); + TEST_THAT(check_reference_counts()); // Store a file -- first make the encoded file BackupStoreFilenameClear store1name("file1"); @@ -992,6 +993,7 @@ bool test_server_housekeeping() TEST_THAT(check_num_files(1, 0, 0, 1)); TEST_THAT(check_num_blocks(protocol, file1_blocks, 0, 0, root_dir_blocks, file1_blocks + root_dir_blocks)); + TEST_THAT(check_reference_counts()); // Upload again, as a patch to the original file. int64_t patch1_id = BackupStoreFile::QueryStoreFileDiff(protocol, @@ -1003,6 +1005,8 @@ bool test_server_housekeeping() ); TEST_EQUAL_LINE(3, patch1_id, "wrong ObjectID for newly uploaded " "patch file"); + // Update expected reference count of this new object + set_refcount(patch1_id, 1); // We need to check the old file's size, because it's been replaced // by a reverse diff, and patch1_id is a complete file, not a diff. @@ -1015,6 +1019,7 @@ bool test_server_housekeeping() TEST_THAT(check_num_files(1, 1, 0, 1)); TEST_THAT(check_num_blocks(protocol, file1_blocks, patch1_blocks, 0, root_dir_blocks, file1_blocks + patch1_blocks + root_dir_blocks)); + TEST_THAT(check_reference_counts()); // Change the file and upload again, as a patch to the original file. { @@ -1033,6 +1038,7 @@ bool test_server_housekeeping() ); TEST_EQUAL_LINE(4, patch2_id, "wrong ObjectID for newly uploaded " "patch file"); + set_refcount(patch2_id, 1); // How many blocks used by the new file? // We need to check the old file's size, because it's been replaced @@ -1043,6 +1049,7 @@ bool test_server_housekeeping() TEST_THAT(check_num_blocks(protocol, file1_blocks, patch1_blocks + patch2_blocks, 0, root_dir_blocks, file1_blocks + patch1_blocks + patch2_blocks + root_dir_blocks)); + TEST_THAT(check_reference_counts()); // Housekeeping should not change anything just yet protocol.QueryFinished(); @@ -1053,6 +1060,7 @@ bool test_server_housekeeping() TEST_THAT(check_num_blocks(protocol, file1_blocks, patch1_blocks + patch2_blocks, 0, root_dir_blocks, file1_blocks + patch1_blocks + patch2_blocks + root_dir_blocks)); + TEST_THAT(check_reference_counts()); // Upload not as a patch, but as a completely different file. This // marks the previous file as old (because the filename is the same) @@ -1066,6 +1074,7 @@ bool test_server_housekeeping() ); TEST_EQUAL_LINE(5, replaced_id, "wrong ObjectID for newly uploaded " "full file"); + set_refcount(replaced_id, 1); // How many blocks used by the new file? This time we need to check // the new file, because it's not a patch. @@ -1078,6 +1087,7 @@ bool test_server_housekeeping() root_dir_blocks, // directories file1_blocks + patch1_blocks + patch2_blocks + replaced_blocks + root_dir_blocks)); // total + TEST_THAT(check_reference_counts()); // Housekeeping should not change anything just yet protocol.QueryFinished(); @@ -1091,6 +1101,7 @@ bool test_server_housekeeping() root_dir_blocks, // directories file1_blocks + patch1_blocks + patch2_blocks + replaced_blocks + root_dir_blocks)); // total + TEST_THAT(check_reference_counts()); // But if we reduce the limits, then it will protocol.QueryFinished(); @@ -1100,12 +1111,17 @@ bool test_server_housekeeping() TEST_THAT(run_housekeeping_and_check_account()); protocol.Reopen(); + // We expect housekeeping to have removed the two oldest versions: + set_refcount(store1objid, 0); + set_refcount(patch1_id, 0); + TEST_THAT(check_num_files(1, 1, 0, 1)); TEST_THAT(check_num_blocks(protocol, replaced_blocks, // current file1_blocks, // old 0, // deleted root_dir_blocks, // directories file1_blocks + replaced_blocks + root_dir_blocks)); // total + TEST_THAT(check_reference_counts()); // Check that deleting files is accounted for as well protocol.QueryDeleteFile( @@ -1119,6 +1135,7 @@ bool test_server_housekeeping() replaced_blocks + file1_blocks, // deleted root_dir_blocks, // directories file1_blocks + replaced_blocks + root_dir_blocks)); + TEST_THAT(check_reference_counts()); // Reduce limits again, check that removed files are subtracted from // block counts. @@ -1126,10 +1143,15 @@ bool test_server_housekeeping() TEST_THAT(change_account_limits("0B", "2000B")); TEST_THAT(run_housekeeping_and_check_account()); protocol.Reopen(); - set_refcount(store1objid, 0); + + // We expect housekeeping to have removed the two most recent versions + // of the now-deleted file: + set_refcount(patch2_id, 0); + set_refcount(replaced_id, 0); TEST_THAT(check_num_files(0, 0, 0, 1)); TEST_THAT(check_num_blocks(protocol, 0, 0, 0, root_dir_blocks, root_dir_blocks)); + TEST_THAT(check_reference_counts()); // Close the protocol, so we can housekeep the account protocol.QueryFinished();