pgbackrest.git / summary / log / commit / refs

commit    77ae753ef59bd40b9867be21e8519093786c3b85
Author:   David Steele <david@pgbackrest.org>
Date:     Wed Oct 09 14:48:00 2024 +0000

    Allow fdReady() shim to be run only once with a specified return value.
    
    This allows more targeted testing than the prior (still supported) approach.


test/src/common/harnessFd.c | 30 ++++++++++++++++++++++++++++-- test/src/common/harnessFd.h | 3 +++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/test/src/common/harnessFd.c b/test/src/common/harnessFd.c index c3fd01caf..6fcc724df 100644 --- a/test/src/common/harnessFd.c +++ b/test/src/common/harnessFd.c @@ -18,6 +18,8 @@ Shim install state static struct { bool localShimFdReady; // Is shim installed? + bool localShimFdReadyOne; // Should the shim run once? + bool localShimFdReadyOneResult; // Shim result for single run } hrnFdStatic; /*********************************************************************************************************************************** @@ -35,9 +37,19 @@ fdReady(int fd, bool read, bool write, TimeMSec timeout) bool result; - if (hrnFdStatic.localShimFdReady) + // If shim will run once then return the requested result + if (hrnFdStatic.localShimFdReadyOne) + { + hrnFdStatic.localShimFdReadyOne = false; + result = hrnFdStatic.localShimFdReadyOneResult; + + // If result is false sleep the full timeout + if (!result) + sleepMSec(timeout); + } + // Else if shim is installed return false if read and write are both true, otherwise return true + else if (hrnFdStatic.localShimFdReady) { - // When shim is installed return false if read and write are both true, otherwise return true result = !(read && write); } // Else call normal function @@ -68,3 +80,17 @@ hrnFdReadyShimUninstall(void) FUNCTION_HARNESS_RETURN_VOID(); } + +/**********************************************************************************************************************************/ +void +hrnFdReadyShimOne(const bool result) +{ + FUNCTION_HARNESS_BEGIN(); + FUNCTION_HARNESS_PARAM(BOOL, result); + FUNCTION_HARNESS_END(); + + hrnFdStatic.localShimFdReadyOne = true; + hrnFdStatic.localShimFdReadyOneResult = result; + + FUNCTION_HARNESS_RETURN_VOID(); +} diff --git a/test/src/common/harnessFd.h b/test/src/common/harnessFd.h index c54c6c93a..1f945cf12 100644 --- a/test/src/common/harnessFd.h +++ b/test/src/common/harnessFd.h @@ -8,3 +8,6 @@ Functions // Install/uninstall shim void hrnFdReadyShimInstall(void); void hrnFdReadyShimUninstall(void); + +// Use shim for one call +void hrnFdReadyShimOne(bool result); [parent: 6ac4e8dd78f1]