Skip to content

Keep runtime test mocks from breaking asynchronous logging - #88

Merged
abhi1693 merged 1 commit into
masterfrom
fix/runtime-thread-fixture-isolation
Oct 4, 2026
Merged

abhi1693 merged 1 commit into
masterfrom
fix/runtime-thread-fixture-isolation

Conversation

@abhi1693

@abhi1693 abhi1693 commented Oct 4, 2026 •

Copy link
Copy Markdown
Owner

What changes and why?

Scheduler heartbeat and search-indexer shutdown fixtures replaced threading.Event on Python’s shared module. During backend tests, an asynchronous API log writer could then call isinstance(..., threading.Event) with a function instead of a class, lose its output thread and emit an unhandled-thread warning. This occurred in the #79 unit job.

Scope each fake to its service module’s threading binding. The heartbeat, wait, signal and cleanup assertions remain intact. A shared regression fixture now sends and drains a real queued log during every scheduler/indexer runtime case, and verifies that the writer remains alive.

Related issues

Related to #79. This unrelated fixture repair is isolated from that production refactor. Merge after #79 and before continuing #80–#84, one PR at a time.

Validation

  • With the original global mocks, all six strengthened runtime cases failed and all six emitted thread exceptions when warnings were treated as errors.
  • With scoped mocks, 89 scheduler, search-indexer and logging tests passed using -W error::pytest.PytestUnhandledThreadExceptionWarning.
  • Ruff lint and formatting passed. Normal commit hooks passed, including full backend unit coverage, types and version checks. The 67.60% backend coverage minimum remains unchanged.
  • Current-head CI passed 39 jobs, with 10 expected skips: CI required, all three CodeQL analyses, Sonar, dependency/secret/workflow checks, populated upgrades, real API/admin journeys, web/Chrome/Edge reader parity, performance comparison and ARM64 image checks.
  • Hosted backend unit suite: 3,007 passed, no skips and no warnings, all 273 source files, 67.72% combined coverage. All 1,137 PostgreSQL/Redis integration tests, 818 web and 648 admin unit tests passed. The unhandled asynchronous logging warning present in Reduce backend duplication and strengthen service boundaries #79 is absent.
  • Sonar MCP confirms gate OK, zero open issues and 0.0% new duplication. This test-only change has no new-production-code coverage condition. No quality rule or gate was changed.
  • GitHub’s separate managed AI findings scan remains unavailable because the monthly quota is exhausted (HTTP 402); standard CodeQL passed. No paid/account changes were made.
  • Changes are confined to backend test fixtures; there is no UI or runtime behavior change requiring screenshots or new product documentation.

Rollout notes

No application, dependency, database, workflow or deployment change. Auto-merge is disabled. Wait for current-head CI required, CodeQL and Sonar to pass and resolve all review threads before manually merging.

Ready for review

  • The description explains the change and validation results, including gaps.
  • Relevant regression tests are updated; product documentation is unchanged because application behavior is unchanged.

@gitar-bot

gitar-bot Bot commented Oct 4, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

🟢 Low risk · Test fixtures isolate thread mocks and exercise queued logging without changing runtime code.

Isolates runtime test mocks for scheduler heartbeat and search-indexer shutdown to prevent asynchronous logging from breaking. Scoped fakes to each service module's threading binding while preserving heartbeat, wait, signal and cleanup assertions, and adds a regression fixture that verifies the log writer thread remains alive. No issues found.

Review coverage

📋 Rules No rules evaluated

🧪 Functional validation Not enabled · Set up

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Counting what did not apply, without listing it.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown

PR reader API performance

Result: INCONCLUSIVE

6 inconclusive · 2 within threshold. Zero request failures across all six runs.

Base 626947d3643f0848b9c90024574a0a1d923cb412 → PR 691a0386da9994cc06e17f98bc6d1d7b040c954c

Three independent runs per revision, each on a fresh GitHub-hosted ARM64 runner. 16 users, 60 seconds/run, 1,000 synthetic articles, cache off, five PgBouncer slots.

Latency comparison

All latency values are in milliseconds; lower is better. Values are medians of three runs.

Route Base p95 PR p95 Change Result
All requests 77 79 +2 (+2.6%) Inconclusive
Latest feed 100 110 +10 (+10.0%) Inconclusive
Feed pagination 72 70 -2 (-2.8%) Inconclusive
Article detail 54 59 +5 (+9.3%) Within threshold
Source feed 87 71 -16 (-18.4%) Inconclusive
Topic feed 85 74 -11 (-12.9%) Inconclusive
Feed filters 67 61 -6 (-9.0%) Inconclusive
Sources 32 34 +2 (+6.2%) Within threshold
Topics 32 37 +5 (+15.6%) Inconclusive
Additional latency and throughput metrics

Each cell shows base → PR. Latencies are in milliseconds.

Endpoint p50 p99 Requests/s
Aggregated 25 → 25 120 → 120 30.65 → 30.91
/v1/feed [latest] 41 → 40 140 → 150 8.92 → 9.05
/v1/feed [page] 24 → 24 110 → 97 3.85 → 3.87
/v1/articles/[id] 15 → 16 110 → 95 6.00 → 6.32
/v1/feed [source] 25 → 24 130 → 96 2.23 → 1.87
/v1/feed [topic] 27 → 24 90 → 88 1.96 → 1.76
/v1/feed/options 20 → 19 86 → 88 2.62 → 2.65
/v1/sources 10 → 10 53 → 54 2.62 → 2.65
/v1/topics 11 → 11 78 → 68 2.62 → 2.65
Individual runs
Run Requests Failures Exit code
Base 1 1720 0 0
Base 2 1712 0 0
Base 3 1738 0 0
PR 1 1717 0 0
PR 2 1754 0 0
PR 3 1732 0 0
How to interpret this report

Regressed / Improved: a p95 regression needs >20% and >20 ms increase in the medians and at least two head samples versus the base median. Improvements use the inverse threshold. Within threshold means the change did not meet both thresholds.

Inconclusive: a within-revision p95 range >35% of its median and >20 ms is too noisy for a confident latency verdict.

Inconclusive latency comparisons are non-blocking: the check passes without claiming an improvement. Confirmed regressions and test/report errors fail the PR gate. Throughput is descriptive: paced users do not measure maximum capacity. This uncached public API test does not establish production health, browser performance or worker capacity. Separate runners can differ in hardware or host load; repetitions and noise checks reduce but cannot eliminate that uncertainty.

Full HTML/CSV reports and logs · attempt 1

@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown

Backend unit coverage

PASS · minimum combined coverage 67.60%.

Tests: 3007 passed, 0 failed, 0 skipped. Source files: 273.

Workspace Lines Branches Combined
All backend code 71.57% 53.67% 67.72%
apps/admin-api 64.78% 35.76% 59.95%
apps/aggregator 73.60% 57.18% 69.86%
apps/api 68.94% 55.88% 66.48%
apps/article-enrichment-worker 80.00% 50.00% 71.43%
apps/cli 68.76% 42.93% 64.81%
apps/images-worker 80.00% 50.00% 71.43%
apps/mcp 79.90% 73.88% 78.77%
apps/notifications 83.33% 76.67% 81.75%
apps/search-indexer 85.48% 85.71% 85.53%
apps/source-discovery-worker 80.00% 50.00% 71.43%
apps/user-api 59.19% 32.90% 54.27%
packages/core 73.66% 56.49% 69.57%
packages/http 94.43% 86.47% 92.62%

Unit coverage includes every backend workspace. PostgreSQL/Redis integration tests run separately.

Commit: 691a038 · HTML, JSON, XML reports and job logs · attempt 1

@sonarqubecloud

sonarqubecloud Bot commented Oct 4, 2026

Copy link
Copy Markdown

@abhi1693
abhi1693 merged commit 19af7f2 into master Oct 4, 2026
52 checks passed
@abhi1693
abhi1693 deleted the fix/runtime-thread-fixture-isolation branch October 4, 2026 16:19
@abhi1693 abhi1693 mentioned this pull request Oct 4, 2026
2 tasks done
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