Skip to content

Commit

Permalink
Add extra refcount checks to test_server_housekeeping
Browse files Browse the repository at this point in the history
  • Loading branch information
qris committed Oct 7, 2017
1 parent 0ab2508 commit 1556500
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion test/backupstore/testbackupstore.cpp
Expand Up @@ -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");
Expand Down Expand Up @@ -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,
Expand All @@ -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.
Expand All @@ -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.
{
Expand All @@ -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
Expand All @@ -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();
Expand All @@ -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)
Expand All @@ -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.
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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(
Expand All @@ -1119,17 +1135,23 @@ 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.
protocol.QueryFinished();
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();
Expand Down

0 comments on commit 1556500

Please sign in to comment.