[Box Backup-commit] COMMIT r3379 - in box/trunk: lib/backupstore test/backupstore test/bbackupd

subversion at boxbackup.org subversion at boxbackup.org
Thu Sep 4 02:36:16 BST 2014


Author: chris
Date: 2014-09-04 02:36:15 +0100 (Thu, 04 Sep 2014)
New Revision: 3379

Modified:
   box/trunk/lib/backupstore/StoreTestUtils.h
   box/trunk/test/backupstore/testbackupstore.cpp
   box/trunk/test/bbackupd/testbbackupd.cpp
Log:
Define setup and teardown functions and macros, and use them.

Merged back changes from the test refactor branch to reduce diffs.

Modified: box/trunk/lib/backupstore/StoreTestUtils.h
===================================================================
--- box/trunk/lib/backupstore/StoreTestUtils.h	2014-09-04 01:36:13 UTC (rev 3378)
+++ box/trunk/lib/backupstore/StoreTestUtils.h	2014-09-04 01:36:15 UTC (rev 3379)
@@ -17,9 +17,6 @@
 class SocketStreamTLS;
 class TLSContext;
 
-//! Simplifies calling setUp() with the current function name in each test.
-#define SETUP() if (!setUp(__FUNCTION__)) return true; // skip this test
-
 //! Holds the expected reference counts of each object.
 extern std::vector<uint32_t> ExpectedRefCounts;
 

Modified: box/trunk/test/backupstore/testbackupstore.cpp
===================================================================
--- box/trunk/test/backupstore/testbackupstore.cpp	2014-09-04 01:36:13 UTC (rev 3378)
+++ box/trunk/test/backupstore/testbackupstore.cpp	2014-09-04 01:36:15 UTC (rev 3379)
@@ -239,6 +239,23 @@
 	TEST_THAT(DIR_NUM == SkipEntries(e, FlagsMustBeSet, FlagsNotToBeSet));
 }
 
+//! Simplifies calling setUp() with the current function name in each test.
+#define SETUP() if (!setUp(__FUNCTION__)) return true; // skip this test
+
+//! Checks account for errors and shuts down daemons at end of every test.
+bool teardown_test_backupstore()
+{
+	bool status = tearDown();
+
+	if (FileExists("testfiles/0_0/backup/01234567/info.rf"))
+	{
+		TEST_THAT_OR(check_reference_counts(), status = false);
+		TEST_THAT_OR(check_account(), status = false);
+	}
+
+	return status;
+}
+
 bool test_filename_encoding()
 {
 	SETUP();
@@ -322,8 +339,7 @@
 		}
 	}
 
-	tearDown();
-	return true;
+	return teardown_test_backupstore();
 }
 
 bool test_backupstore_directory()
@@ -409,7 +425,7 @@
 		}
 	}
 
-	return tearDown();
+	return teardown_test_backupstore();
 }
 
 void write_test_file(int t)
@@ -656,6 +672,8 @@
 	}
 }
 
+TLSContext context;
+
 void recursive_count_objects(const char *hostname, int64_t id, recursive_count_objects_results &results)
 {
 	// Context
@@ -1096,9 +1114,8 @@
 	protocol.QueryFinished();
 	TEST_THAT(run_housekeeping_and_check_account());
 
-	ExpectedRefCounts.resize(3); // stop test failure in tearDown()
-	tearDown();
-	return true;
+	ExpectedRefCounts.resize(3); // stop test failure in teardown_test_backupstore()
+	return teardown_test_backupstore();
 }
 
 int64_t create_directory(BackupProtocolCallable& protocol, int64_t parent_dir_id)
@@ -1174,7 +1191,6 @@
 
 bool test_multiple_uploads()
 {
-	TLSContext context;
 	SETUP();
 	TEST_THAT_THROWONFAIL(StartServer());
 
@@ -1806,8 +1822,7 @@
 		apProtocol->QueryFinished();
 	}
 
-	tearDown();
-	return true;
+	return teardown_test_backupstore();
 }
 
 int get_object_size(BackupProtocolCallable& protocol, int64_t ObjectID,
@@ -1988,8 +2003,8 @@
 		BACKUPSTORE_ROOT_DIRECTORY_ID));
 
 	protocolReadOnly.QueryFinished();
-	tearDown();
-	return true;
+
+	return teardown_test_backupstore();
 }
 
 bool test_cannot_open_multiple_writable_connections()
@@ -2024,8 +2039,8 @@
 	TEST_EQUAL(0x8732523ab23aLL,
 		assert_readonly_connection_succeeds(protocolReadOnly2));
 
-	tearDown();
-	return true;
+	protocolWritable.QueryFinished();
+	return teardown_test_backupstore();
 }
 
 bool test_encoding()
@@ -2185,8 +2200,7 @@
 		}
 	}
 
-	tearDown();
-	return true;
+	return teardown_test_backupstore();
 }
 
 bool test_symlinks()
@@ -2213,7 +2227,7 @@
 			UNLINK_IF_EXISTS("testfiles/testsymlink_2");
 			BackupStoreFile::DecodeFile(b, "testfiles/testsymlink_2", IOStream::TimeOutInfinite);
 		}
-	tearDown();	
+	teardown_test_backupstore();	
 #endif
 
 	return true;
@@ -2270,12 +2284,9 @@
 		TEST_THAT(delfiles[1] == 4);
 	}
 
-	tearDown();
-	return true;
+	return teardown_test_backupstore();
 }
 
-TLSContext context;
-
 bool test_login_without_account()
 {
 	// First, try logging in without an account having been created... just make sure login fails.
@@ -2301,11 +2312,10 @@
 		protocol.QueryFinished();
 	}
 
-	// Recreate the account so that tearDown() doesn't freak out
+	// Recreate the account so that teardown_test_backupstore() doesn't freak out
 	// TEST_THAT_THROWONFAIL(create_account(10000, 20000));
 
-	tearDown();
-	return true;
+	return teardown_test_backupstore();
 }
 
 bool test_bbstoreaccounts_create()
@@ -2320,8 +2330,7 @@
 		"10000B 20000B") == 0);
 	TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks");
 
-	tearDown();
-	return true;
+	return teardown_test_backupstore();
 }
 
 bool test_bbstoreaccounts_delete()
@@ -2331,11 +2340,10 @@
 		" -c testfiles/bbstored.conf -Wwarning delete 01234567 yes") == 0);
 	TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks");
 
-	// Recreate the account so that tearDown() doesn't freak out
+	// Recreate the account so that teardown_test_backupstore() doesn't freak out
 	TEST_THAT_THROWONFAIL(create_account(10000, 20000));
 
-	tearDown();
-	return true;
+	return teardown_test_backupstore();
 }
 
 // Test that login fails on a disabled account 
@@ -2383,8 +2391,7 @@
 		protocol.QueryFinished();
 	}
 
-	tearDown();
-	return true;
+	return teardown_test_backupstore();
 }
 
 bool test_login_with_no_refcount_db()
@@ -2448,8 +2455,7 @@
 	run_housekeeping(account);
 	apReferences = BackupStoreRefCountDatabase::Load(account, true);
 
-	tearDown();
-	return true;
+	return teardown_test_backupstore();
 }
 
 bool test_housekeeping_deletes_files()
@@ -2517,16 +2523,15 @@
 	TEST_EQUAL(0, after.old);
 
 	// Adjust reference counts on deleted files, so that the final checks in
-	// tearDown() don't fail.
+	// teardown_test_backupstore() don't fail.
 	ExpectedRefCounts.resize(2);
 
-	// Delete the account to stop tearDown from checking it. TODO FIXME
-	// I'm aware of the block count mismatch that tearDown catches and
-	// will investigate.
+	// Delete the account to stop teardown_test_backupstore from checking it.
+	// TODO FIXME investigate the block count mismatch that teardown_test_backupstore
+	// catches if we don't delete the account.
 	delete_account();
 
-	tearDown();
-	return true;
+	return teardown_test_backupstore();
 }
 
 bool test_account_limits_respected()
@@ -2574,8 +2579,7 @@
 		protocol.QueryFinished();
 	}
 
-	tearDown();
-	return true;
+	return teardown_test_backupstore();
 }
 
 int multi_server()
@@ -2914,14 +2918,13 @@
 		"BackupStoreInfo::CreateForRegeneration and reloaded", info_v1,
 		*apInfo, "spurtle", false /* AccountEnabled */, extra_data);
 
-	// Delete the account to stop tearDown checking it for errors.
+	// Delete the account to stop teardown_test_backupstore checking it for errors.
 	apInfo.reset();
 	TEST_THAT_ABORTONFAIL(::system(BBSTOREACCOUNTS
 		" -c testfiles/bbstored.conf delete 01234567 yes") == 0);
 	TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks");
 
-	tearDown();
-	return true;
+	return teardown_test_backupstore();
 }
 
 int test(int argc, const char *argv[])

Modified: box/trunk/test/bbackupd/testbbackupd.cpp
===================================================================
--- box/trunk/test/bbackupd/testbbackupd.cpp	2014-09-04 01:36:13 UTC (rev 3378)
+++ box/trunk/test/bbackupd/testbbackupd.cpp	2014-09-04 01:36:15 UTC (rev 3379)
@@ -437,8 +437,48 @@
 	return true;
 }
 
+bool setup_test_bbackupd(BackupDaemon& bbackupd, bool do_unpack_files = true,
+	bool do_start_bbstored = true)
+{
+	Timers::Cleanup(false); // don't throw exception if not initialised
+	Timers::Init();
+
+	if (do_start_bbstored)
+	{
+		TEST_THAT_OR(StartServer(), FAIL);
+	}
+
+	if (do_unpack_files)
+	{
+		TEST_THAT_OR(unpack_files("test_base"), FAIL);
+	}
+
+	TEST_THAT_OR(configure_bbackupd(bbackupd, "testfiles/bbackupd.conf"),
+		FAIL);
+	spDaemon = &bbackupd;
+	return true;
+}
+
 int num_tests_selected = 0;
 
+//! Simplifies calling setUp() with the current function name in each test.
+#define SETUP() \
+	TEST_THAT(kill_running_daemons()); \
+	if (!setUp(__FUNCTION__)) return true; \
+	num_tests_selected++; \
+	int old_failure_count = failures;
+
+#define SETUP_WITHOUT_FILES() \
+	SETUP() \
+	BackupDaemon bbackupd; \
+	TEST_THAT_OR(setup_test_bbackupd(bbackupd, false), FAIL); \
+	TEST_THAT_OR(::mkdir("testfiles/TestDir1", 0755) == 0, FAIL);
+
+#define SETUP_WITH_BBSTORED() \
+	SETUP() \
+	BackupDaemon bbackupd; \
+	TEST_THAT_OR(setup_test_bbackupd(bbackupd), FAIL);
+
 //! Checks account for errors and shuts down daemons at end of every test.
 bool teardown_test_bbackupd(std::string test_name, int old_failure_count)
 {
@@ -461,8 +501,13 @@
 	return tearDown();
 }
 
+#define TEARDOWN() \
+	return teardown_test_bbackupd(__FUNCTION__, old_failure_count);
+
 bool test_basics()
 {
+	SETUP();
+
 	// Read attributes from files
 	BackupClientFileAttributes t1;
 	t1.ReadAttributes("testfiles/test1");
@@ -578,7 +623,7 @@
 	finish_with_write_xattr_test();
 #endif // HAVE_SYS_XATTR_H
 
-	return false;
+	TEARDOWN();
 }
 
 int64_t GetDirID(BackupProtocolCallable &protocol, const char *name, int64_t InDirectory)
@@ -3941,11 +3986,6 @@
 			"| ( cd testfiles && tar xf - )") == 0);
 	#endif
 
-	// Do the tests
-
-	int r = test_basics();
-	if(r != 0) return r;
-
 	{
 		std::string errs;
 		std::auto_ptr<Configuration> config(
@@ -3959,10 +3999,10 @@
 		rcontroller.Initialise(config->GetKeyValue("RaidFileConf").c_str());
 	}
 
-	r = (create_account(1000, 2000) ? 0 : 1);
-	if(r != 0) return r;
+	// Do the tests
+	TEST_THAT(test_basics());
 
-	r = (StartServer() ? 0 : 1);
+	int r = (StartServer() ? 0 : 1);
 	TEST_THAT(r == 0);
 	if(r != 0) return r;
 	




More information about the Boxbackup-commit mailing list