Skip to content

Add util to close db connections - #8626

Merged
Jens Hedegaard Nielsen (jenshnielsen) merged 5 commits into
microsoft:mainfrom
jenshnielsen:cleanup_db_connections_simple
Oct 19, 2026
Merged

Jens Hedegaard Nielsen (jenshnielsen) merged 5 commits into
microsoft:mainfrom
jenshnielsen:cleanup_db_connections_simple

Conversation

@jenshnielsen

Copy link
Copy Markdown
Collaborator
  • Close all connections at end of each test
  • Add atexit logic to close any open connection on shutdown

Local benchmarking shows a factor of 2 speed up in Linux but limited effect in Windows

@codecov

codecov Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.62%. Comparing base (68641db) to head (cc1af44).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8626      +/-   ##
==========================================
+ Coverage   72.58%   72.62%   +0.03%     
==========================================
  Files         307      307              
  Lines       32409    32431      +22     
==========================================
+ Hits        23525    23552      +27     
+ Misses       8884     8879       -5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/qcodes/dataset/sqlite/connection.py Outdated
Comment thread tests/dataset/test_sqlite_connection.py
Comment thread tests/conftest.py
Comment thread src/qcodes/dataset/sqlite/connection.py
AtomicConnection now registers itself in a weak set on creation and
removes itself on close. close_all_connections() closes all connections
that are still open, and get_open_connections() lists them.

The tests use an autouse fixture that closes all connections after each
test, replacing the gc.collect() calls that were used to release
connections that had gone out of scope.
The connection is already closed explicitly, so there is no need to
garbage collect to release it.
AtomicConnection now records the thread that created it, and
close_all_connections() only closes connections owned by the calling
thread, since sqlite connections cannot be closed from other threads.

close_all_connections() is registered as an atexit handler.

Complete the background-writer datasets in the concurrent dataset tests
so that the writer threads shut down and close their connections.
SQLiteSettings left the in-memory connection it opens on import open,
and some tests never closed plain sqlite3 connections.

Document why the unclosed database warning is still filtered in tests.
Use a reentrant registry lock, preserve pre-existing fixture connections, isolate subprocess configuration, and complete new test annotations.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Merged via the queue into microsoft:main with commit fbaaaee Oct 19, 2026
19 checks passed
@jenshnielsen
Jens Hedegaard Nielsen (jenshnielsen) deleted the cleanup_db_connections_simple branch October 19, 2026 11:52
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