Skip to content

fix: distribute shard tests round-robin to avoid PCRE backtrack limit#1744

Open
NarimanGardi wants to merge 1 commit into
pestphp:4.xfrom
NarimanGardi:fix/shard-pcre-backtrack-limit
Open

fix: distribute shard tests round-robin to avoid PCRE backtrack limit#1744
NarimanGardi wants to merge 1 commit into
pestphp:4.xfrom
NarimanGardi:fix/shard-pcre-backtrack-limit

Conversation

@NarimanGardi

Copy link
Copy Markdown

Fixes #1722.

When sharding without a tests/.pest/shards.json timings file, the fallback split tests into contiguous chunks. Since --list-tests returns classes sorted, a chunk is a cluster of classes sharing long common prefixes; joined into one unanchored --filter alternation it trips PCRE's backtrack limit on large suites — preg_match returns false (PREG_INTERNAL_ERROR), so the shard matches nothing and exits "No tests found".

This interleaves the fallback round-robin — the same approach the timings path already uses for new tests — so prefixes are scattered across shards and each shard's filter stays within PCRE limits. Extracted the distribution into Shard::distribute() with unit tests.

The no-cache --shard fallback chunked tests contiguously. Because --list-tests returns classes sorted, a chunk clustered classes sharing long common prefixes; joined into one unanchored --filter alternation it trips PCRE's backtrack limit on large suites, so the shard matched nothing and exited "No tests found". Interleave round-robin like the timings path already does for new tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: count-based --shard fallback selects zero tests on large suites (PCRE backtrack limit in --filter)

1 participant