Skip to content

Commit 095c23a

Browse files
gin0115claude
andcommitted
Fix flaky Find_Or_Create_Snapshot tests under random ordering
The tests failed intermittently in CI depending on the PHPUnit random seed. Test_Find_Or_Create_Snapshot mocks archive.org at the HTTP layer (pre_http_request), but several other test classes register fake clients via the iawmlf_snapshot_client / iawmlf_link_checker_client filters and only cleared them in set_up, never in tear_down. When one ran just before Find_Or_Create, the stale client hijacked the event so get_latest_snapshot returned null and the link stuck at 'pending' instead of 'new'/'done'. - Defensive: clear both client filters in Find_Or_Create_Snapshot::set_up. - Root cause: add tear_down cleanup to the set_up-only leakers (Check_Snapshot_Status_Event, Action_Scheduler_Garbage_Collection, Report_Table_Actions). Verified: the previously-failing seed 1782941233 now passes, plus three further random seeds - 355 tests green each. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent f6af7cf commit 095c23a

4 files changed

Lines changed: 38 additions & 0 deletions

File tree

tests/Event/Test_Check_Snapshot_Status_Event.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ public function set_up(): void {
4848
parent::set_up();
4949
}
5050

51+
/**
52+
* Tear down
53+
*/
54+
public function tear_down(): void {
55+
// Remove client mocks so they can't leak into later tests under random ordering.
56+
remove_all_filters( 'iawmlf_snapshot_client' );
57+
remove_all_filters( 'iawmlf_link_checker_client' );
58+
59+
parent::tear_down();
60+
}
61+
5162
/**
5263
* Set the snapshot client to return a mocked response.
5364
*

tests/Event/Test_Find_Or_Create_Snapshot.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public function set_up(): void {
3232
// Clear the actionscheduler_actions table.
3333
$this->wpdb->query( "TRUNCATE TABLE {$this->wpdb->prefix}actionscheduler_actions" );
3434

35+
// Clear any snapshot / link-checker client mocks leaked from other tests (random order):
36+
// this class mocks at the HTTP layer, so a stale injected client would leave links 'pending'.
37+
remove_all_filters( 'iawmlf_snapshot_client' );
38+
remove_all_filters( 'iawmlf_link_checker_client' );
39+
3540
parent::set_up();
3641
}
3742

tests/Report/Test_Report_Table_Actions.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ public function set_up(): void {
4949
parent::set_up();
5050
}
5151

52+
/**
53+
* Tear down
54+
*/
55+
public function tear_down(): void {
56+
// Remove client mocks so they can't leak into later tests under random ordering.
57+
remove_all_filters( 'iawmlf_snapshot_client' );
58+
remove_all_filters( 'iawmlf_link_checker_client' );
59+
60+
parent::tear_down();
61+
}
62+
5263
/**
5364
* Set the snapshot client to return a mocked response.
5465
*

tests/Util/Test_Action_Scheduler_Garbage_Collection.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ public function set_up(): void {
5555
parent::set_up();
5656
}
5757

58+
/**
59+
* Tear down
60+
*/
61+
public function tear_down(): void {
62+
// Remove client mocks so they can't leak into later tests under random ordering.
63+
remove_all_filters( 'iawmlf_snapshot_client' );
64+
remove_all_filters( 'iawmlf_link_checker_client' );
65+
66+
parent::tear_down();
67+
}
68+
5869
/**
5970
* Set the snapshot client to return a mocked response.
6071
*

0 commit comments

Comments
 (0)