Skip to content

Commit

Permalink
Remove remaining calls to check_num_files() without a BackupFileSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
qris committed Jan 2, 2018
1 parent d7a30bc commit 1a8dad6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 26 deletions.
8 changes: 0 additions & 8 deletions lib/backupstore/StoreTestUtils.cpp
Expand Up @@ -132,14 +132,6 @@ std::auto_ptr<BackupProtocolCallable> connect_and_login(TLSContext& rContext,
return protocol;
}

bool check_num_files(int files, int old, int deleted, int dirs)
{
std::auto_ptr<BackupStoreInfo> apInfo =
BackupStoreInfo::Load(0x1234567,
"backup/01234567/", 0, true);
return check_num_files(*apInfo, files, old, deleted, dirs);
}

bool check_num_files(BackupFileSystem& fs, int files, int old, int deleted, int dirs)
{
std::auto_ptr<BackupStoreInfo> apInfo = fs.GetBackupStoreInfoUncached();
Expand Down
1 change: 0 additions & 1 deletion lib/backupstore/StoreTestUtils.h
Expand Up @@ -43,7 +43,6 @@ std::auto_ptr<BackupProtocolCallable> connect_and_login(TLSContext& rContext,
int flags = 0);

//! Checks the number of files of each type in the store against expectations.
bool check_num_files(int files, int old, int deleted, int dirs);
bool check_num_files(BackupFileSystem& fs, int files, int old, int deleted, int dirs);
bool check_num_files(BackupStoreInfo& info, int files, int old, int deleted, int dirs);

Expand Down
23 changes: 13 additions & 10 deletions test/backupstore/testbackupstore.cpp
Expand Up @@ -1401,6 +1401,7 @@ bool test_multiple_uploads()
// TODO FIXME replace protocolReadOnly with apProtocolReadOnly.
BackupProtocolLocal2 protocolReadOnly(0x01234567, "test",
"backup/01234567/", 0, true); // ReadOnly
RaidBackupFileSystem fs(0x01234567, "backup/01234567/", 0);

// Read the root directory a few times (as it's cached, so make sure it doesn't hurt anything)
for(int l = 0; l < 3; ++l)
Expand Down Expand Up @@ -1430,7 +1431,7 @@ bool test_multiple_uploads()

// TODO FIXME dedent
{
TEST_THAT(check_num_files(0, 0, 0, 1));
TEST_THAT(check_num_files(fs, 0, 0, 0, 1));

// sleep to ensure that the timestamp on the file will change
::safe_sleep(1);
Expand Down Expand Up @@ -1471,7 +1472,7 @@ bool test_multiple_uploads()
if (t >= 13) expected_num_old_files++;
int expected_num_current_files = t + 1 - expected_num_old_files;

TEST_THAT(check_num_files(expected_num_current_files,
TEST_THAT(check_num_files(fs, expected_num_current_files,
expected_num_old_files, 0, 1));

apProtocol->QueryFinished();
Expand All @@ -1480,13 +1481,13 @@ bool test_multiple_uploads()
apProtocol = connect_and_login(context);
protocolReadOnly.Reopen();

TEST_THAT(check_num_files(expected_num_current_files,
TEST_THAT(check_num_files(fs, expected_num_current_files,
expected_num_old_files, 0, 1));
}

// Add some attributes onto one of them
{
TEST_THAT(check_num_files(UPLOAD_NUM - 3, 3, 0, 1));
TEST_THAT(check_num_files(fs, UPLOAD_NUM - 3, 3, 0, 1));
std::auto_ptr<IOStream> attrnew(
new MemBlockStream(attr3, sizeof(attr3)));
std::auto_ptr<BackupProtocolSuccess> set(apProtocol->QuerySetReplacementFileAttributes(
Expand All @@ -1495,7 +1496,7 @@ bool test_multiple_uploads()
uploads[UPLOAD_ATTRS_EN].name,
attrnew));
TEST_THAT(set->GetObjectID() == uploads[UPLOAD_ATTRS_EN].allocated_objid);
TEST_THAT(check_num_files(UPLOAD_NUM - 3, 3, 0, 1));
TEST_THAT(check_num_files(fs, UPLOAD_NUM - 3, 3, 0, 1));
}

apProtocol->QueryFinished();
Expand All @@ -1510,7 +1511,7 @@ bool test_multiple_uploads()
BACKUPSTORE_ROOT_DIRECTORY_ID,
uploads[UPLOAD_DELETE_EN].name));
TEST_THAT(del->GetObjectID() == uploads[UPLOAD_DELETE_EN].allocated_objid);
TEST_THAT(check_num_files(UPLOAD_NUM - 4, 3, 2, 1));
TEST_THAT(check_num_files(fs, UPLOAD_NUM - 4, 3, 2, 1));
}

apProtocol->QueryFinished();
Expand Down Expand Up @@ -1577,12 +1578,11 @@ bool test_multiple_uploads()
::free(buf);
}

TEST_THAT(check_num_files(UPLOAD_NUM - 4, 3, 2, 1));
TEST_THAT(check_num_files(fs, UPLOAD_NUM - 4, 3, 2, 1));

// Run housekeeping (for which we need to disconnect
// ourselves) and check that it doesn't change the numbers
// of files

apProtocol->QueryFinished();
protocolReadOnly.QueryFinished();

Expand All @@ -1602,7 +1602,7 @@ bool test_multiple_uploads()
apProtocol = connect_and_login(context);
protocolReadOnly.Reopen();

TEST_THAT(check_num_files(UPLOAD_NUM - 4, 3, 2, 1));
TEST_THAT(check_num_files(fs, UPLOAD_NUM - 4, 3, 2, 1));

{
// Fetch the block index for this one
Expand All @@ -1625,13 +1625,15 @@ bool test_multiple_uploads()
NULL, // pointer to DiffTimer impl
&modtime, &isCompletelyDifferent));
TEST_THAT(isCompletelyDifferent == false);

// Sent this to a file, so we can check the size, rather than uploading it directly
{
FileStream patch(TEST_FILE_FOR_PATCHING ".patch", O_WRONLY | O_CREAT);
patchstream->CopyStreamTo(patch);
}
// Make sure the stream is a plausible size for a patch containing only one new block
TEST_THAT(TestGetFileSize(TEST_FILE_FOR_PATCHING ".patch") < (8*1024));

// Upload it
int64_t patchedID = 0;
{
Expand All @@ -1657,9 +1659,10 @@ bool test_multiple_uploads()
std::auto_ptr<IOStream> filestream(apProtocol->ReceiveStream());
BackupStoreFile::DecodeFile(*filestream,
TEST_FILE_FOR_PATCHING ".downloaded", SHORT_TIMEOUT);

// Check it's the same
TEST_THAT(check_files_same(TEST_FILE_FOR_PATCHING ".downloaded", TEST_FILE_FOR_PATCHING ".mod"));
TEST_THAT(check_num_files(UPLOAD_NUM - 4, 4, 2, 1));
TEST_THAT(check_num_files(fs, UPLOAD_NUM - 4, 4, 2, 1));
}
}

Expand Down
18 changes: 11 additions & 7 deletions test/bbackupd/testbbackupd.cpp
Expand Up @@ -1474,6 +1474,8 @@ bool test_backup_pauses_when_store_is_full()
unpack_files("spacetest1", "testfiles/TestDir1");
TEST_THAT_OR(StartClient(), FAIL);

RaidBackupFileSystem fs(0x01234567, "backup/01234567/", 0);

// TODO FIXME dedent
{
// wait for files to be uploaded
Expand All @@ -1486,7 +1488,7 @@ bool test_backup_pauses_when_store_is_full()
{
std::auto_ptr<BackupProtocolCallable> client =
connect_and_login(sTlsContext, 0 /* read-write */);
TEST_THAT(check_num_files(5, 0, 0, 9));
TEST_THAT(check_num_files(fs, 5, 0, 0, 9));
TEST_THAT(check_num_blocks(*client, 10, 0, 0, 18, 28));
client->QueryFinished();
}
Expand Down Expand Up @@ -1594,7 +1596,7 @@ bool test_backup_pauses_when_store_is_full()
TEST_EQUAL(SearchDir(*spacetest_dir, "f1"), 0);
TEST_EQUAL(SearchDir(*spacetest_dir, "d7"), 0);

TEST_THAT(check_num_files(4, 0, 0, 8));
TEST_THAT(check_num_files(fs, 4, 0, 0, 8));
TEST_THAT(check_num_blocks(*client, 8, 0, 0, 16, 24));
client->QueryFinished();
}
Expand All @@ -1614,6 +1616,8 @@ bool test_bbackupd_exclusions()
{
SETUP_WITHOUT_FILES();

RaidBackupFileSystem fs(0x01234567, "backup/01234567/", 0);

TEST_THAT(unpack_files("spacetest1", "testfiles/TestDir1"));
// Delete a file and a directory
TEST_THAT(EMU_UNLINK("testfiles/TestDir1/spacetest/f1") == 0);
Expand All @@ -1638,7 +1642,7 @@ bool test_bbackupd_exclusions()
{
std::auto_ptr<BackupProtocolCallable> client =
connect_and_login(sTlsContext, 0 /* read-write */);
TEST_THAT(check_num_files(4, 0, 0, 8));
TEST_THAT(check_num_files(fs, 4, 0, 0, 8));
TEST_THAT(check_num_blocks(*client, 8, 0, 0, 16, 24));
client->QueryFinished();
}
Expand All @@ -1663,7 +1667,7 @@ bool test_bbackupd_exclusions()
{
std::auto_ptr<BackupProtocolCallable> client =
connect_and_login(sTlsContext, 0 /* read-write */);
TEST_THAT(check_num_files(4, 0, 0, 8));
TEST_THAT(check_num_files(fs, 4, 0, 0, 8));
TEST_THAT(check_num_blocks(*client, 8, 0, 0, 16, 24));
client->QueryFinished();
}
Expand Down Expand Up @@ -1766,7 +1770,7 @@ bool test_bbackupd_exclusions()
// server which are not deleted, they use 2 blocks
// each, the rest is directories and 2 deleted files
// (f2 and d3/d4/f5)
TEST_THAT(check_num_files(2, 0, 2, 8));
TEST_THAT(check_num_files(fs, 2, 0, 2, 8));
TEST_THAT(check_num_blocks(*client, 4, 0, 4, 16, 24));

// Log out.
Expand Down Expand Up @@ -1807,7 +1811,7 @@ bool test_bbackupd_exclusions()
// f2, d3, d3/d4 and d3/d4/f5 have been removed.
// The files were counted as deleted files before, the
// deleted directories just as directories.
TEST_THAT(check_num_files(2, 0, 0, 6));
TEST_THAT(check_num_files(fs, 2, 0, 0, 6));
TEST_THAT(check_num_blocks(*client, 4, 0, 0, 12, 16));

// Log out.
Expand Down Expand Up @@ -1835,7 +1839,7 @@ bool test_bbackupd_exclusions()
std::auto_ptr<BackupProtocolCallable> client =
connect_and_login(sTlsContext, 0 /* read-write */);

TEST_THAT(check_num_files(4, 0, 0, 7));
TEST_THAT(check_num_files(fs, 4, 0, 0, 7));
TEST_THAT(check_num_blocks(*client, 8, 0, 0, 14, 22));

// d2/f6, d6/d8 and d6/d8/f7 are new
Expand Down

0 comments on commit 1a8dad6

Please sign in to comment.