Skip to content

Commit

Permalink
Fix cleanup of backupstore specialised tests
Browse files Browse the repository at this point in the history
In case of exception, ensure that teardown code is always run, to release
filesystem lock before deleting files in standard tearDown().
  • Loading branch information
qris committed Nov 20, 2017
1 parent 6ef8e5b commit 65df260
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions test/backupstore/testbackupstore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ bool setup_test_backupstore_specialised(const std::string& spec_name,

#define SETUP_TEST_BACKUPSTORE_SPECIALISED(name, control) \
SETUP_SPECIALISED(name); \
TEST_THAT_OR(setup_test_backupstore_specialised(name, control), FAIL);
TEST_THAT_OR(setup_test_backupstore_specialised(name, control), FAIL); \
try \
{ // left open for TEARDOWN_TEST_BACKUPSTORE_SPECIALISED()

//! Checks account for errors and shuts down daemons at end of every test.
bool teardown_test_backupstore()
Expand Down Expand Up @@ -264,13 +266,25 @@ bool teardown_test_backupstore_specialised(const std::string& spec_name,
}

#define TEARDOWN_TEST_BACKUPSTORE_SPECIALISED(name, control) \
if (ServerIsAlive(bbstored_pid)) \
StopServer(); \
if(control.GetCurrentFileSystem() != NULL) \
if (ServerIsAlive(bbstored_pid)) \
StopServer(); \
if(control.GetCurrentFileSystem() != NULL) \
{ \
control.GetCurrentFileSystem()->ReleaseLock(); \
} \
TEST_THAT_OR(teardown_test_backupstore_specialised(name, control), FAIL); \
} \
catch (BoxException &e) \
{ \
control.GetCurrentFileSystem()->ReleaseLock(); \
if (ServerIsAlive(bbstored_pid)) \
StopServer(); \
if(control.GetCurrentFileSystem() != NULL) \
{ \
control.GetCurrentFileSystem()->ReleaseLock(); \
} \
TEST_THAT_OR(teardown_test_backupstore_specialised(name, control), FAIL); \
throw; \
} \
TEST_THAT_OR(teardown_test_backupstore_specialised(name, control), FAIL); \
TEARDOWN();

// Nice random data for testing written files
Expand Down

0 comments on commit 65df260

Please sign in to comment.