Skip to content

refactor: no functions inside functions in the worker and the tests - #382

Merged
HardMax71 merged 1 commit into
test/durable-e2efrom
refactor/no-nested-functions
Oct 13, 2026
Merged

HardMax71 merged 1 commit into
test/durable-e2efrom
refactor/no-nested-functions

Conversation

@HardMax71

@HardMax71 HardMax71 commented Oct 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

Fixes #

Changes

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)
  • CI/CD or tooling changes

Test Plan

  • Backend unit tests pass (cd backend && uv run pytest tests/unit)
  • Frontend unit tests pass (cd frontend && npm run test)
  • Backend E2E tests pass (docker compose exec -T backend sh -c 'uv sync --group test --no-dev --frozen --no-install-project --no-build && pytest tests/e2e')
  • Frontend E2E tests pass (cd frontend && npm run test:e2e)
  • API spec and client regenerated if routes or schemas changed (./deploy.sh openapi, then ./deploy.sh types), never edited by hand
  • Manual testing performed

Manual test steps:

Checklist

  • My code follows the project's style guidelines
  • I have run pre-commit run --all-files and all checks pass
  • I have added tests that prove my fix/feature works
  • I have updated documentation if needed
  • My changes don't introduce new warnings

Screenshots (if applicable)


Summary by cubic

Refactors the worker and its tests to eliminate nested functions, moving the pod watch error handling and 410 cursor reset into PodMonitor.watch_cycle. The worker now calls a module-level start_jobs and binds scheduler.shutdown and container.close directly to the FastStream hooks, so it no longer reaches into the monitor's private cursor.

  • Test fakes and callbacks defined inside test functions became module-level classes, bound methods, and AsyncMock/MagicMock configurations; Dishka mocks are now wired through from_context.
  • Removed hypothesis and tests/load/strategies.py, since the strategy was only used to generate random JSON bodies; the load tool's clients now run in async with blocks.
  • Building a PodMonitor in tests no longer creates a real Kubernetes watch client, so the monitor tests pass with warnings as errors.

Written for commit 5fb6f3c. Summary will update on new commits.

View guided diff Turn on auto-fix

@HardMax71
HardMax71 added this pull request to stack #379 October 13, 2026 22:54
@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: dd2bb8a1-1d1a-41ad-8e4c-82e8e8174151
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added documentation Improvements or additions to documentation area: execution Queue, sagas, k8s worker, pod monitor, result processor, executor pods, runtimes labels Oct 13, 2026
@codecov-commenter

codecov-commenter commented Oct 13, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 97.67442% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
backend/app/worker.py 96.29% 1 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Flag Coverage Δ
backend-unit 72.22% <97.67%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
backend/app/services/pod_monitor/monitor.py 96.00% <100.00%> (+0.58%) ⬆️
backend/app/worker.py 86.53% <96.29%> (+9.82%) ⬆️
Components Coverage Δ
Backend 91.39% <97.67%> (+0.10%) ⬆️
Frontend 92.60% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

app/worker.py nested run, start, watch_pods and stop_scheduler inside main. main and run are module-level now, start_jobs prepares the cluster and returns the started scheduler, and FastStream gets bound methods as hooks: scheduler.shutdown before the broker stops, container.close after. The watch cycle's error handling moved into PodMonitor.watch_cycle, so the worker no longer reaches into the monitor's private cursor, and it has tests now.

In the tests, fakes and callbacks defined inside test functions became module-level classes, plain AsyncMock and MagicMock configurations, bound methods or named functions: the streaming ASGI transport and the middleware harnesses keep their state in small channel classes, routes and subscribers are registered explicitly, call order comes from attach_mock, the JWT cases are data instead of lambdas, and Dishka gets mocks through from_context. Building a PodMonitor no longer leaks a real Kubernetes watch client, so the monitor tests pass with warnings as errors, and they carry no type: ignore. The load tool's clients live in async with blocks, and its Hypothesis strategy, which only ran through .example(), is gone along with the dependency.
@HardMax71
HardMax71 force-pushed the refactor/no-nested-functions branch from c298c8f to 5fb6f3c Compare October 13, 2026 23:27
@sonarqubecloud

Copy link
Copy Markdown

@HardMax71
HardMax71 merged commit f68a85f into main Oct 13, 2026
23 checks passed
@HardMax71
HardMax71 deleted the refactor/no-nested-functions branch October 13, 2026 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: execution Queue, sagas, k8s worker, pod monitor, result processor, executor pods, runtimes documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants