diff options
Diffstat (limited to 'test/backupstorepatch/testbackupstorepatch.cpp')
-rw-r--r-- | test/backupstorepatch/testbackupstorepatch.cpp | 66 |
1 files changed, 38 insertions, 28 deletions
diff --git a/test/backupstorepatch/testbackupstorepatch.cpp b/test/backupstorepatch/testbackupstorepatch.cpp index fab56523..46f278ad 100644 --- a/test/backupstorepatch/testbackupstorepatch.cpp +++ b/test/backupstorepatch/testbackupstorepatch.cpp @@ -22,6 +22,7 @@ #include "BackupStoreDirectory.h" #include "BackupStoreException.h" #include "BackupStoreFile.h" +#include "BackupStoreFileEncodeStream.h" #include "BackupStoreFilenameClear.h" #include "BackupStoreInfo.h" #include "BoxPortsAndFiles.h" @@ -73,6 +74,7 @@ int test_file_remove_order[] = {0, 2, 3, 5, 8, 1, 4, -1}; #define NUMBER_FILES ((sizeof(test_files) / sizeof(test_files[0]))) #define FIRST_FILE_SIZE (64*1024+3) #define BUFFER_SIZE (256*1024) +#define SHORT_TIMEOUT 5000 // Chunk of memory to use for copying files, etc static void *buffer = 0; @@ -193,7 +195,7 @@ void create_test_files() FileStream out(fnt, O_WRONLY | O_CREAT); // Copy up to the change point - int b = previous.Read(buffer, test_files[f].ChangePoint, IOStream::TimeOutInfinite); + int b = previous.Read(buffer, test_files[f].ChangePoint, SHORT_TIMEOUT); out.Write(buffer, b); // Add new bytes? @@ -208,7 +210,7 @@ void create_test_files() previous.Seek(test_files[f].DeleteBytes, IOStream::SeekType_Relative); } // Copy rest of data - b = previous.Read(buffer, BUFFER_SIZE, IOStream::TimeOutInfinite); + b = previous.Read(buffer, BUFFER_SIZE, SHORT_TIMEOUT); out.Write(buffer, b); } } @@ -244,7 +246,7 @@ void test_depends_in_dirs() // Load the directory back in BackupStoreDirectory dir2; FileStream in("testfiles/dir.1"); - dir2.ReadFromStream(in, IOStream::TimeOutInfinite); + dir2.ReadFromStream(in, SHORT_TIMEOUT); // Check entries TEST_THAT(dir2.GetNumberOfEntries() == 4); for(int i = 2; i <= 5; ++i) @@ -272,7 +274,7 @@ void test_depends_in_dirs() { BackupStoreDirectory dir3; FileStream in("testfiles/dir.2"); - dir3.ReadFromStream(in, IOStream::TimeOutInfinite); + dir3.ReadFromStream(in, SHORT_TIMEOUT); dir3.Dump(0, true); for(int i = 2; i <= 5; ++i) { @@ -344,12 +346,13 @@ int test(int argc, const char *argv[]) { // Open a connection to the server - SocketStreamTLS conn; - conn.Open(context, Socket::TypeINET, "localhost", + SocketStreamTLS *pConn = new SocketStreamTLS; + std::auto_ptr<SocketStream> apConn(pConn); + pConn->Open(context, Socket::TypeINET, "localhost", BOX_PORT_BBSTORED_TEST); // Make a protocol - BackupProtocolClient protocol(conn); + BackupProtocolClient protocol(apConn); // Login { @@ -370,7 +373,7 @@ int test(int argc, const char *argv[]) BackupProtocolListDirectory::RootDirectory, storeFilename)); std::auto_ptr<BackupProtocolSuccess> stored(protocol.QueryStoreFile( BackupProtocolListDirectory::RootDirectory, ModificationTime, - ModificationTime, 0 /* no diff from file ID */, storeFilename, *upload)); + ModificationTime, 0 /* no diff from file ID */, storeFilename, upload)); test_files[0].IDOnServer = stored->GetObjectID(); test_files[0].IsCompletelyDifferent = true; ModificationTime += MODIFICATION_TIME_INC; @@ -409,7 +412,8 @@ int test(int argc, const char *argv[]) // Upload the patch to the store std::auto_ptr<BackupProtocolSuccess> stored(protocol.QueryStoreFile( BackupProtocolListDirectory::RootDirectory, ModificationTime, - ModificationTime, isCompletelyDifferent?(0):(diffFromID), storeFilename, *patchStream)); + ModificationTime, isCompletelyDifferent?(0):(diffFromID), + storeFilename, patchStream)); ModificationTime += MODIFICATION_TIME_INC; // Store details @@ -439,7 +443,7 @@ int test(int argc, const char *argv[]) // Stream BackupStoreDirectory dir; std::auto_ptr<IOStream> dirstream(protocol.ReceiveStream()); - dir.ReadFromStream(*dirstream, IOStream::TimeOutInfinite); + dir.ReadFromStream(*dirstream, SHORT_TIMEOUT); BackupStoreDirectory::Iterator i(dir); BackupStoreDirectory::Entry *en = 0; @@ -452,7 +456,6 @@ int test(int argc, const char *argv[]) // Finish the connection protocol.QueryFinished(); - conn.Close(); } // Fill in initial dependency information @@ -480,7 +483,7 @@ int test(int argc, const char *argv[]) BackupStoreDirectory dir; { std::auto_ptr<RaidFileRead> dirStream(RaidFileRead::Open(0, "backup/01234567/o01")); - dir.ReadFromStream(*dirStream, IOStream::TimeOutInfinite); + dir.ReadFromStream(*dirStream, SHORT_TIMEOUT); dir.Dump(0, true); // Check that dependency info is correct @@ -501,9 +504,13 @@ int test(int argc, const char *argv[]) storeRootDir, discSet, filenameOut, false /* don't bother ensuring the directory exists */); - TEST_EQUAL(RaidFileUtil::NoFile, + std::ostringstream msg; + msg << "Unreferenced object " << + test_files[f].IDOnServer << + " was not deleted by housekeeping"; + TEST_EQUAL_LINE(RaidFileUtil::NoFile, RaidFileUtil::RaidFileExists( - rfd, filenameOut)); + rfd, filenameOut), msg.str()); } else { @@ -526,10 +533,11 @@ int test(int argc, const char *argv[]) } // Open a connection to the server (need to do this each time, otherwise housekeeping won't delete files) - SocketStreamTLS conn; - conn.Open(context, Socket::TypeINET, "localhost", + SocketStreamTLS *pConn = new SocketStreamTLS; + std::auto_ptr<SocketStream> apConn(pConn); + pConn->Open(context, Socket::TypeINET, "localhost", BOX_PORT_BBSTORED_TEST); - BackupProtocolClient protocol(conn); + BackupProtocolClient protocol(apConn); { std::auto_ptr<BackupProtocolVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION)); TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION); @@ -564,7 +572,7 @@ int test(int argc, const char *argv[]) // Get stream std::auto_ptr<IOStream> filestream(protocol.ReceiveStream()); // Get and decode - BackupStoreFile::DecodeFile(*filestream, filename_fetched, IOStream::TimeOutInfinite); + BackupStoreFile::DecodeFile(*filestream, filename_fetched, SHORT_TIMEOUT); } } // Test for identicalness @@ -575,13 +583,12 @@ int test(int argc, const char *argv[]) std::auto_ptr<BackupProtocolSuccess> getblockindex(protocol.QueryGetBlockIndexByID(test_files[f].IDOnServer)); TEST_THAT(getblockindex->GetObjectID() == test_files[f].IDOnServer); std::auto_ptr<IOStream> blockIndexStream(protocol.ReceiveStream()); - TEST_THAT(BackupStoreFile::CompareFileContentsAgainstBlockIndex(filename, *blockIndexStream, IOStream::TimeOutInfinite)); + TEST_THAT(BackupStoreFile::CompareFileContentsAgainstBlockIndex(filename, *blockIndexStream, SHORT_TIMEOUT)); } } // Close the connection protocol.QueryFinished(); - conn.Close(); // Mark one of the elements as deleted if(test_file_remove_order[deleteIndex] == -1) @@ -603,10 +610,13 @@ int test(int argc, const char *argv[]) writedir.Commit(true); } + // Get the revision number of the root directory, before housekeeping makes any changes. + int64_t first_revision = 0; + RaidFileRead::FileExists(0, "backup/01234567/o01", &first_revision); + #ifdef WIN32 - // Cannot signal bbstored to do housekeeping now, - // so just wait until we're sure it's done - wait_for_operation(12, "housekeeping to run"); + // Cannot signal bbstored to do housekeeping now, and we don't need to, as we will + // wait up to 32 seconds and detect automatically when it has finished. #else // Send the server a restart signal, so it does // housekeeping immediately, and wait for it to happen @@ -615,10 +625,8 @@ int test(int argc, const char *argv[]) ::kill(pid, SIGHUP); #endif - // Get the revision number of the info file - int64_t first_revision = 0; - RaidFileRead::FileExists(0, "backup/01234567/o01", &first_revision); - for(int l = 0; l < 32; ++l) + // Wait for changes to be written back to the root directory. + for(int secs_remaining = 32; secs_remaining >= 0; secs_remaining--) { // Sleep a while, and print a dot ::sleep(1); @@ -626,7 +634,7 @@ int test(int argc, const char *argv[]) ::fflush(stdout); // Early end? - if(l > 2) + if(!TestFileExists("testfiles/0_0/backup/01234567/write.lock")) { int64_t revid = 0; RaidFileRead::FileExists(0, "backup/01234567/o01", &revid); @@ -635,6 +643,8 @@ int test(int argc, const char *argv[]) break; } } + + TEST_LINE(secs_remaining != 0, "No changes detected to root directory after 32 seconds"); } ::printf("\n"); |