/*********************************************************************************************************************************** Test Run ***********************************************************************************************************************************/ void testRun(void) { FUNCTION_HARNESS_VOID(); // Create default storage object for testing Storage *storageTest = storagePosixNew( strNew(testPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL); // ***************************************************************************************************************************** if (testBegin("lockStopFileName()")) { // Load configuration so lock path is set StringList *argList = strLstNew(); strLstAddZ(argList, "pgbackrest"); strLstAddZ(argList, "--stanza=db"); strLstAddZ(argList, "--lock-path=/path/to/lock"); strLstAddZ(argList, "archive-get"); harnessCfgLoad(strLstSize(argList), strLstPtr(argList)); TEST_RESULT_STR(strPtr(lockStopFileName(NULL)), "/path/to/lock/all.stop", "stop file for all stanzas"); TEST_RESULT_STR(strPtr(lockStopFileName(strNew("db"))), "/path/to/lock/db.stop", "stop file for on stanza"); } // ***************************************************************************************************************************** if (testBegin("lockStopTest()")) { StringList *argList = strLstNew(); strLstAddZ(argList, "pgbackrest"); strLstAdd(argList, strNewFmt("--lock-path=%s", testPath())); strLstAddZ(argList, "start"); harnessCfgLoad(strLstSize(argList), strLstPtr(argList)); TEST_RESULT_VOID(lockStopTest(), "no stop files without stanza"); // ------------------------------------------------------------------------------------------------------------------------- argList = strLstNew(); strLstAddZ(argList, "pgbackrest"); strLstAddZ(argList, "--stanza=db"); strLstAdd(argList, strNewFmt("--lock-path=%s", testPath())); strLstAddZ(argList, "start"); harnessCfgLoad(strLstSize(argList), strLstPtr(argList)); TEST_RESULT_VOID(lockStopTest(), "no stop files with stanza"); storagePutNP(storageNewWriteNP(storageTest, strNew("all.stop")), NULL); TEST_ERROR(lockStopTest(), StopError, "stop file exists for all stanzas"); storagePutNP(storageNewWriteNP(storageTest, strNew("db.stop")), NULL); TEST_ERROR(lockStopTest(), StopError, "stop file exists for stanza db"); } FUNCTION_HARNESS_RESULT_VOID(); }
/*********************************************************************************************************************************** Test for the existence of a stop file ***********************************************************************************************************************************/ void lockStopTest(void) { FUNCTION_LOG_VOID(logLevelDebug); MEM_CONTEXT_TEMP_BEGIN() { // Check the current stanza (if any) if (cfgOptionTest(cfgOptStanza)) { if (storageExistsNP(storageLocal(), lockStopFileName(cfgOptionStr(cfgOptStanza)))) THROW_FMT(StopError, "stop file exists for stanza %s", strPtr(cfgOptionStr(cfgOptStanza))); } // Check all stanzas if (storageExistsNP(storageLocal(), lockStopFileName(NULL))) THROW(StopError, "stop file exists for all stanzas"); } MEM_CONTEXT_TEMP_END(); FUNCTION_LOG_RETURN_VOID(); }