You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-13 01:00:23 +02:00
91 lines
5.0 KiB
C
91 lines
5.0 KiB
C
![]() |
/***********************************************************************************************************************************
|
||
|
Test Archive Common
|
||
|
***********************************************************************************************************************************/
|
||
|
#include <unistd.h>
|
||
|
|
||
|
#include "common/harnessConfig.h"
|
||
|
|
||
|
/***********************************************************************************************************************************
|
||
|
Test Run
|
||
|
***********************************************************************************************************************************/
|
||
|
void
|
||
|
testRun()
|
||
|
{
|
||
|
// *****************************************************************************************************************************
|
||
|
if (testBegin("archiveAsyncStatus()"))
|
||
|
{
|
||
|
StringList *argList = strLstNew();
|
||
|
strLstAddZ(argList, "pgbackrest");
|
||
|
strLstAdd(argList, strNewFmt("--spool-path=%s", testPath()));
|
||
|
strLstAddZ(argList, "--archive-async");
|
||
|
strLstAddZ(argList, "--archive-timeout=1");
|
||
|
strLstAddZ(argList, "--stanza=db");
|
||
|
strLstAddZ(argList, "archive-push");
|
||
|
harnessCfgLoad(strLstSize(argList), strLstPtr(argList));
|
||
|
|
||
|
// -------------------------------------------------------------------------------------------------------------------------
|
||
|
String *segment = strNew("000000010000000100000001");
|
||
|
|
||
|
TEST_RESULT_BOOL(archiveAsyncStatus(segment, false), false, "directory and status file not present");
|
||
|
|
||
|
// -------------------------------------------------------------------------------------------------------------------------
|
||
|
mkdir(strPtr(strNewFmt("%s/archive", testPath())), 0750);
|
||
|
mkdir(strPtr(strNewFmt("%s/archive/db", testPath())), 0750);
|
||
|
mkdir(strPtr(strNewFmt("%s/archive/db/out", testPath())), 0750);
|
||
|
|
||
|
TEST_RESULT_BOOL(archiveAsyncStatus(segment, false), false, "status file not present");
|
||
|
|
||
|
// -------------------------------------------------------------------------------------------------------------------------
|
||
|
storagePutNP(
|
||
|
storageNewWriteNP(storageSpool(), strNewFmt(STORAGE_SPOOL_ARCHIVE_OUT "/%s.ok", strPtr(segment))),
|
||
|
bufNewStr(strNew(BOGUS_STR)));
|
||
|
TEST_ERROR(
|
||
|
archiveAsyncStatus(segment, false), FormatError, "000000010000000100000001.ok content must have at least two lines");
|
||
|
|
||
|
storagePutNP(
|
||
|
storageNewWriteNP(storageSpool(), strNewFmt(STORAGE_SPOOL_ARCHIVE_OUT "/%s.ok", strPtr(segment))),
|
||
|
bufNewStr(strNew(BOGUS_STR "\n")));
|
||
|
TEST_ERROR(archiveAsyncStatus(segment, false), FormatError, "000000010000000100000001.ok message must be > 0");
|
||
|
|
||
|
storagePutNP(
|
||
|
storageNewWriteNP(storageSpool(), strNewFmt(STORAGE_SPOOL_ARCHIVE_OUT "/%s.ok", strPtr(segment))),
|
||
|
bufNewStr(strNew(BOGUS_STR "\nmessage")));
|
||
|
TEST_ERROR(archiveAsyncStatus(segment, false), FormatError, "unable to convert str 'BOGUS' to int");
|
||
|
|
||
|
storagePutNP(
|
||
|
storageNewWriteNP(storageSpool(), strNewFmt(STORAGE_SPOOL_ARCHIVE_OUT "/%s.ok", strPtr(segment))),
|
||
|
bufNewStr(strNew("0\nwarning")));
|
||
|
TEST_RESULT_BOOL(archiveAsyncStatus(segment, false), true, "ok file with warning");
|
||
|
testLogResult("P00 WARN: warning");
|
||
|
|
||
|
storagePutNP(
|
||
|
storageNewWriteNP(storageSpool(), strNewFmt(STORAGE_SPOOL_ARCHIVE_OUT "/%s.ok", strPtr(segment))),
|
||
|
bufNewStr(strNew("25\nerror")));
|
||
|
TEST_RESULT_BOOL(archiveAsyncStatus(segment, false), true, "error status renamed to ok");
|
||
|
testLogResult(
|
||
|
"P00 WARN: WAL segment '000000010000000100000001' was not pushed due to error [25] and was manually skipped: error");
|
||
|
|
||
|
// -------------------------------------------------------------------------------------------------------------------------
|
||
|
storagePutNP(
|
||
|
storageNewWriteNP(storageSpool(), strNewFmt(STORAGE_SPOOL_ARCHIVE_OUT "/%s.error", strPtr(segment))),
|
||
|
bufNewStr(strNew("")));
|
||
|
TEST_ERROR(
|
||
|
archiveAsyncStatus(segment, false), AssertError,
|
||
|
strPtr(
|
||
|
strNewFmt(
|
||
|
"multiple status files found in '%s/archive/db/out' for WAL segment '000000010000000100000001'", testPath())));
|
||
|
|
||
|
unlink(strPtr(storagePathNP(storageSpool(), strNewFmt(STORAGE_SPOOL_ARCHIVE_OUT "/%s.ok", strPtr(segment)))));
|
||
|
TEST_ERROR(archiveAsyncStatus(segment, true), AssertError, "status file '000000010000000100000001.error' has no content");
|
||
|
|
||
|
storagePutNP(
|
||
|
storageNewWriteNP(storageSpool(), strNewFmt(STORAGE_SPOOL_ARCHIVE_OUT "/%s.error", strPtr(segment))),
|
||
|
bufNewStr(strNew("25\nmessage")));
|
||
|
TEST_ERROR(archiveAsyncStatus(segment, true), AssertError, "message");
|
||
|
|
||
|
TEST_RESULT_BOOL(archiveAsyncStatus(segment, false), false, "suppress error");
|
||
|
|
||
|
unlink(strPtr(storagePathNP(storageSpool(), strNewFmt(STORAGE_SPOOL_ARCHIVE_OUT "/%s.error", strPtr(segment)))));
|
||
|
}
|
||
|
}
|