Skip to content

Commit

Permalink
Refactor of pq shim to allow more flexible scripting.
Browse files Browse the repository at this point in the history
The pq scripts were pretty static which had already led to a lot of code duplication in the backup test harness.

Instead allow the scripts to be built dynamically, which allows for much more flexibility and reduces duplication. For now just make these changes in the backup harness, but they may be useful elsewhere.

While we are making big changes, also update the macro/function names to hew closer to our current harness naming conventions.
  • Loading branch information
dwsteele committed Oct 22, 2023
1 parent 306fdff commit e0f5880
Show file tree
Hide file tree
Showing 11 changed files with 1,257 additions and 1,507 deletions.
14 changes: 5 additions & 9 deletions CONTRIBUTING.md
Expand Up @@ -509,17 +509,13 @@ HRN_FORK_END();
A PostgreSQL libpq shim is provided to simulate interactions with PostgreSQL. Below is a simple example. See [harnessPq.h](https://github.com/pgbackrest/pgbackrest/blob/main/test/src/common/harnessPq.h) for more details.
```
// Set up two standbys but no primary
harnessPqScriptSet((HarnessPq [])
{
HRNPQ_MACRO_OPEN_GE_96(1, "dbname='postgres' port=5432", PG_VERSION_96, "/pgdata", true, NULL, NULL),
HRNPQ_MACRO_OPEN_GE_96(8, "dbname='postgres' port=5433", PG_VERSION_96, "/pgdata", true, NULL, NULL),
HRN_PQ_SCRIPT_SET(
HRN_PQ_SCRIPT_OPEN_GE_96(1, "dbname='postgres' port=5432", PG_VERSION_96, "/pgdata", true, NULL, NULL),
HRN_PQ_SCRIPT_OPEN_GE_96(8, "dbname='postgres' port=5433", PG_VERSION_96, "/pgdata", true, NULL, NULL),

// Close the "inner" session first (8) then the outer (1)
HRNPQ_MACRO_CLOSE(8),
HRNPQ_MACRO_CLOSE(1),

HRNPQ_MACRO_DONE()
});
HRN_PQ_SCRIPT_CLOSE(8),
HRN_PQ_SCRIPT_CLOSE(1));

TEST_ERROR(cmdCheck(), ConfigError, "primary database not found\nHINT: check indexed pg-path/pg-host configurations");
```
Expand Down
14 changes: 5 additions & 9 deletions doc/xml/contributing.xml
Expand Up @@ -571,17 +571,13 @@ HRN_FORK_END();

<code-block>
// Set up two standbys but no primary
harnessPqScriptSet((HarnessPq [])
{
HRNPQ_MACRO_OPEN_GE_96(1, "dbname='postgres' port=5432", PG_VERSION_96, "/pgdata", true, NULL, NULL),
HRNPQ_MACRO_OPEN_GE_96(8, "dbname='postgres' port=5433", PG_VERSION_96, "/pgdata", true, NULL, NULL),
HRN_PQ_SCRIPT_SET(
HRN_PQ_SCRIPT_OPEN_GE_96(1, "dbname='postgres' port=5432", PG_VERSION_96, "/pgdata", true, NULL, NULL),
HRN_PQ_SCRIPT_OPEN_GE_96(8, "dbname='postgres' port=5433", PG_VERSION_96, "/pgdata", true, NULL, NULL),

// Close the "inner" session first (8) then the outer (1)
HRNPQ_MACRO_CLOSE(8),
HRNPQ_MACRO_CLOSE(1),

HRNPQ_MACRO_DONE()
});
HRN_PQ_SCRIPT_CLOSE(8),
HRN_PQ_SCRIPT_CLOSE(1));

TEST_ERROR(cmdCheck(), ConfigError, "primary database not found\nHINT: check indexed pg-path/pg-host configurations");
</code-block>
Expand Down
395 changes: 138 additions & 257 deletions test/src/common/harnessBackup.c

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions test/src/common/harnessBackup.h
Expand Up @@ -26,6 +26,8 @@ typedef struct HrnBackupPqScriptParam
bool noWal; // Don't write test WAL segments
bool noPriorWal; // Don't write prior test WAL segments
bool noArchiveCheck; // Do not check archive
bool walSwitch; // WAL switch is required
bool tablespace; // Is there a tablespace?
CompressType walCompressType; // Compress type for the archive files
CipherType cipherType; // Cipher type
const char *cipherPass; // Cipher pass
Expand Down

0 comments on commit e0f5880

Please sign in to comment.