Skip to content

Commit 08bfdb3

Browse files
dd32claude
andcommitted
Fix race condition in test by serializing hook execution
When two concurrent subprocesses both modify the WordPress cron option simultaneously, the second write can overwrite the first removal, leaving stale events. Use --concurrent=1 for the basic execution test to avoid this; actual concurrency is still tested separately in test 8. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2efc5c0 commit 08bfdb3

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

tests/run-tests.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ check "no pending tasks message" "No pending cron tasks found." "$out"
7979
out=$(WP cron-concurrent run --filter=__nonexistent_hook_xyz__ || true)
8080
check "filter with zero matches" "No pending cron tasks found." "$out"
8181

82-
# 5. Schedule two hooks and verify both are executed.
82+
# 5. Schedule two hooks and verify both are executed (sequential to avoid
83+
# race conditions in WordPress's cron option; concurrency tested in #8).
8384
WP eval "wp_schedule_single_event( time() - 1, 'test_cc_hook_a' );" > /dev/null
8485
WP eval "wp_schedule_single_event( time() - 1, 'test_cc_hook_b' );" > /dev/null
85-
out=$(WP cron-concurrent run --filter=test_cc_ || true)
86+
out=$(WP cron-concurrent run --filter=test_cc_ --concurrent=1 || true)
8687
check "detects and runs pending tasks" "cron task(s) completed" "$out"
8788

8889
# 6. After running, events are consumed and queue is empty again.

0 commit comments

Comments
 (0)