Skip to content

Commit 3bacfbd

Browse files
test: isolate retention filter overrides
1 parent 58fa2f7 commit 3bacfbd

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

tests/retention-action-scheduler-batching-smoke.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
$total = 0;
3636

3737
// Simple in-memory filter registry so apply_filters() returns overrides.
38-
$GLOBALS['__retention_filters'] = array();
38+
$GLOBALS['__retention_filters'] = array();
39+
$GLOBALS['__retention_filter_callbacks'] = array();
3940

4041
if ( ! function_exists( 'apply_filters' ) ) {
4142
function apply_filters( string $hook, $value ) {
@@ -51,6 +52,29 @@ function do_action( ...$args ) {}
5152

5253
function retention_set_filter( string $hook, $value ): void {
5354
$GLOBALS['__retention_filters'][ $hook ] = $value;
55+
56+
if ( ! function_exists( 'add_filter' ) ) {
57+
return;
58+
}
59+
60+
if ( isset( $GLOBALS['__retention_filter_callbacks'][ $hook ] ) ) {
61+
remove_filter( $hook, $GLOBALS['__retention_filter_callbacks'][ $hook ], PHP_INT_MAX );
62+
}
63+
64+
$callback = static fn() => $value;
65+
add_filter( $hook, $callback, PHP_INT_MAX );
66+
$GLOBALS['__retention_filter_callbacks'][ $hook ] = $callback;
67+
}
68+
69+
function retention_reset_filters(): void {
70+
if ( function_exists( 'remove_filter' ) ) {
71+
foreach ( $GLOBALS['__retention_filter_callbacks'] as $hook => $callback ) {
72+
remove_filter( $hook, $callback, PHP_INT_MAX );
73+
}
74+
}
75+
76+
$GLOBALS['__retention_filters'] = array();
77+
$GLOBALS['__retention_filter_callbacks'] = array();
5478
}
5579

5680
function assert_batching( string $name, bool $condition, string $detail = '' ): void {
@@ -572,7 +596,7 @@ private function matching_logs( string $cutoff, ?string $hook ): array {
572596
// ceiling can delete. Seed 25 fresh execute_step rows with distinct, recent
573597
// timestamps (within any age window) — 15 should be deleted by the ceiling,
574598
// the 10 most-recent must survive.
575-
$GLOBALS['__retention_filters'] = array();
599+
retention_reset_filters();
576600
retention_set_filter( 'datamachine_as_actions_hook_max_age_days', array( 'datamachine_execute_step' => 3650.0 ) );
577601
retention_set_filter( 'datamachine_as_actions_hook_max_rows', array( 'datamachine_execute_step' => 10 ) );
578602

@@ -664,6 +688,8 @@ private function matching_logs( string $cutoff, ?string $hook ): array {
664688
false === $disabled['enabled'] && false === $disabled['breached']
665689
);
666690

691+
retention_reset_filters();
692+
667693
if ( $failed > 0 ) {
668694
echo "\nretention-action-scheduler-batching-smoke failed: {$failed}/{$total} assertions failed.\n";
669695
exit( 1 );

0 commit comments

Comments
 (0)