From 1a96f9545ee117bc3b02969a3791efcab73ce38a Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sun, 19 Nov 2017 21:54:14 +0000 Subject: [PATCH] Fix cleanup of backupstore specialised tests In case of exception, ensure that teardown code is always run, to release filesystem lock before deleting files in standard tearDown(). (cherry picked from commit 69f205bafe925548d799df13d01d2e8ea5e5e7bc) --- test/backupstore/testbackupstore.cpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/test/backupstore/testbackupstore.cpp b/test/backupstore/testbackupstore.cpp index 786afb127..6f1d1d142 100644 --- a/test/backupstore/testbackupstore.cpp +++ b/test/backupstore/testbackupstore.cpp @@ -219,7 +219,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() @@ -258,13 +260,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