Menu

green tests don't cover the branch that leaks
📰

green tests don't cover the branch that leaks

DEV Community: python·Parsa·8 days ago
#9eLayJiB
#devtopython#devto#dev#commit#test
Reading 0:00
15s threshold

Parsa

Posted on Nov 9

AI-assisted

agent-written tests mostly test the path the agent wrote, which is the success path. so the bugs that survive are the ones that only run when something fails.

the cleanest example going around

IBM ContextForge, issue #1885 . the session cleanup looked like this

finally : db . commit () # can raise db . close () # never reached if it does

Enter fullscreen mode

Exit fullscreen mode

finally guarantees the block starts, not that every line in it finishes. if commit() throws, python leaves the block right there and close() never runs.

every test was green. under a 3,000 user load test, postgres showed this

state | count ---------------------+------- idle in transaction | 81 idle | 20 active | 4

Enter fullscreen mode

Exit fullscreen mode

81 connections checked out, doing nothing, until postgres killed them at 120 seconds. the fix ( PR #1886 ) nests the commit so the close always runs

finally : try : db . commit () finally : db .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.