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

subversion at boxbackup.org subversion at boxbackup.org
Fri Oct 31 22:09:28 GMT 2014


Author: chris
Date: 2014-10-31 22:09:28 +0000 (Fri, 31 Oct 2014)
New Revision: 3413

Modified:
   box/trunk/lib/backupstore/StoreTestUtils.cpp
   box/trunk/lib/backupstore/StoreTestUtils.h
   box/trunk/test/backupstorefix/testbackupstorefix.cpp
   box/trunk/test/bbackupd/testbbackupd.cpp
Log:
Refactor StartClient and StopClient out of testbbackupd.

Use them in testbackupstorefix to reduce code duplication.

Modified: box/trunk/lib/backupstore/StoreTestUtils.cpp
===================================================================
--- box/trunk/lib/backupstore/StoreTestUtils.cpp	2014-09-18 20:29:01 UTC (rev 3412)
+++ box/trunk/lib/backupstore/StoreTestUtils.cpp	2014-10-31 22:09:28 UTC (rev 3413)
@@ -54,7 +54,7 @@
 }
 
 std::vector<uint32_t> ExpectedRefCounts;
-int bbstored_pid = 0;
+int bbstored_pid = 0, bbackupd_pid = 0;
 std::string OriginalWorkingDir;
 
 bool setUp(const char* function_name)
@@ -381,4 +381,50 @@
 	return true;
 }
 
+#define FAIL { \
+	/* \
+	std::ostringstream os; \
+	os << "failed at " << __FUNCTION__ << ":" << __LINE__; \
+	s_test_status[current_test_name] = os.str(); \
+	return fail(); \
+	*/ \
+	return false; \
+}
 
+bool StartClient(const std::string& bbackupd_conf_file)
+{
+	TEST_THAT_OR(bbackupd_pid == 0, FAIL);
+
+	std::string cmd = BBACKUPD " " + bbackupd_args + " " + bbackupd_conf_file;
+	bbackupd_pid = LaunchServer(cmd.c_str(), "testfiles/bbackupd.pid");
+
+	TEST_THAT_OR(bbackupd_pid != -1 && bbackupd_pid != 0, FAIL);
+	::sleep(1);
+	TEST_THAT_OR(ServerIsAlive(bbackupd_pid), FAIL);
+
+	return true;
+}
+
+bool StopClient(bool wait_for_process)
+{
+	TEST_THAT_OR(bbackupd_pid != 0, FAIL);
+	TEST_THAT_OR(ServerIsAlive(bbackupd_pid), FAIL);
+	TEST_THAT_OR(KillServer(bbackupd_pid, wait_for_process), FAIL);
+	::sleep(1);
+
+	TEST_THAT_OR(!ServerIsAlive(bbackupd_pid), FAIL);
+	bbackupd_pid = 0;
+
+	#ifdef WIN32
+		int unlink_result = unlink("testfiles/bbackupd.pid");
+		TEST_EQUAL_LINE(0, unlink_result, "unlink testfiles/bbackupd.pid");
+		if(unlink_result != 0)
+		{
+			FAIL;
+		}
+	#else
+		TestRemoteProcessMemLeaks("bbackupd.memleaks");
+	#endif
+
+	return true;
+}

Modified: box/trunk/lib/backupstore/StoreTestUtils.h
===================================================================
--- box/trunk/lib/backupstore/StoreTestUtils.h	2014-09-18 20:29:01 UTC (rev 3412)
+++ box/trunk/lib/backupstore/StoreTestUtils.h	2014-10-31 22:09:28 UTC (rev 3413)
@@ -21,7 +21,7 @@
 extern std::vector<uint32_t> ExpectedRefCounts;
 
 //! Holds the PID of the currently running bbstored test server.
-extern int bbstored_pid;
+extern int bbstored_pid, bbackupd_pid;
 
 //! Sets up (cleans up) test environment at the start of every test.
 bool setUp(const char* function_name);
@@ -80,6 +80,12 @@
 //! Stops the currently running bbstored test server.
 bool StopServer(bool wait_for_process = false);
 
+//! Starts the bbackupd client running, which must not already be running.
+bool StartClient(const std::string& bbackupd_conf_file = "testfiles/bbackupd.conf");
+
+//! Stops the currently running bbackupd client.
+bool StopClient(bool wait_for_process = false);
+
 //! Creates the standard test account, for example after delete_account().
 bool create_account(int soft, int hard);
 

Modified: box/trunk/test/backupstorefix/testbackupstorefix.cpp
===================================================================
--- box/trunk/test/backupstorefix/testbackupstorefix.cpp	2014-09-18 20:29:01 UTC (rev 3412)
+++ box/trunk/test/backupstorefix/testbackupstorefix.cpp	2014-10-31 22:09:28 UTC (rev 3413)
@@ -36,6 +36,7 @@
 #include "RaidFileWrite.h"
 #include "ServerControl.h"
 #include "StoreStructure.h"
+#include "StoreTestUtils.h"
 #include "ZeroStream.h"
 
 #include "MemLeakFindOn.h"
@@ -536,25 +537,9 @@
 		"raidfile is corrupted doesn't crash");
 
 	// Start the bbstored server
-	BOX_TRACE("  === Starting bbstored server: " BBSTORED 
-		" testfiles/bbstored.conf");
-	int bbstored_pid = LaunchServer(BBSTORED " testfiles/bbstored.conf", 
-		"testfiles/bbstored.pid");
-	TEST_THAT(bbstored_pid > 0);
-	if (bbstored_pid <= 0) return 1;
-	
-	::sleep(1);
-	TEST_THAT(ServerIsAlive(bbstored_pid));
+	TEST_THAT_OR(StartServer(), return 1);
+	TEST_THAT_OR(StartClient(), return 1);
 
-	std::string cmd = BBACKUPD " " + bbackupd_args +
-		" testfiles/bbackupd.conf";
-	int bbackupd_pid = LaunchServer(cmd, "testfiles/bbackupd.pid");
-	TEST_THAT(bbackupd_pid > 0);
-	if (bbackupd_pid <= 0) return 1;
-
-	::safe_sleep(1);
-	TEST_THAT(ServerIsAlive(bbackupd_pid));
-
 	// Wait 4 more seconds for the files to be old enough
 	// to upload
 	::safe_sleep(4);
@@ -563,13 +548,7 @@
 	::sync_and_wait();
 
 	// Stop bbackupd
-	#ifdef WIN32
-		terminate_bbackupd(bbackupd_pid);
-		// implicit check for memory leaks
-	#else
-		TEST_THAT(KillServer(bbackupd_pid));
-		TestRemoteProcessMemLeaks("bbackupd.memleaks");
-	#endif
+	TEST_THAT_OR(StopClient(), return 1);
 
 	BOX_INFO("  === Add a reference to a file that doesn't exist, check "
 		"that it's removed");
@@ -670,6 +649,10 @@
 	BOX_INFO("  === Delete an entry for an object from dir, change that "
 		"object to be a patch, check it's deleted");
 	{
+		// Temporarily stop the server, so it doesn't repair the
+		// refcount error
+		TEST_THAT(StopServer());
+
 		// Open dir and find entry
 		int64_t delID = getID("Test1/cannes/ict/metegoguered/oats");
 		{
@@ -749,10 +732,30 @@
 #endif // BOX_RELEASE_BUILD
 
 		// Fix it
-		RUN_CHECK_INTERNAL(4);
+		// ERROR:   Object 0x44 is unattached.
+		// ERROR:   BlocksUsed changed from 284 to 282
+		// ERROR:   BlocksInCurrentFiles changed from 228 to 226
+		// ERROR:   NumCurrentFiles changed from 114 to 113
+		// WARNING: Reference count of object 0x44 changed from 1 to 0
+		RUN_CHECK_INTERNAL(5);
+		{
+			std::auto_ptr<BackupProtocolAccountUsage2> usage =
+				BackupProtocolLocal2(0x01234567, "test",
+					"backup/01234567/", 0,
+					false).QueryGetAccountUsage2();
+			TEST_EQUAL(usage->GetNumCurrentFiles(), 113);
+			TEST_EQUAL(usage->GetNumDirectories(), 28);
+			TEST_EQUAL(usage->GetBlocksUsed(), 282);
+			TEST_EQUAL(usage->GetBlocksInCurrentFiles(), 226);
+			TEST_EQUAL(usage->GetBlocksInDirectories(), 56);
+		}
 
+		// Start the server again, so testbackupstorefix.pl can
+		// run bbackupquery which connects to it.
+		TEST_THAT(StartServer());
+
 		// Check
-		TEST_THAT(::system(PERL_EXECUTABLE 
+		TEST_THAT(::system(PERL_EXECUTABLE
 			" testfiles/testbackupstorefix.pl check 1") 
 			== 0);
 

Modified: box/trunk/test/bbackupd/testbbackupd.cpp
===================================================================
--- box/trunk/test/bbackupd/testbbackupd.cpp	2014-09-18 20:29:01 UTC (rev 3412)
+++ box/trunk/test/bbackupd/testbbackupd.cpp	2014-10-31 22:09:28 UTC (rev 3413)
@@ -107,46 +107,6 @@
 	wait_for_operation(TIME_TO_WAIT_FOR_BACKUP_OPERATION, message);
 }
 
-int bbackupd_pid = 0;
-
-bool StartClient(const std::string& bbackupd_conf_file = "testfiles/bbackupd.conf")
-{
-	TEST_THAT_OR(bbackupd_pid == 0, FAIL);
-
-	std::string cmd = BBACKUPD " " + bbackupd_args + " " + bbackupd_conf_file;
-	bbackupd_pid = LaunchServer(cmd.c_str(), "testfiles/bbackupd.pid");
-
-	TEST_THAT_OR(bbackupd_pid != -1 && bbackupd_pid != 0, FAIL);
-	::sleep(1);
-	TEST_THAT_OR(ServerIsAlive(bbackupd_pid), FAIL);
-
-	return true;
-}
-
-bool StopClient(bool wait_for_process = false)
-{
-	TEST_THAT_OR(bbackupd_pid != 0, FAIL);
-	TEST_THAT_OR(ServerIsAlive(bbackupd_pid), FAIL);
-	TEST_THAT_OR(KillServer(bbackupd_pid, wait_for_process), FAIL);
-	::sleep(1);
-
-	TEST_THAT_OR(!ServerIsAlive(bbackupd_pid), FAIL);
-	bbackupd_pid = 0;
-
-	#ifdef WIN32
-		int unlink_result = unlink("testfiles/bbackupd.pid");
-		TEST_EQUAL_LINE(0, unlink_result, "unlink testfiles/bbackupd.pid");
-		if(unlink_result != 0)
-		{
-			FAIL;
-		}
-	#else
-		TestRemoteProcessMemLeaks("bbackupd.memleaks");
-	#endif
-
-	return true;
-}
-
 #ifdef HAVE_SYS_XATTR_H
 bool readxattr_into_map(const char *filename, std::map<std::string,std::string> &rOutput)
 {




More information about the Boxbackup-commit mailing list