Skip to content

FIX: Fixing test that does not work properly / Failing in connection pool#564

Open
subrata-ms wants to merge 2 commits into
mainfrom
subrata-ms/EnablingSkipTestConnPool
Open

FIX: Fixing test that does not work properly / Failing in connection pool#564
subrata-ms wants to merge 2 commits into
mainfrom
subrata-ms/EnablingSkipTestConnPool

Conversation

@subrata-ms
Copy link
Copy Markdown
Contributor

@subrata-ms subrata-ms commented May 11, 2026

Work Item / Issue Reference

AB#40818

GitHub Issue: #<ISSUE_NUMBER>


Summary

This pull request significantly improves the reliability and accuracy of the connection pooling tests by running certain tests in isolated subprocesses and updating their logic to more robustly verify pooling behavior. The changes address issues with flaky or unreliable tests, ensure proper cleanup of pooled connections, and use more precise session identity checks.

Test infrastructure improvements:

  • Added a helper function _run_in_subprocess to execute test bodies in fresh Python subprocesses, ensuring that pooling configuration is isolated and not affected by previous tests. This is crucial because the pooling settings are locked in for the lifetime of the process due to the underlying C++ implementation.

Connection pooling test robustness:

  • Refactored test_pool_idle_timeout_removes_connections to run in a subprocess and to use a unique session identity (SPID and login_time) instead of just SPID, making the test more reliable against SQL Server's SPID reuse.
  • Refactored test_pool_removes_invalid_connections to run in a subprocess and simulate server-side session termination using KILL, then verify that the pool never returns a killed session. The test now uses only public APIs and is more realistic and robust.

Password handling in tests:

  • Improved password handling in test_pool_recovery_after_failed_connection by using a case-insensitive regular expression to modify the password in the connection string, ensuring compatibility with various ODBC connection string formats.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request updates the connection pooling test suite to reduce flakiness by isolating certain pooling-dependent tests into fresh subprocesses and by using more robust session identity checks when validating pool behavior.

Changes:

  • Added a _run_in_subprocess helper to run pooling tests in isolated Python processes so pooling(...) configuration isn’t affected by earlier tests.
  • Refactored the idle-timeout pooling test to validate session replacement using (SPID, login_time) instead of SPID alone.
  • Refactored the invalid-connection pooling test to simulate server-side session termination via KILL and verify the pool does not return the killed session; improved password mutation logic in a recovery test using a case-insensitive regex.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_009_pooling.py Outdated
Comment thread tests/test_009_pooling.py
Comment on lines +467 to +476
# KILL is processed asynchronously on the server. Poll until the
# victim's session has actually disappeared from sys.dm_exec_sessions
# before returning anything to the pool.
deadline = time.monotonic() + 10.0
while time.monotonic() < deadline:
row = admin.cursor().execute(
"SELECT COUNT(*) FROM sys.dm_exec_sessions WHERE session_id = ?",
victim_spid,
).fetchone()
if row[0] == 0:
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 11, 2026

📊 Code Coverage Report

🔥 Diff Coverage

100%


🎯 Overall Coverage

79%


📈 Total Lines Covered: 6860 out of 8636
📁 Project: mssql-python


Diff Coverage

Diff: main...HEAD, staged and unstaged changes

No lines with coverage information in this diff.


📋 Files Needing Attention

📉 Files with overall lowest coverage (click to expand)
mssql_python.pybind.logger_bridge.cpp: 59.2%
mssql_python.pybind.ddbc_bindings.h: 67.9%
mssql_python.row.py: 70.5%
mssql_python.pybind.logger_bridge.hpp: 70.8%
mssql_python.pybind.ddbc_bindings.cpp: 74.6%
mssql_python.pybind.connection.connection.cpp: 76.2%
mssql_python.__init__.py: 77.3%
mssql_python.ddbc_bindings.py: 79.6%
mssql_python.pybind.connection.connection_pool.cpp: 79.6%
mssql_python.connection.py: 85.3%

🔗 Quick Links

⚙️ Build Summary 📋 Coverage Details

View Azure DevOps Build

Browse Full Coverage Report

sumitmsft
sumitmsft previously approved these changes May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-size: medium Moderate update size

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants