Skip to content

test(graphql): cover one resolver lock across a request's fields - #14981

Merged
abnegate merged 1 commit into
mainfrom
fix/graphql-resolver-lock-coverage
Oct 27, 2026
Merged

abnegate merged 1 commit into
mainfrom
fix/graphql-resolver-lock-coverage

Conversation

@abnegate

Copy link
Copy Markdown
Member

What does this PR do?

Adds a unit test for the GraphQL resolver lock that #14820 moved into the request context (resolverLock in app/init/resources/request.php). That PR's e2e test covers caller identity, but nothing covered the lock itself.

The test registers the production request context, resolves three fields of one request through Resolvers::api() in Swoole coroutines, and starts the third field after the first has finished while the second still holds the lock. It asserts that no two fields run at once.

CoroutineServer is a minimal HTTP adapter whose context is coroutine-local, like the Swoole adapters, so each resolver coroutine gets its own child container. The test runs in a separate process because Swoole\Coroutine\run() leaves runtime hooks enabled for the rest of the process.

Test Plan

  • vendor/bin/phpunit tests/unit/GraphQL/ResolversTest.php passes on main (3 of 3 runs).
  • With the Resolvers.php and request.php changes from acfc742 reverted, it fails in 3 of 3 runs: Failed asserting that 2 is identical to 1.
  • --testsuite unit in appwrite/base:2.2.7 shows the same results as main. In both, the only failures are 12 errors from KeyTest and ListCacheTest, which need the stack's OpenSSL key and Redis.
  • composer lint and phpstan on the new files both pass.

Related PRs and Issues

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

🤖 Generated with Claude Code

Fields of one GraphQL request share the request's resources, so they
must run one at a time. Resolve three fields through the production
request context and assert a field that starts after the first has
finished still waits for the second.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@luxor-code-review

luxor-code-review Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This PR is test-only: it introduces a Swoole coroutine-based fake HTTP adapter and a unit test asserting that GraphQL fields within a single request execute serially under the shared resolverLock, running in a separate process to keep coroutine work out of the shared unit suite.

Files Change
tests/unit/GraphQL/CoroutineServer.php New coroutine-aware Utopia\Http\Adapter fake that serves requests inside Coroutine\run() for unit tests.
tests/unit/GraphQL/ResolversTest.php New test asserting GraphQL resolvers serialize per request via the resolverLock resource.

Reviewed commit: 4724ac8

@ghost

ghost commented Oct 27, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The test uses the production request resource registration and verifies the resolver lock behavior without a shared-process Swoole runtime.

Adds a coroutine-local HTTP adapter for GraphQL resolver testing and a separate-process test that invokes three API resolvers using the production request context. The test checks that all fields complete and that only one route action runs at a time.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 2
File Change
tests/unit/GraphQL/CoroutineServer.php Adds a minimal HTTP adapter whose context is stored per Swoole coroutine.
tests/unit/GraphQL/ResolversTest.php Adds a separate-process concurrency test for resolver calls sharing one request context.

Reviewed 4724ac8 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

6 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (3)
  • php.appwrite.secret-compare-timing (1)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@github-actions

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/graphql-resolver-lock-coverage (after).

Metric Before After Change
🚀 Requests/sec 217.63 217.03 ⚪ -0.3%
⏱️ Latency P50 78.68 ms 79.35 ms ⚪ +0.9%
⏱️ Latency P95 180.78 ms 188.33 ms ⚪ +4.2%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 79.35 188.33 13,680 217.03 +7.55
Account 153.12 294.57 720 11.95 +33.47
TablesDB 77.86 149.57 7,440 119.34 +10.51
Storage 71.53 163.23 3,600 60.06 -15.16
Functions 110.78 216.66 1,920 32.72 +16.97

Top API waits (after)

API request Max wait (ms)
account.name.update 484.35
storage.buckets.create 449.97
tablesdb.rows.create 390.45
account.prefs.update 386.93
functions.variables.update 326.28

@abnegate
abnegate merged commit bf1827b into main Oct 27, 2026
33 checks passed
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.

1 participant