Skip to content

test(usage): wait for schema readiness before E2E queries - #13506

Merged
ChiragAgg5k merged 3 commits into
mainfrom
fix/usage-e2e-schema-readiness
Sep 6, 2026
Merged

ChiragAgg5k merged 3 commits into
mainfrom
fix/usage-e2e-schema-readiness

Conversation

@ChiragAgg5k

Copy link
Copy Markdown
Member

Summary

  • Wait for /health/usage before the six usage-query E2E tests run.
  • Use the existing assertEventually helper (60-second timeout, 500ms polling) and reuse one health.read key across probes.
  • Keep every query/validation assertion unchanged. Disabled-stats and missing-scope tests do not wait for storage.

Root cause

Failing PostgreSQL (dedicated) / Usage job

All six failures were HTTP 503 instead of the expected 200/400. The API was serving requests while ClickHouse initialization was still retrying (Usage schema setup failed. Retrying (1/2)...). Usage routes correctly returned general_usage_not_ready during that window. HTTP /health/version readiness does not guarantee that the usage schema exists.

The usage health endpoint checks the event, gauge, and daily schema through the real storage connection. Polling it establishes the test prerequisite without retrying the requests/assertions under test, adding an unconditional sleep, or changing application startup behavior.

Local E2E verification

Ran against an isolated Docker stack with dedicated PostgreSQL, Redis, ClickHouse 26.4.3, and the real API/worker. Source and locked Composer dependencies were from main at 6c9ce08306 plus this test-only change.

Scenario Result
Unmodified suite, storage ready Pass: 8 tests, 1 expected disabled-mode skip
Unmodified suite, empty ClickHouse volume and startup delayed by 8 seconds Reproduced all 6 CI failures (503 vs 200/400)
Fixed suite, delayed initial ClickHouse startup, PHPUnit Pass; readiness probe waited ~11 seconds
Fixed suite, empty ClickHouse volume + 8-second delayed startup, four-process functional ParaTest 3/3 passes, 8 tests each, 1 expected skip each
Fixed suite, warm stack, four-process functional ParaTest 10/10 passes, 8 tests / 115 assertions / 1 expected skip each
ClickHouse permanently stopped, single affected test Expected failure after the bounded wait (~63 seconds total), with Usage storage must be ready before testing usage queries
_APP_USAGE_STATS=disabled on API and test process, ClickHouse stopped Pass: 8 tests / 27 assertions / 6 expected enabled-mode skips; disabled-mode and scope tests both execute
Restored enabled stack, full Usage suite Pass: 8 tests / 85 assertions / 1 expected skip
Pint, PHP syntax, git diff --check Pass

Commands used for the suites:

docker compose -f /tmp/usage-compose.json exec -T appwrite test tests/e2e/Services/Usage

docker compose -f /tmp/usage-compose.json exec -T appwrite \
  vendor/bin/paratest --processes 4 --functional tests/e2e/Services/Usage \
  --exclude-group abuseEnabled --exclude-group screenshots --exclude-group antivirus

Cold-start verification used only disposable project-scoped containers/volumes: remove the test ClickHouse container/volume, restart the API, start ClickHouse after 8 seconds, and launch the suite as soon as API health passes. The baseline ran the unchanged test file from HEAD; the fixed runs used this branch. No production code was patched or mocked.

Local runtime: ARM64 PHP 8.5.9 (CI used PHP 8.5.10). The cached development image has MongoDB extension 2.3.3 rather than the lockfile's required 2.1.x, so dependency installation used --ignore-platform-req=ext-mongodb; MongoDB was not used in these PostgreSQL tests.

@greptile-apps

greptile-apps Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR stabilizes usage-query E2E tests by waiting for the authenticated usage health endpoint to report schema readiness before running the existing query assertions.

  • Replaces the enabled-only guard in six tests with a bounded readiness wait.
  • Reuses one project and health.read API key for each test’s polling loop.
  • Preserves the disabled-usage skip and all query validation assertions.

Confidence Score: 5/5

The PR appears safe to merge because the readiness probe matches the health endpoint contract and preserves existing test behavior.

No blocking or actionable new issue remains; temporary not-ready responses are retried within the established eventual-assertion helper, while disabled usage configurations continue to skip the affected tests.

Important Files Changed

Filename Overview
tests/e2e/Services/Usage/UsageCustomServerTest.php Adds a correctly scoped, bounded usage-schema readiness probe before the six storage-dependent usage tests.

Reviews (3): Last reviewed commit: "Merge branch 'main' into fix/usage-e2e-s..." | Re-trigger Greptile

@github-actions

github-actions Bot commented Sep 6, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/usage-e2e-schema-readiness (after).

Metric Before After Change
🚀 Requests/sec 209.33 218.2 ⚪ +4.2%
⏱️ Latency P50 85.59 ms 83.43 ms ⚪ -2.5%
⏱️ Latency P95 184.68 ms 177.37 ms ⚪ -4%
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 83.43 177.37 13,680 218.2 -7.3
Account 150.45 250.6 720 12.14 -12.49
TablesDB 83.27 143.86 7,440 121.37 -14.67
Storage 70.86 159.76 3,600 60.75 +6.1
Functions 109.86 211.97 1,920 33.09 +3.34

Top API waits (after)

API request Max wait (ms)
storage.buckets.create 382.69
functions.create 382.13
functions.variables.create 373.14
account.name.update 361.59
tablesdb.rows.decrement 319.77

@ChiragAgg5k
ChiragAgg5k merged commit d8db278 into main Sep 6, 2026
47 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/usage-e2e-schema-readiness branch September 6, 2026 18:43
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.

2 participants