Skip to content

Commit

Permalink
Refactor Start/StopSimulator out of testbackupstore
Browse files Browse the repository at this point in the history
To enable reuse by testbackupstorepatch.

(cherry picked from commit 92d3f32)
  • Loading branch information
qris committed Jan 14, 2019
1 parent 254c099 commit 05b9202
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 19 deletions.
39 changes: 38 additions & 1 deletion lib/backupstore/StoreTestUtils.cpp
Expand Up @@ -54,7 +54,7 @@ bool delete_account()
}

std::vector<uint32_t> ExpectedRefCounts;
int bbstored_pid = 0, bbackupd_pid = 0;
int bbstored_pid = 0, bbackupd_pid = 0, s3simulator_pid = 0;

void set_refcount(int64_t ObjectID, uint32_t RefCount)
{
Expand Down Expand Up @@ -298,3 +298,40 @@ bool StopClient(bool wait_for_process)
return result;
}

bool StartSimulator()
{
s3simulator_pid = StartDaemon(s3simulator_pid,
"../../bin/s3simulator/s3simulator " + bbstored_args +
" testfiles/s3simulator.conf", "testfiles/s3simulator.pid");
return s3simulator_pid != 0;
}

bool StopSimulator()
{
bool result = StopDaemon(s3simulator_pid, "testfiles/s3simulator.pid",
"s3simulator.memleaks", true);
s3simulator_pid = 0;
return result;
}

bool kill_running_daemons()
{
bool success = true;

if(FileExists("testfiles/bbstored.pid"))
{
TEST_THAT_OR(KillServer("testfiles/bbstored.pid", true), success = false);
}

if(FileExists("testfiles/bbackupd.pid"))
{
TEST_THAT_OR(KillServer("testfiles/bbackupd.pid", true), success = false);
}

if(FileExists("testfiles/s3simulator.pid"))
{
TEST_THAT_OR(KillServer("testfiles/s3simulator.pid", true), success = false);
}

return success;
}
6 changes: 6 additions & 0 deletions lib/backupstore/StoreTestUtils.h
Expand Up @@ -77,6 +77,12 @@ bool StartClient(const std::string& bbackupd_conf_file = "testfiles/bbackupd.con
//! Stops the currently running bbackupd client.
bool StopClient(bool wait_for_process = false);

bool StartSimulator();

bool StopSimulator();

bool kill_running_daemons();

//! Creates the standard test account, for example after delete_account().
bool create_account(int soft, int hard);

Expand Down
4 changes: 4 additions & 0 deletions lib/common/Test.h
Expand Up @@ -32,6 +32,10 @@
#define TEST_RETURN(actual, expected) TEST_EQUAL((expected << 8), actual);
#endif

#define DEFAULT_BBSTORED_CONFIG_FILE "testfiles/bbstored.conf"
#define DEFAULT_BBACKUPD_CONFIG_FILE "testfiles/bbackupd.conf"
#define DEFAULT_S3_CACHE_DIR "testfiles/bbackupd-cache"

extern int num_failures;
extern int first_fail_line;
extern int num_tests_selected;
Expand Down
18 changes: 0 additions & 18 deletions test/bbackupd/testbbackupd.cpp
Expand Up @@ -96,7 +96,6 @@
#define TIME_TO_WAIT_FOR_BACKUP_OPERATION 12
#define SHORT_TIMEOUT 5000
#define BACKUP_ERROR_DELAY_SHORTENED 10
#define DEFAULT_BBACKUPD_CONFIG_FILE "testfiles/bbackupd.conf"

void wait_for_backup_operation(const char* message)
{
Expand Down Expand Up @@ -410,23 +409,6 @@ bool configure_bbackupd(BackupDaemon& bbackupd, const std::string& config_file)
return true;
}

bool kill_running_daemons()
{
bool success = true;

if(FileExists("testfiles/bbstored.pid"))
{
TEST_THAT_OR(KillServer("testfiles/bbstored.pid", true), success = false);
}

if(FileExists("testfiles/bbackupd.pid"))
{
TEST_THAT_OR(KillServer("testfiles/bbackupd.pid", true), success = false);
}

return success;
}

bool prepare_test_with_client_daemon(BackupDaemon& bbackupd, bool do_unpack_files = true,
bool do_start_bbstored = true)
{
Expand Down

0 comments on commit 05b9202

Please sign in to comment.