Skip to content

Fix SQLite concurrency for refresh rotation tests#667

Open
shreyansh-tech21 wants to merge 6 commits into
neeru24:mainfrom
shreyansh-tech21:bug/fix-test-concurrent-refresh
Open

Fix SQLite concurrency for refresh rotation tests#667
shreyansh-tech21 wants to merge 6 commits into
neeru24:mainfrom
shreyansh-tech21:bug/fix-test-concurrent-refresh

Conversation

@shreyansh-tech21

Copy link
Copy Markdown
Contributor

What does this PR do?

Improves SQLite behavior for concurrent refresh-token rotation and hardens the refresh rotation tests so they match real multi-threaded use: workers run with their own Flask app_context, tests use a shared file-backed SQLite DB (not isolated :memory: per connection), and the app configures SQLAlchemy’s BEGIN IMMEDIATE pattern on SQLite so two threads cannot both “win” the same rotation race. The concurrent test still asserts exactly one successful rotate_refresh_token and one RefreshRotationError (reuse).

Related Issue

Closes #12

Changes made

  • Add sqlite_db.py with configure_sqlite_immediate_transactions() (connectisolation_level = None, beginBEGIN IMMEDIATE) for SQLite engines only.
  • Call that configuration from app.py immediately after db.init_app(app) (inside app_context()), so production and tests using SQLite get serialized writer behavior without affecting Postgres.
  • Update tests/test_refresh_rotation.py: tmp_path file SQLite URI + db.engine.dispose() in the fixture; per-thread with app.app_context() in concurrent workers; docstring describing threading + SQLite safety; stricter assertions on the loser (reuse).

Checklist

  • I have tested my changes
  • My code follows project guidelines
  • No new errors introduced

@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Thanks for creating a PR for your Issue! ☺️

We'll review it as soon as possible.
In the meantime, please double-check the file changes and ensure that all commits are accurate.

If there are any unresolved review comments, feel free to resolve them. 🙌🏼

@iarmaanx iarmaanx self-requested a review June 8, 2026 10:47
@neeru24

neeru24 commented Jun 8, 2026

Copy link
Copy Markdown
Owner

@shreyansh-tech21 resolve conflicts

@shreyansh-tech21

shreyansh-tech21 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

Hi @neeru24 and @iarmaanx , I have resolved all the conflicts. Made code changes as we per the proposal. Please let me know if there are any further code changes from my side. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Pull Request Template

2 participants