mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-01-18 04:58:51 +02:00
Update command/control and command/command tests to use standard patterns.
In the commandTest the HRN_STORAGE_REMOVE replacement uses .errorOnMissing when the code being tested added the file. The reason for this is 3 fold: 1. to ensure that an inadvertent typo in the path/file name does not go undetected, 2. to ensure that nothing else has removed the file prior to the call, and 3. consistency Also, added "stanza" to comment when a stanza stop file is removed vs an "all" stop file.
This commit is contained in:
parent
8e1807cdbe
commit
8bb0b28455
@ -144,6 +144,9 @@
|
||||
<commit subject="Update command/archive tests to use standard patterns.">
|
||||
<github-pull-request id="1449"/>
|
||||
</commit>
|
||||
<commit subject="Update command/control and command/command tests to use standard patterns.">
|
||||
<github-pull-request id="1456"/>
|
||||
</commit>
|
||||
|
||||
<release-item-contributor-list>
|
||||
<release-item-contributor id="cynthia.shang"/>
|
||||
|
@ -74,17 +74,19 @@ testRun(void)
|
||||
|
||||
TEST_RESULT_VOID(cmdBegin(), "command begin");
|
||||
|
||||
#define RESULT_OPTION \
|
||||
" --no-config --db-include=db1 --db-include=db2 --exec-id=1-test --pg1-path=/pg1 --pg2-path=/pg2" \
|
||||
" --recovery-option=standby_mode=on --recovery-option=primary_conninfo=blah --repo1-cipher-pass=<redacted>" \
|
||||
" --repo1-cipher-type=aes-256-cbc --reset-repo1-host --repo1-path=\"/path/to the/repo\" --stanza=test"
|
||||
|
||||
TEST_RESULT_LOG("P00 INFO: restore command begin " PROJECT_VERSION ":" RESULT_OPTION);
|
||||
TEST_RESULT_LOG(
|
||||
"P00 INFO: restore command begin " PROJECT_VERSION ": --no-config --db-include=db1 --db-include=db2 --exec-id=1-test"
|
||||
" --pg1-path=/pg1 --pg2-path=/pg2 --recovery-option=standby_mode=on --recovery-option=primary_conninfo=blah"
|
||||
" --repo1-cipher-pass=<redacted> --repo1-cipher-type=aes-256-cbc --reset-repo1-host --repo1-path=\"/path/to the/repo\""
|
||||
" --stanza=test");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("check options in cache");
|
||||
|
||||
TEST_RESULT_STR_Z(cmdOption(), RESULT_OPTION, "option cache");
|
||||
TEST_RESULT_STR_Z(
|
||||
cmdOption(), " --no-config --db-include=db1 --db-include=db2 --exec-id=1-test --pg1-path=/pg1 --pg2-path=/pg2"
|
||||
" --recovery-option=standby_mode=on --recovery-option=primary_conninfo=blah --repo1-cipher-pass=<redacted>"
|
||||
" --repo1-cipher-type=aes-256-cbc --reset-repo1-host --repo1-path=\"/path/to the/repo\" --stanza=test", "option cache");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("command begin does not log when level is too low");
|
||||
|
@ -3,6 +3,7 @@ Test Command Control
|
||||
***********************************************************************************************************************************/
|
||||
#include "common/harnessConfig.h"
|
||||
#include "common/harnessFork.h"
|
||||
#include "common/harnessStorage.h"
|
||||
#include "common/io/fdRead.h"
|
||||
#include "common/io/fdWrite.h"
|
||||
#include "storage/posix/storage.h"
|
||||
@ -23,12 +24,12 @@ testRun(void)
|
||||
{
|
||||
// Load configuration so lock path is set
|
||||
StringList *argList = strLstNew();
|
||||
strLstAddZ(argList, "--stanza=db");
|
||||
hrnCfgArgRawZ(argList, cfgOptStanza, "db");
|
||||
hrnCfgArgRawZ(argList, cfgOptPgPath, "/path/to/pg");
|
||||
HRN_CFG_LOAD(cfgCmdArchiveGet, argList);
|
||||
|
||||
TEST_RESULT_STR_Z(lockStopFileName(NULL), HRN_PATH "/lock/all" STOP_FILE_EXT, "stop file for all stanzas");
|
||||
TEST_RESULT_STR_Z(lockStopFileName(STRDEF("db")), HRN_PATH "/lock/db" STOP_FILE_EXT, "stop file for on stanza");
|
||||
TEST_RESULT_STR_Z(lockStopFileName(STRDEF("db")), HRN_PATH "/lock/db" STOP_FILE_EXT, "stop file for one stanza");
|
||||
}
|
||||
|
||||
// *****************************************************************************************************************************
|
||||
@ -37,112 +38,127 @@ testRun(void)
|
||||
StringList *argList = strLstNew();
|
||||
HRN_CFG_LOAD(cfgCmdStart, argList);
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("no stanza, no stop file");
|
||||
|
||||
TEST_RESULT_VOID(lockStopTest(), "no stop files without stanza");
|
||||
TEST_RESULT_VOID(cmdStart(), " cmdStart - no stanza, no stop files");
|
||||
TEST_RESULT_VOID(cmdStart(), "cmdStart - no stanza, no stop files");
|
||||
TEST_RESULT_LOG("P00 WARN: stop file does not exist");
|
||||
|
||||
TEST_RESULT_VOID(storagePutP(storageNewWriteP(hrnStorage, STRDEF("lock/all" STOP_FILE_EXT)), NULL), "create stop file");
|
||||
TEST_RESULT_VOID(cmdStart(), " cmdStart - no stanza, stop file exists");
|
||||
TEST_RESULT_BOOL(storageExistsP(hrnStorage, STRDEF("lock/all" STOP_FILE_EXT)), false, " stop file removed");
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("no stanza, stop file exists");
|
||||
|
||||
HRN_STORAGE_PUT_EMPTY(hrnStorage, "lock/all" STOP_FILE_EXT, .comment = "create stop file");
|
||||
TEST_RESULT_VOID(cmdStart(), "cmdStart - no stanza, stop file exists");
|
||||
TEST_STORAGE_LIST_EMPTY(hrnStorage, "lock", .comment = "stop file removed");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("stanza, no stop file");
|
||||
|
||||
argList = strLstNew();
|
||||
strLstAddZ(argList, "--stanza=db");
|
||||
hrnCfgArgRawZ(argList, cfgOptStanza, "db");
|
||||
HRN_CFG_LOAD(cfgCmdStart, argList);
|
||||
|
||||
TEST_RESULT_VOID(lockStopTest(), "no stop files with stanza");
|
||||
TEST_RESULT_VOID(cmdStart(), " cmdStart - stanza, no stop files");
|
||||
TEST_RESULT_VOID(cmdStart(), "cmdStart - stanza, no stop files");
|
||||
TEST_RESULT_LOG("P00 WARN: stop file does not exist for stanza db");
|
||||
|
||||
storagePutP(storageNewWriteP(hrnStorage, STRDEF("lock/all" STOP_FILE_EXT)), NULL);
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("stanza, stop file exists");
|
||||
|
||||
HRN_STORAGE_PUT_EMPTY(hrnStorage, "lock/all" STOP_FILE_EXT);
|
||||
TEST_ERROR(lockStopTest(), StopError, "stop file exists for all stanzas");
|
||||
|
||||
storagePutP(storageNewWriteP(hrnStorage, STRDEF("lock/db" STOP_FILE_EXT)), NULL);
|
||||
HRN_STORAGE_PUT_EMPTY(hrnStorage, "lock/db" STOP_FILE_EXT);
|
||||
TEST_ERROR(lockStopTest(), StopError, "stop file exists for stanza db");
|
||||
|
||||
TEST_RESULT_VOID(cmdStart(), "cmdStart - stanza, stop file exists");
|
||||
TEST_RESULT_BOOL(storageExistsP(hrnStorage, STRDEF("lock/db" STOP_FILE_EXT)), false, " stanza stop file removed");
|
||||
TEST_RESULT_BOOL(storageExistsP(hrnStorage, STRDEF("lock/all" STOP_FILE_EXT)), true, " all stop file not removed");
|
||||
TEST_STORAGE_LIST(hrnStorage, "lock", "all" STOP_FILE_EXT "\n", .comment = "only stanza stop file removed");
|
||||
}
|
||||
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("cmdStop()"))
|
||||
{
|
||||
const String *lockPath = STRDEF(HRN_PATH "/lock");
|
||||
StringList *argList = strLstNew();
|
||||
HRN_CFG_LOAD(cfgCmdStop, argList);
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("path/file info");
|
||||
|
||||
TEST_RESULT_VOID(cmdStop(), "no stanza, create stop file");
|
||||
StorageInfo info = {0};
|
||||
TEST_ASSIGN(info, storageInfoP(hrnStorage, lockPath), " get path info");
|
||||
TEST_RESULT_INT(info.mode, 0770, " check path mode");
|
||||
TEST_RESULT_BOOL(
|
||||
storageExistsP(hrnStorage, strNewFmt("%s/all" STOP_FILE_EXT, strZ(lockPath))), true, " all stop file created");
|
||||
TEST_ASSIGN(info, storageInfoP(hrnStorage, strNewFmt("%s/all" STOP_FILE_EXT, strZ(lockPath))), " get file info");
|
||||
TEST_RESULT_INT(info.mode, 0640, " check file mode");
|
||||
TEST_ASSIGN(info, storageInfoP(hrnStorage, STRDEF("lock")), "get path info");
|
||||
TEST_RESULT_INT(info.mode, 0770, "check path mode");
|
||||
TEST_STORAGE_EXISTS(hrnStorage, "lock/all" STOP_FILE_EXT, .comment = "all stop file created");
|
||||
TEST_ASSIGN(info, storageInfoP(hrnStorage, STRDEF("lock/all" STOP_FILE_EXT)), "get file info");
|
||||
TEST_RESULT_INT(info.mode, 0640, "check file mode");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("stop file already exists");
|
||||
|
||||
TEST_RESULT_VOID(cmdStop(), "no stanza, stop file already exists");
|
||||
TEST_RESULT_LOG("P00 WARN: stop file already exists for all stanzas");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_RESULT_VOID(storageRemoveP(hrnStorage, STRDEF("lockpath/all" STOP_FILE_EXT)), "remove stop file");
|
||||
HRN_SYSTEM_FMT("chmod 444 %s", strZ(lockPath));
|
||||
TEST_ERROR_FMT(
|
||||
cmdStop(), FileOpenError, "unable to get info for path/file '%s/all.stop': [13] Permission denied", strZ(lockPath));
|
||||
HRN_SYSTEM_FMT("chmod 700 %s", strZ(lockPath));
|
||||
TEST_RESULT_VOID(
|
||||
storagePathRemoveP(hrnStorage, lockPath, .recurse = true, .errorOnMissing = true), " remove the lock path");
|
||||
TEST_TITLE("stop file error");
|
||||
|
||||
HRN_STORAGE_REMOVE(hrnStorage, "lock/all" STOP_FILE_EXT, .errorOnMissing = true, .comment = "remove stop file");
|
||||
HRN_STORAGE_MODE(hrnStorage, "lock", .mode = 0444);
|
||||
TEST_ERROR(
|
||||
cmdStop(), FileOpenError, "unable to get info for path/file '" HRN_PATH "/lock/all.stop': [13] Permission denied");
|
||||
HRN_STORAGE_MODE(hrnStorage, "lock", .mode = 0700);
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
String *stanzaStopFile = strNewFmt("%s/db" STOP_FILE_EXT, strZ(lockPath));
|
||||
strLstAddZ(argList, "--stanza=db");
|
||||
TEST_TITLE("stanza stop file create");
|
||||
|
||||
hrnCfgArgRawZ(argList, cfgOptStanza, "db");
|
||||
HRN_CFG_LOAD(cfgCmdStop, argList);
|
||||
|
||||
HRN_STORAGE_PATH_REMOVE(hrnStorage, "lock", .recurse = true, .errorOnMissing = true, .comment = "remove the lock path");
|
||||
TEST_RESULT_VOID(cmdStop(), "stanza, create stop file");
|
||||
TEST_RESULT_BOOL(storageExistsP(hrnStorage, stanzaStopFile), true, " stanza stop file created");
|
||||
|
||||
StringList *lockPathList = NULL;
|
||||
TEST_ASSIGN(lockPathList, storageListP(hrnStorage, STRDEF("lock"), .errorOnMissing = true), " get file list");
|
||||
TEST_RESULT_INT(strLstSize(lockPathList), 1, " only file in lock path");
|
||||
TEST_RESULT_STR_Z(strLstGet(lockPathList, 0), "db" STOP_FILE_EXT, " stanza stop exists");
|
||||
TEST_STORAGE_LIST(
|
||||
hrnStorage, "lock", "db" STOP_FILE_EXT "\n",
|
||||
.comment = "lock path and file created, only stanza stop exists in lock path");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("stanza stop file already exists");
|
||||
|
||||
TEST_RESULT_VOID(cmdStop(), "stanza, stop file already exists");
|
||||
TEST_RESULT_LOG("P00 WARN: stop file already exists for stanza db");
|
||||
TEST_RESULT_VOID(storageRemoveP(hrnStorage, stanzaStopFile), " remove stop file");
|
||||
HRN_STORAGE_REMOVE(hrnStorage, "lock/db" STOP_FILE_EXT, .errorOnMissing = true, .comment = "remove stanza stop file");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
strLstAddZ(argList, "--force");
|
||||
TEST_TITLE("stanza stop file create with force");
|
||||
|
||||
hrnCfgArgRawBool(argList, cfgOptForce, true);
|
||||
HRN_CFG_LOAD(cfgCmdStop, argList);
|
||||
TEST_RESULT_VOID(cmdStop(), "stanza, create stop file, force");
|
||||
TEST_RESULT_VOID(storageRemoveP(hrnStorage, stanzaStopFile), " remove stop file");
|
||||
TEST_STORAGE_EXISTS(hrnStorage, "lock/db" STOP_FILE_EXT, .remove = true, .comment = "stanza stop file created, remove");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_RESULT_VOID(
|
||||
storagePutP(storageNewWriteP(hrnStorage, strNewFmt("%s/bad" LOCK_FILE_EXT, strZ(lockPath)), .modeFile = 0222), NULL),
|
||||
"create a lock file that cannot be opened");
|
||||
TEST_RESULT_VOID(cmdStop(), " stanza, create stop file but unable to open lock file");
|
||||
TEST_RESULT_LOG_FMT("P00 WARN: unable to open lock file %s/bad" LOCK_FILE_EXT, strZ(lockPath));
|
||||
TEST_RESULT_VOID(
|
||||
storagePathRemoveP(hrnStorage, lockPath, .recurse = true, .errorOnMissing = true), " remove the lock path");
|
||||
TEST_TITLE("unable to open lock file");
|
||||
|
||||
HRN_STORAGE_PUT_EMPTY(
|
||||
hrnStorage, "lock/bad" LOCK_FILE_EXT, .modeFile = 0222, .comment = "create a lock file that cannot be opened");
|
||||
TEST_RESULT_VOID(cmdStop(), "stanza, create stop file but unable to open lock file");
|
||||
TEST_STORAGE_EXISTS(hrnStorage, "lock/db" STOP_FILE_EXT, .comment = "stanza stop file created");
|
||||
TEST_RESULT_LOG("P00 WARN: unable to open lock file " HRN_PATH "/lock/bad" LOCK_FILE_EXT);
|
||||
HRN_STORAGE_PATH_REMOVE(hrnStorage, "lock", .recurse = true, .errorOnMissing = true, .comment = "remove the lock path");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_RESULT_VOID(
|
||||
storagePutP(storageNewWriteP(hrnStorage, strNewFmt("%s/empty" LOCK_FILE_EXT, strZ(lockPath))), NULL),
|
||||
"create empty lock file");
|
||||
TEST_RESULT_VOID(cmdStop(), " stanza, create stop file, force - empty lock file");
|
||||
TEST_RESULT_BOOL(storageExistsP(hrnStorage, stanzaStopFile), true, " stanza stop file created");
|
||||
TEST_RESULT_BOOL(
|
||||
storageExistsP(hrnStorage, strNewFmt("%s/empty" LOCK_FILE_EXT, strZ(lockPath))), false,
|
||||
" no other process lock, lock file was removed");
|
||||
TEST_TITLE("lock file removal");
|
||||
|
||||
HRN_STORAGE_PUT_EMPTY(hrnStorage, "lock/empty" LOCK_FILE_EXT, .comment = "create empty lock file");
|
||||
TEST_RESULT_VOID(cmdStop(), "stanza, create stop file, force - empty lock file");
|
||||
TEST_STORAGE_LIST(
|
||||
hrnStorage, "lock", "db" STOP_FILE_EXT "\n",
|
||||
.comment = "stanza stop file created, no other process lock, lock file was removed");
|
||||
|
||||
// empty lock file with another process lock, processId == NULL
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_RESULT_VOID(storageRemoveP(hrnStorage, stanzaStopFile), "remove stop file");
|
||||
TEST_RESULT_VOID(
|
||||
storagePutP(storageNewWriteP(hrnStorage, strNewFmt("%s/empty" LOCK_FILE_EXT, strZ(lockPath))), NULL),
|
||||
" create empty lock file");
|
||||
TEST_TITLE("empty lock file with another process lock, processId == NULL");
|
||||
|
||||
HRN_STORAGE_REMOVE(hrnStorage, "lock/db" STOP_FILE_EXT, .errorOnMissing = true, .comment = "remove stanza stop file");
|
||||
HRN_STORAGE_PUT_EMPTY(hrnStorage, "lock/empty" LOCK_FILE_EXT, .comment = "create empty lock file");
|
||||
|
||||
HARNESS_FORK_BEGIN()
|
||||
{
|
||||
@ -153,9 +169,9 @@ testRun(void)
|
||||
IoWrite *write = ioFdWriteNew(STRDEF("child write"), HARNESS_FORK_CHILD_WRITE(), 2000);
|
||||
ioWriteOpen(write);
|
||||
|
||||
int lockFd = open(strZ(strNewFmt("%s/empty" LOCK_FILE_EXT, strZ(lockPath))), O_RDONLY, 0);
|
||||
TEST_RESULT_BOOL(lockFd != -1, true, " file descriptor acquired");
|
||||
TEST_RESULT_INT(flock(lockFd, LOCK_EX | LOCK_NB), 0, " lock the empty file");
|
||||
int lockFd = open(HRN_PATH "/lock/empty" LOCK_FILE_EXT, O_RDONLY, 0);
|
||||
TEST_RESULT_BOOL(lockFd != -1, true, "file descriptor acquired");
|
||||
TEST_RESULT_INT(flock(lockFd, LOCK_EX | LOCK_NB), 0, "lock the empty file");
|
||||
|
||||
// Let the parent know the lock has been acquired and wait for the parent to allow lock release
|
||||
ioWriteStrLine(write, strNew());
|
||||
@ -180,11 +196,9 @@ testRun(void)
|
||||
ioReadLine(read);
|
||||
|
||||
TEST_RESULT_VOID(
|
||||
cmdStop(),
|
||||
" stanza, create stop file, force - empty lock file with another process lock, processId == NULL");
|
||||
TEST_RESULT_BOOL(
|
||||
storageExistsP(hrnStorage, strNewFmt("%s/empty" LOCK_FILE_EXT, strZ(lockPath))), false,
|
||||
" lock file was removed");
|
||||
cmdStop(), "stanza, create stop file, force - empty lock file with another process lock, processId == NULL");
|
||||
TEST_STORAGE_LIST(
|
||||
hrnStorage, "lock", "db" STOP_FILE_EXT "\n", .comment = "stop file created, lock file was removed");
|
||||
|
||||
// Notify the child to release the lock
|
||||
ioWriteLine(write, bufNew(0));
|
||||
@ -194,12 +208,11 @@ testRun(void)
|
||||
}
|
||||
HARNESS_FORK_END();
|
||||
|
||||
// not empty lock file with another process lock, processId size trimmed to 0
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_RESULT_VOID(storageRemoveP(hrnStorage, stanzaStopFile), "remove stop file");
|
||||
TEST_RESULT_VOID(
|
||||
storagePutP(storageNewWriteP(hrnStorage, strNewFmt("%s/empty" LOCK_FILE_EXT, strZ(lockPath))), BUFSTRDEF(" ")),
|
||||
" create non-empty lock file");
|
||||
TEST_TITLE("not empty lock file with another process lock, processId size trimmed to 0");
|
||||
|
||||
HRN_STORAGE_REMOVE(hrnStorage, "lock/db" STOP_FILE_EXT, .errorOnMissing = true, .comment = "remove stanza stop file");
|
||||
HRN_STORAGE_PUT_Z(hrnStorage, "lock/empty" LOCK_FILE_EXT, " ", .comment = "create non-empty lock file");
|
||||
|
||||
HARNESS_FORK_BEGIN()
|
||||
{
|
||||
@ -210,9 +223,9 @@ testRun(void)
|
||||
IoWrite *write = ioFdWriteNew(STRDEF("child write"), HARNESS_FORK_CHILD_WRITE(), 2000);
|
||||
ioWriteOpen(write);
|
||||
|
||||
int lockFd = open(strZ(strNewFmt("%s/empty" LOCK_FILE_EXT, strZ(lockPath))), O_RDONLY, 0);
|
||||
TEST_RESULT_BOOL(lockFd != -1, true, " file descriptor acquired");
|
||||
TEST_RESULT_INT(flock(lockFd, LOCK_EX | LOCK_NB), 0, " lock the non-empty file");
|
||||
int lockFd = open(HRN_PATH "/lock/empty" LOCK_FILE_EXT, O_RDONLY, 0);
|
||||
TEST_RESULT_BOOL(lockFd != -1, true, "file descriptor acquired");
|
||||
TEST_RESULT_INT(flock(lockFd, LOCK_EX | LOCK_NB), 0, "lock the non-empty file");
|
||||
|
||||
// Let the parent know the lock has been acquired and wait for the parent to allow lock release
|
||||
ioWriteStrLine(write, strNew());
|
||||
@ -237,10 +250,9 @@ testRun(void)
|
||||
ioReadLine(read);
|
||||
|
||||
TEST_RESULT_VOID(
|
||||
cmdStop(), " stanza, create stop file, force - empty lock file with another process lock, processId size 0");
|
||||
TEST_RESULT_BOOL(
|
||||
storageExistsP(hrnStorage, strNewFmt("%s/empty" LOCK_FILE_EXT, strZ(lockPath))), false,
|
||||
" lock file was removed");
|
||||
cmdStop(), "stanza, create stop file, force - empty lock file with another process lock, processId size 0");
|
||||
TEST_STORAGE_LIST(
|
||||
hrnStorage, "lock", "db" STOP_FILE_EXT "\n", .comment = "stop file created, lock file was removed");
|
||||
|
||||
// Notify the child to release the lock
|
||||
ioWriteLine(write, bufNew(0));
|
||||
@ -250,9 +262,10 @@ testRun(void)
|
||||
}
|
||||
HARNESS_FORK_END();
|
||||
|
||||
// lock file with another process lock, processId is valid
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_RESULT_VOID(storageRemoveP(hrnStorage, stanzaStopFile), "remove stop file");
|
||||
TEST_TITLE("lock file with another process lock, processId is valid");
|
||||
|
||||
HRN_STORAGE_REMOVE(hrnStorage, "lock/db" STOP_FILE_EXT, .errorOnMissing = true, .comment = "remove stanza stop file");
|
||||
HARNESS_FORK_BEGIN()
|
||||
{
|
||||
HARNESS_FORK_CHILD_BEGIN(0, true)
|
||||
@ -263,8 +276,8 @@ testRun(void)
|
||||
ioWriteOpen(write);
|
||||
|
||||
TEST_RESULT_BOOL(
|
||||
lockAcquire(lockPath, cfgOptionStr(cfgOptStanza), cfgOptionStr(cfgOptExecId), 0, 30000, true),
|
||||
true," child process acquires lock");
|
||||
lockAcquire(STRDEF(HRN_PATH "/lock"), cfgOptionStr(cfgOptStanza), cfgOptionStr(cfgOptExecId), 0, 30000, true),
|
||||
true, "child process acquires lock");
|
||||
|
||||
// Let the parent know the lock has been acquired and wait for the parent to allow lock release
|
||||
ioWriteStrLine(write, strNew());
|
||||
@ -286,8 +299,7 @@ testRun(void)
|
||||
ioReadLine(read);
|
||||
|
||||
TEST_RESULT_VOID(
|
||||
cmdStop(),
|
||||
" stanza, create stop file, force - lock file with another process lock, processId is valid");
|
||||
cmdStop(), "stanza, create stop file, force - lock file with another process lock, processId is valid");
|
||||
|
||||
TEST_RESULT_LOG_FMT("P00 INFO: sent term signal to process %d", HARNESS_FORK_PROCESS_ID(0));
|
||||
}
|
||||
@ -295,12 +307,11 @@ testRun(void)
|
||||
}
|
||||
HARNESS_FORK_END();
|
||||
|
||||
// lock file with another process lock, processId is invalid
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_RESULT_VOID(storageRemoveP(hrnStorage, stanzaStopFile), "remove stop file");
|
||||
TEST_RESULT_VOID(
|
||||
storagePutP(storageNewWriteP(hrnStorage, strNewFmt("%s/badpid" LOCK_FILE_EXT, strZ(lockPath))), BUFSTRDEF("-32768")),
|
||||
"create lock file with invalid PID");
|
||||
TEST_TITLE("lock file with another process lock, processId is invalid");
|
||||
|
||||
HRN_STORAGE_REMOVE(hrnStorage, "lock/db" STOP_FILE_EXT, .errorOnMissing = true, .comment = "remove stanza stop file");
|
||||
HRN_STORAGE_PUT_Z(hrnStorage, "lock/badpid" LOCK_FILE_EXT, "-32768", .comment = "create lock file with invalid PID");
|
||||
|
||||
HARNESS_FORK_BEGIN()
|
||||
{
|
||||
@ -311,9 +322,9 @@ testRun(void)
|
||||
IoWrite *write = ioFdWriteNew(STRDEF("child write"), HARNESS_FORK_CHILD_WRITE(), 2000);
|
||||
ioWriteOpen(write);
|
||||
|
||||
int lockFd = open(strZ(strNewFmt("%s/badpid" LOCK_FILE_EXT, strZ(lockPath))), O_RDONLY, 0);
|
||||
TEST_RESULT_BOOL(lockFd != -1, true, " file descriptor acquired");
|
||||
TEST_RESULT_INT(flock(lockFd, LOCK_EX | LOCK_NB), 0, " lock the badpid file");
|
||||
int lockFd = open(HRN_PATH "/lock/badpid" LOCK_FILE_EXT, O_RDONLY, 0);
|
||||
TEST_RESULT_BOOL(lockFd != -1, true, "file descriptor acquired");
|
||||
TEST_RESULT_INT(flock(lockFd, LOCK_EX | LOCK_NB), 0, "lock the badpid file");
|
||||
|
||||
// Let the parent know the lock has been acquired and wait for the parent to allow lock release
|
||||
ioWriteStrLine(write, strNew());
|
||||
@ -323,7 +334,7 @@ testRun(void)
|
||||
ioReadLine(read);
|
||||
|
||||
// Remove the file and close the file descriptor
|
||||
storageRemoveP(hrnStorage, strNewFmt("%s/badpid" LOCK_FILE_EXT, strZ(lockPath)));
|
||||
HRN_STORAGE_REMOVE(hrnStorage, "lock/badpid" LOCK_FILE_EXT);
|
||||
close(lockFd);
|
||||
}
|
||||
HARNESS_FORK_CHILD_END();
|
||||
@ -339,9 +350,9 @@ testRun(void)
|
||||
ioReadLine(read);
|
||||
|
||||
TEST_RESULT_VOID(
|
||||
cmdStop(), " stanza, create stop file, force - lock file with another process lock, processId is invalid");
|
||||
cmdStop(), "stanza, create stop file, force - lock file with another process lock, processId is invalid");
|
||||
TEST_RESULT_LOG("P00 WARN: unable to send term signal to process -32768");
|
||||
TEST_RESULT_BOOL(storageExistsP(hrnStorage, stanzaStopFile), true, " stanza stop file not removed");
|
||||
TEST_STORAGE_EXISTS(hrnStorage, "lock/db" STOP_FILE_EXT, .comment = "stanza stop file not removed");
|
||||
|
||||
// Notify the child to release the lock
|
||||
ioWriteLine(write, bufNew(0));
|
||||
|
Loading…
x
Reference in New Issue
Block a user