You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-13 01:00:23 +02:00
Add local process shim to archive-get/archive-push unit tests.
Use the local process shim introduced in ef63750e
in the archive-get/archive-push unit tests.
This commit is contained in:
@ -210,6 +210,7 @@
|
|||||||
<commit subject="Add log shim."/>
|
<commit subject="Add log shim."/>
|
||||||
<commit subject="Fix shims with more than one function."/>
|
<commit subject="Fix shims with more than one function."/>
|
||||||
<commit subject="Protocol shim improvements."/>
|
<commit subject="Protocol shim improvements."/>
|
||||||
|
<commit subject="Add local process shim to archive-get/archive-push unit tests."/>
|
||||||
|
|
||||||
<p>Add local processs shim.</p>
|
<p>Add local processs shim.</p>
|
||||||
</release-item>
|
</release-item>
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
Test Archive Get Command
|
Test Archive Get Command
|
||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
#include "common/compress/helper.h"
|
#include "common/compress/helper.h"
|
||||||
#include "common/io/bufferRead.h"
|
|
||||||
#include "common/io/bufferWrite.h"
|
|
||||||
#include "common/io/fdRead.h"
|
#include "common/io/fdRead.h"
|
||||||
#include "common/io/fdWrite.h"
|
#include "common/io/fdWrite.h"
|
||||||
#include "postgres/interface.h"
|
#include "postgres/interface.h"
|
||||||
@ -14,6 +12,7 @@ Test Archive Get Command
|
|||||||
#include "common/harnessFork.h"
|
#include "common/harnessFork.h"
|
||||||
#include "common/harnessInfo.h"
|
#include "common/harnessInfo.h"
|
||||||
#include "common/harnessPostgres.h"
|
#include "common/harnessPostgres.h"
|
||||||
|
#include "common/harnessProtocol.h"
|
||||||
#include "common/harnessStorage.h"
|
#include "common/harnessStorage.h"
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
@ -107,6 +106,10 @@ testRun(void)
|
|||||||
{
|
{
|
||||||
harnessLogLevelSet(logLevelDetail);
|
harnessLogLevelSet(logLevelDetail);
|
||||||
|
|
||||||
|
// Install local command handler shim
|
||||||
|
static const ProtocolServerHandler testLocalHandlerList[] = {PROTOCOL_SERVER_HANDLER_ARCHIVE_GET_LIST};
|
||||||
|
hrnProtocolLocalShimInstall(testLocalHandlerList, PROTOCOL_SERVER_HANDLER_LIST_SIZE(testLocalHandlerList));
|
||||||
|
|
||||||
// Arguments that must be included
|
// Arguments that must be included
|
||||||
StringList *argBaseList = strLstNew();
|
StringList *argBaseList = strLstNew();
|
||||||
hrnCfgArgRawZ(argBaseList, cfgOptPgPath, TEST_PATH_PG);
|
hrnCfgArgRawZ(argBaseList, cfgOptPgPath, TEST_PATH_PG);
|
||||||
@ -203,14 +206,14 @@ testRun(void)
|
|||||||
|
|
||||||
TEST_RESULT_LOG(
|
TEST_RESULT_LOG(
|
||||||
"P00 INFO: get 1 WAL file(s) from archive: 000000010000000100000001\n"
|
"P00 INFO: get 1 WAL file(s) from archive: 000000010000000100000001\n"
|
||||||
"P01 WARN: [FileReadError] raised from local-1 protocol: unable to get 000000010000000100000001:\n"
|
"P01 WARN: [FileReadError] raised from local-1 shim protocol: unable to get 000000010000000100000001:\n"
|
||||||
" repo1: 10-1/0000000100000001/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz"
|
" repo1: 10-1/0000000100000001/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz"
|
||||||
" [FormatError] unexpected eof in compressed data");
|
" [FormatError] unexpected eof in compressed data");
|
||||||
|
|
||||||
TEST_STORAGE_GET(
|
TEST_STORAGE_GET(
|
||||||
storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000100000001.error",
|
storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000100000001.error",
|
||||||
"42\n"
|
"42\n"
|
||||||
"raised from local-1 protocol: unable to get 000000010000000100000001:\n"
|
"raised from local-1 shim protocol: unable to get 000000010000000100000001:\n"
|
||||||
"repo1: 10-1/0000000100000001/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz [FormatError]"
|
"repo1: 10-1/0000000100000001/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz [FormatError]"
|
||||||
" unexpected eof in compressed data",
|
" unexpected eof in compressed data",
|
||||||
.remove = true);
|
.remove = true);
|
||||||
@ -515,14 +518,14 @@ testRun(void)
|
|||||||
TEST_RESULT_LOG(
|
TEST_RESULT_LOG(
|
||||||
"P00 INFO: get 1 WAL file(s) from archive: 000000010000000200000000\n"
|
"P00 INFO: get 1 WAL file(s) from archive: 000000010000000200000000\n"
|
||||||
"P00 WARN: " TEST_WARN1 "\n"
|
"P00 WARN: " TEST_WARN1 "\n"
|
||||||
"P01 WARN: [FileReadError] raised from local-1 protocol: unable to get 000000010000000200000000:\n"
|
"P01 WARN: [FileReadError] raised from local-1 shim protocol: unable to get 000000010000000200000000:\n"
|
||||||
" " TEST_WARN2 "\n"
|
" " TEST_WARN2 "\n"
|
||||||
" " TEST_WARN3);
|
" " TEST_WARN3);
|
||||||
|
|
||||||
TEST_STORAGE_GET(
|
TEST_STORAGE_GET(
|
||||||
storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000200000000.error",
|
storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000200000000.error",
|
||||||
"42\n"
|
"42\n"
|
||||||
"raised from local-1 protocol: unable to get 000000010000000200000000:\n"
|
"raised from local-1 shim protocol: unable to get 000000010000000200000000:\n"
|
||||||
TEST_WARN2 "\n"
|
TEST_WARN2 "\n"
|
||||||
TEST_WARN3 "\n"
|
TEST_WARN3 "\n"
|
||||||
TEST_WARN1,
|
TEST_WARN1,
|
||||||
@ -533,6 +536,9 @@ testRun(void)
|
|||||||
// -------------------------------------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------------------------------------
|
||||||
TEST_TITLE("global error on invalid executable");
|
TEST_TITLE("global error on invalid executable");
|
||||||
|
|
||||||
|
// Uninstall local command handler shim
|
||||||
|
hrnProtocolLocalShimUninstall();
|
||||||
|
|
||||||
argList = strLstNew();
|
argList = strLstNew();
|
||||||
strLstAddZ(argList, "pgbackrest-bogus");
|
strLstAddZ(argList, "pgbackrest-bogus");
|
||||||
hrnCfgArgRawZ(argList, cfgOptPgPath, TEST_PATH_PG);
|
hrnCfgArgRawZ(argList, cfgOptPgPath, TEST_PATH_PG);
|
||||||
@ -1072,42 +1078,6 @@ testRun(void)
|
|||||||
TEST_RESULT_LOG(
|
TEST_RESULT_LOG(
|
||||||
"P00 INFO: found 01ABCDEF01ABCDEF01ABCDEF in the repo2: 10-1 archive");
|
"P00 INFO: found 01ABCDEF01ABCDEF01ABCDEF in the repo2: 10-1 archive");
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------------------------------------------
|
|
||||||
TEST_TITLE("call protocol function directly");
|
|
||||||
|
|
||||||
// Start a protocol server
|
|
||||||
Buffer *serverWrite = bufNew(8192);
|
|
||||||
IoWrite *serverWriteIo = ioBufferWriteNew(serverWrite);
|
|
||||||
ioWriteOpen(serverWriteIo);
|
|
||||||
|
|
||||||
ProtocolServer *server = protocolServerNew(STRDEF("test"), STRDEF("test"), ioBufferReadNew(bufNew(0)), serverWriteIo);
|
|
||||||
bufUsedSet(serverWrite, 0);
|
|
||||||
|
|
||||||
// Add archive-async and spool path
|
|
||||||
hrnCfgArgRawZ(argList, cfgOptSpoolPath, TEST_PATH_SPOOL);
|
|
||||||
hrnCfgArgRawBool(argList, cfgOptArchiveAsync, true);
|
|
||||||
hrnCfgEnvKeyRawZ(cfgOptRepoCipherPass, 2, TEST_CIPHER_PASS);
|
|
||||||
harnessCfgLoadRole(cfgCmdArchiveGet, cfgCmdRoleLocal, argList);
|
|
||||||
hrnCfgEnvKeyRemoveRaw(cfgOptRepoCipherPass, 2);
|
|
||||||
|
|
||||||
// Setup protocol command
|
|
||||||
VariantList *paramList = varLstNew();
|
|
||||||
varLstAdd(paramList, varNewStrZ("01ABCDEF01ABCDEF01ABCDEF"));
|
|
||||||
varLstAdd(
|
|
||||||
paramList, varNewStrZ("10-1/01ABCDEF01ABCDEF/01ABCDEF01ABCDEF01ABCDEF-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.gz"));
|
|
||||||
varLstAdd(paramList, varNewUInt(1));
|
|
||||||
varLstAdd(paramList, varNewStrZ("10-1"));
|
|
||||||
varLstAdd(paramList, varNewUInt64(cipherTypeAes256Cbc));
|
|
||||||
varLstAdd(paramList, varNewStrZ(TEST_CIPHER_PASS_ARCHIVE));
|
|
||||||
|
|
||||||
TEST_RESULT_VOID(archiveGetFileProtocol(paramList, server), "protocol archive get");
|
|
||||||
|
|
||||||
TEST_RESULT_STR_Z(strNewBuf(serverWrite), "{\"out\":[0,[]]}\n", "check result");
|
|
||||||
TEST_STORAGE_LIST(
|
|
||||||
storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN, "01ABCDEF01ABCDEF01ABCDEF.pgbackrest.tmp\n", .remove = true);
|
|
||||||
|
|
||||||
bufUsedSet(serverWrite, 0);
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------------------------------------
|
||||||
TEST_TITLE("no segments to find with existing ok file");
|
TEST_TITLE("no segments to find with existing ok file");
|
||||||
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
Test Archive Push Command
|
Test Archive Push Command
|
||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
#include "common/io/bufferRead.h"
|
|
||||||
#include "common/io/bufferWrite.h"
|
|
||||||
#include "common/io/fdRead.h"
|
#include "common/io/fdRead.h"
|
||||||
#include "common/io/fdWrite.h"
|
#include "common/io/fdWrite.h"
|
||||||
#include "common/time.h"
|
#include "common/time.h"
|
||||||
@ -13,6 +11,7 @@ Test Archive Push Command
|
|||||||
#include "common/harnessFork.h"
|
#include "common/harnessFork.h"
|
||||||
#include "common/harnessInfo.h"
|
#include "common/harnessInfo.h"
|
||||||
#include "common/harnessPostgres.h"
|
#include "common/harnessPostgres.h"
|
||||||
|
#include "common/harnessProtocol.h"
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
Test Run
|
Test Run
|
||||||
@ -25,16 +24,6 @@ testRun(void)
|
|||||||
// Create default storage object for testing
|
// Create default storage object for testing
|
||||||
Storage *storageTest = storagePosixNewP(TEST_PATH_STR, .write = true);
|
Storage *storageTest = storagePosixNewP(TEST_PATH_STR, .write = true);
|
||||||
|
|
||||||
// Start a protocol server to test the protocol directly
|
|
||||||
Buffer *serverWrite = bufNew(8192);
|
|
||||||
IoWrite *serverWriteIo = ioBufferWriteNew(serverWrite);
|
|
||||||
ioWriteOpen(serverWriteIo);
|
|
||||||
|
|
||||||
ProtocolServer *server = protocolServerNew(
|
|
||||||
STRDEF("test"), STRDEF("test"), ioBufferReadNew(bufNew(0)), serverWriteIo);
|
|
||||||
|
|
||||||
bufUsedSet(serverWrite, 0);
|
|
||||||
|
|
||||||
// *****************************************************************************************************************************
|
// *****************************************************************************************************************************
|
||||||
if (testBegin("archivePushReadyList(), archivePushProcessList(), and archivePushDrop()"))
|
if (testBegin("archivePushReadyList(), archivePushProcessList(), and archivePushDrop()"))
|
||||||
{
|
{
|
||||||
@ -258,7 +247,7 @@ testRun(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// *****************************************************************************************************************************
|
// *****************************************************************************************************************************
|
||||||
if (testBegin("Synchronous cmdArchivePush(), archivePushFile() and archivePushFileProtocol()"))
|
if (testBegin("Synchronous cmdArchivePush() and archivePushFile()"))
|
||||||
{
|
{
|
||||||
TEST_TITLE("command must be run on the pg host");
|
TEST_TITLE("command must be run on the pg host");
|
||||||
|
|
||||||
@ -473,32 +462,6 @@ testRun(void)
|
|||||||
" HINT: this is valid in some recovery scenarios but may also indicate a problem.\n"
|
" HINT: this is valid in some recovery scenarios but may also indicate a problem.\n"
|
||||||
"P00 INFO: pushed WAL file '000000010000000100000002' to the archive");
|
"P00 INFO: pushed WAL file '000000010000000100000002' to the archive");
|
||||||
|
|
||||||
// Check protocol function directly
|
|
||||||
// -------------------------------------------------------------------------------------------------------------------------
|
|
||||||
VariantList *paramList = varLstNew();
|
|
||||||
varLstAdd(paramList, varNewStrZ(TEST_PATH "/pg/pg_wal/000000010000000100000002"));
|
|
||||||
varLstAdd(paramList, varNewBool(true));
|
|
||||||
varLstAdd(paramList, varNewUInt64(PG_VERSION_11));
|
|
||||||
varLstAdd(paramList, varNewUInt64(0xFACEFACEFACEFACE));
|
|
||||||
varLstAdd(paramList, varNewStrZ("000000010000000100000002"));
|
|
||||||
varLstAdd(paramList, varNewBool(false));
|
|
||||||
varLstAdd(paramList, varNewInt(6));
|
|
||||||
varLstAdd(paramList, varNewVarLst(varLstNewStrLst(strLstNew())));
|
|
||||||
varLstAdd(paramList, varNewUInt(1));
|
|
||||||
varLstAdd(paramList, varNewUInt(0));
|
|
||||||
varLstAdd(paramList, varNewStrZ("11-1"));
|
|
||||||
varLstAdd(paramList, varNewUInt64(cipherTypeNone));
|
|
||||||
varLstAdd(paramList, NULL);
|
|
||||||
|
|
||||||
TEST_RESULT_VOID(archivePushFileProtocol(paramList, server), "protocol archive put");
|
|
||||||
TEST_RESULT_STR_Z(
|
|
||||||
strNewBuf(serverWrite),
|
|
||||||
"{\"out\":[[\"WAL file '000000010000000100000002' already exists in the repo1 archive with the same checksum"
|
|
||||||
"\\nHINT: this is valid in some recovery scenarios but may also indicate a problem.\"]]}\n",
|
|
||||||
"check result");
|
|
||||||
|
|
||||||
bufUsedSet(serverWrite, 0);
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------------------------------------
|
||||||
TEST_TITLE("multiple repos, one encrypted");
|
TEST_TITLE("multiple repos, one encrypted");
|
||||||
|
|
||||||
@ -667,6 +630,10 @@ testRun(void)
|
|||||||
{
|
{
|
||||||
harnessLogLevelSet(logLevelDetail);
|
harnessLogLevelSet(logLevelDetail);
|
||||||
|
|
||||||
|
// Install local command handler shim
|
||||||
|
static const ProtocolServerHandler testLocalHandlerList[] = {PROTOCOL_SERVER_HANDLER_ARCHIVE_PUSH_LIST};
|
||||||
|
hrnProtocolLocalShimInstall(testLocalHandlerList, PROTOCOL_SERVER_HANDLER_LIST_SIZE(testLocalHandlerList));
|
||||||
|
|
||||||
TEST_TITLE("command must be run on the pg host");
|
TEST_TITLE("command must be run on the pg host");
|
||||||
|
|
||||||
StringList *argList = strLstNew();
|
StringList *argList = strLstNew();
|
||||||
@ -899,7 +866,7 @@ testRun(void)
|
|||||||
" HINT: this is valid in some recovery scenarios but may also indicate a problem.\n"
|
" HINT: this is valid in some recovery scenarios but may also indicate a problem.\n"
|
||||||
"P01 DETAIL: pushed WAL file '000000010000000100000001' to the archive\n"
|
"P01 DETAIL: pushed WAL file '000000010000000100000001' to the archive\n"
|
||||||
"P01 WARN: could not push WAL file '000000010000000100000002' to the archive (will be retried): "
|
"P01 WARN: could not push WAL file '000000010000000100000002' to the archive (will be retried): "
|
||||||
"[55] raised from local-1 protocol: " STORAGE_ERROR_READ_MISSING,
|
"[55] raised from local-1 shim protocol: " STORAGE_ERROR_READ_MISSING,
|
||||||
TEST_PATH "/pg/pg_xlog/000000010000000100000002");
|
TEST_PATH "/pg/pg_xlog/000000010000000100000002");
|
||||||
|
|
||||||
TEST_RESULT_BOOL(
|
TEST_RESULT_BOOL(
|
||||||
@ -1026,6 +993,9 @@ testRun(void)
|
|||||||
TEST_RESULT_STRLST_Z(
|
TEST_RESULT_STRLST_Z(
|
||||||
strLstSort(storageListP(storageSpool(), STRDEF(STORAGE_SPOOL_ARCHIVE_OUT)), sortOrderAsc),
|
strLstSort(storageListP(storageSpool(), STRDEF(STORAGE_SPOOL_ARCHIVE_OUT)), sortOrderAsc),
|
||||||
"000000010000000100000001.ok\n000000010000000100000002.ok\n", "check status files");
|
"000000010000000100000001.ok\n000000010000000100000002.ok\n", "check status files");
|
||||||
|
|
||||||
|
// Uninstall local command handler shim
|
||||||
|
hrnProtocolLocalShimUninstall();
|
||||||
}
|
}
|
||||||
|
|
||||||
FUNCTION_HARNESS_RETURN_VOID();
|
FUNCTION_HARNESS_RETURN_VOID();
|
||||||
|
Reference in New Issue
Block a user