summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2014-09-04 01:36:21 +0000
committerChris Wilson <chris+github@qwirx.com>2014-09-04 01:36:21 +0000
commit5549d3f6f42a22d355b4d83402824b03106bd79a (patch)
tree8a99503d52bf6b0f24038c548da4b4a5b622c7db
parente00bd81ce959d02d3fa62e7e75956162f8e70c7e (diff)
More use of functions to simplify testbbackupd.
Merged back changes from the test refactor branch to reduce diffs.
-rw-r--r--test/backupstore/testbackupstore.cpp41
-rw-r--r--test/bbackupd/testbbackupd.cpp69
2 files changed, 23 insertions, 87 deletions
diff --git a/test/backupstore/testbackupstore.cpp b/test/backupstore/testbackupstore.cpp
index 5781d111..5b6910a2 100644
--- a/test/backupstore/testbackupstore.cpp
+++ b/test/backupstore/testbackupstore.cpp
@@ -674,15 +674,8 @@ void recursive_count_objects_r(BackupProtocolCallable &protocol, int64_t id,
TLSContext context;
-void recursive_count_objects(const char *hostname, int64_t id, recursive_count_objects_results &results)
+void recursive_count_objects(int64_t id, recursive_count_objects_results &results)
{
- // Context
- TLSContext context;
- context.Initialise(false /* client */,
- "testfiles/clientCerts.pem",
- "testfiles/clientPrivKey.pem",
- "testfiles/clientTrustedCAs.pem");
-
// Get a connection
BackupProtocolLocal2 protocolReadOnly(0x01234567, "test",
"backup/01234567/", 0, false);
@@ -2030,10 +2023,9 @@ bool test_cannot_open_multiple_writable_connections()
assert_readonly_connection_succeeds(protocolReadOnly));
// Try network connections too.
- TLSContext context;
BackupProtocolClient protocolWritable3(open_conn("localhost", context));
- assert_writable_connection_fails(protocolWritable3);
+ TEST_THAT(assert_writable_connection_fails(protocolWritable3));
BackupProtocolClient protocolReadOnly2(open_conn("localhost", context));
TEST_EQUAL(0x8732523ab23aLL,
@@ -2481,8 +2473,8 @@ bool test_housekeeping_deletes_files()
// First, things as they are now.
TEST_THAT_ABORTONFAIL(StartServer());
recursive_count_objects_results before = {0,0,0};
- recursive_count_objects("localhost", BACKUPSTORE_ROOT_DIRECTORY_ID, before);
-
+ recursive_count_objects(BACKUPSTORE_ROOT_DIRECTORY_ID, before);
+
TEST_EQUAL(0, before.objectsNotDel);
TEST_THAT(before.deleted != 0);
TEST_THAT(before.old != 0);
@@ -2493,31 +2485,12 @@ bool test_housekeeping_deletes_files()
// Reduce the store limits, so housekeeping will remove all old files.
// Leave the hard limit high, so we know that housekeeping's target
// for freeing space is the soft limit.
- TEST_THAT_ABORTONFAIL(::system(BBSTOREACCOUNTS
- " -c testfiles/bbstored.conf setlimit 01234567 "
- "10B 20000B") == 0);
- TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks");
-
- // Start things up
- TEST_THAT(StartServer());
-
- // wait for housekeeping to happen
- printf("waiting for housekeeping:\n");
- for(int l = 0; l < 30; ++l)
- {
- ::sleep(1);
- printf(".");
- fflush(stdout);
- }
- printf("\n");
+ TEST_THAT(change_account_limits("0B", "20000B"));
+ TEST_THAT(run_housekeeping_and_check_account());
// Count the objects again
recursive_count_objects_results after = {0,0,0};
- recursive_count_objects("localhost",
- BackupProtocolListDirectory::RootDirectory,
- after);
-
- // If these tests fail then try increasing the timeout above
+ recursive_count_objects(BACKUPSTORE_ROOT_DIRECTORY_ID, after);
TEST_EQUAL(before.objectsNotDel, after.objectsNotDel);
TEST_EQUAL(0, after.deleted);
TEST_EQUAL(0, after.old);
diff --git a/test/bbackupd/testbbackupd.cpp b/test/bbackupd/testbbackupd.cpp
index 12b22856..7dd1b2c5 100644
--- a/test/bbackupd/testbbackupd.cpp
+++ b/test/bbackupd/testbbackupd.cpp
@@ -768,35 +768,6 @@ int64_t SearchDir(BackupStoreDirectory& rDir,
return id;
}
-std::auto_ptr<BackupProtocolClient> Connect(TLSContext& rContext)
-{
- SocketStreamTLS* pConn = new SocketStreamTLS;
- std::auto_ptr<SocketStream> apConn(pConn);
- pConn->Open(rContext, Socket::TypeINET, "localhost", 22011);
-
- std::auto_ptr<BackupProtocolClient> client;
- client.reset(new BackupProtocolClient(apConn));
- client->Handshake();
- std::auto_ptr<BackupProtocolVersion>
- serverVersion(client->QueryVersion(
- BACKUP_STORE_SERVER_VERSION));
- if(serverVersion->GetVersion() !=
- BACKUP_STORE_SERVER_VERSION)
- {
- THROW_EXCEPTION(BackupStoreException,
- WrongServerVersion);
- }
- return client;
-}
-
-std::auto_ptr<BackupProtocolClient> ConnectAndLogin(TLSContext& rContext,
- int flags)
-{
- std::auto_ptr<BackupProtocolClient> client(Connect(rContext));
- client->QueryLogin(0x01234567, flags);
- return client;
-}
-
std::auto_ptr<BackupStoreDirectory> ReadDirectory
(
BackupProtocolCallable& rClient,
@@ -1077,9 +1048,23 @@ bool touch_and_wait(const std::string& filename)
return true;
}
+TLSContext context;
+
#define TEST_COMPARE(...) \
TEST_THAT(compare(BackupQueries::ReturnCode::__VA_ARGS__));
+bool search_for_file(const std::string& filename)
+{
+ std::auto_ptr<BackupProtocolCallable> client =
+ connect_and_login(context, BackupProtocolLogin::Flags_ReadOnly);
+
+ std::auto_ptr<BackupStoreDirectory> dir = ReadDirectory(*client);
+ int64_t testDirId = SearchDir(*dir, filename);
+ client->QueryFinished();
+
+ return (testDirId != 0);
+}
+
int test_bbackupd()
{
// First, wait for a normal period to make sure the last changes
@@ -1087,7 +1072,6 @@ int test_bbackupd()
// wait_for_backup_operation();
// Connection gubbins
- TLSContext context;
context.Initialise(false /* client */,
"testfiles/clientCerts.pem",
"testfiles/clientPrivKey.pem",
@@ -2188,15 +2172,7 @@ int test_bbackupd()
TEST_THAT(!TestFileExists("testfiles/notifyran.backup-finish.2"));
// Did it actually get created? Should not have been!
- std::auto_ptr<BackupProtocolCallable> client =
- connect_and_login(context,
- BackupProtocolLogin::Flags_ReadOnly);
-
- std::auto_ptr<BackupStoreDirectory> dir =
- ReadDirectory(*client);
- int64_t testDirId = SearchDir(*dir, "Test2");
- TEST_THAT(testDirId == 0);
- client->QueryFinished();
+ TEST_THAT_OR(!search_for_file("Test2"), FAIL);
}
// create the location directory and unpack some files into it
@@ -2216,20 +2192,7 @@ int test_bbackupd()
TEST_THAT( TestFileExists("testfiles/notifyran.backup-finish.2"));
TEST_THAT(!TestFileExists("testfiles/notifyran.backup-finish.3"));
- // BLOCK
- {
- std::auto_ptr<BackupProtocolCallable> client =
- connect_and_login(context,
- BackupProtocolLogin::Flags_ReadOnly);
-
- std::auto_ptr<BackupStoreDirectory> dir =
- ReadDirectory(*client,
- BackupProtocolListDirectory::RootDirectory);
- int64_t testDirId = SearchDir(*dir, "Test2");
- TEST_THAT(testDirId != 0);
-
- client->QueryFinished();
- }
+ TEST_THAT_OR(search_for_file("Test2"), FAIL);
printf("\n==== Testing that redundant locations are deleted on time\n");