From ece7f6032f9ec13c7d89f8a82a170d807a50419e Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Fri, 11 Feb 2022 13:49:36 -0500 Subject: [PATCH] wip PHPC-2064: Change strategy for disabling SKIPIF caching This complements php/php-src#8076 --- tests/utils/basic-skipif.inc | 2 ++ tests/utils/skipif.php | 28 +++++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/tests/utils/basic-skipif.inc b/tests/utils/basic-skipif.inc index ca86df03b..1174b9b69 100644 --- a/tests/utils/basic-skipif.inc +++ b/tests/utils/basic-skipif.inc @@ -25,3 +25,5 @@ register_shutdown_function(function() { exit(sprintf('skip %s: %s', errno_as_string($lastError['type']), $lastError['message'])); } }); + +disable_skipif_caching_if_necessary(); diff --git a/tests/utils/skipif.php b/tests/utils/skipif.php index 25daccac6..15803a157 100644 --- a/tests/utils/skipif.php +++ b/tests/utils/skipif.php @@ -10,15 +10,33 @@ require_once __DIR__ . '/basic.inc'; require_once __DIR__ . '/tools.php'; -/** - * Disables SKIPIF caching (PHP 8.1+). +/* Disable SKIPIF caching on PHP 8.1+ if the current script calls any functions + * that cannot be cached. SkipCache (from run-tests.php) requires that "nocache" + * be printed before all other SKIPIF output, so this function should be called + * from basic-skipif.inc before test-level skip code. */ -function disable_skipif_caching() +function disable_skipif_caching_if_necessary() { if (PHP_VERSION_ID < 80100) { return; } + $skipif = file_get_contents($_SERVER['PATH_TRANSLATED']); + + if (strpos($skipif, 'skip_if_not_clean') === false) { + return; + } + + /* Earlier versions of PHP 8.1.x discard SKIPIF output after consuming a + * leading "nocache" tag, which could prevent a test from being skipped. To + * avoid that, only print "nocache" as the final output. In the event the + * test does skip, this trailing "nocache" tag will be ignored, but that is + * preferable to ignoring the skip entirely. */ + if (PHP_VERSION_ID < 80103) { + register_shutdown_function(function() { echo "nocache\n"; }); + return; + } + echo "nocache\n"; } @@ -432,10 +450,6 @@ function skip_if_not_clean($databaseName = DATABASE_NAME, $collectionName = COLL } catch (RuntimeException $e) { exit("skip Could not drop '$databaseName.$collectionName': " . $e->getMessage()); } - - /* Since this function modifies the state of the database, we need it to run - * each time before a test. */ - disable_skipif_caching(); } function skip_if_no_getmore_failpoint()