Skip to content

Commit 4123ab5

Browse files
claudeCarreau
authored andcommitted
Make test_hist_file_config teardown deterministic
The test created a HistoryManager backed by a real file but never stopped its HistorySavingThread. The thread briefly holds a strong reference to the manager inside its polling loop, so the instance could survive the gc.collect() in the hmmax fixture teardown, making the instance-leak assertion fail intermittently. Stop the saving thread and close the database like the other tests in this file do, and drop the unreachable `HistoryManager.__max_inst` assignment that name-mangling never applied anyway. Fixes #15161 https://claude.ai/code/session_01AtmUVnQwZfjDBuUzF7TdGh
1 parent d073772 commit 4123ab5

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

tests/test_history.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,18 +263,25 @@ def test_hist_file_config(hmmax3):
263263
cfg = Config()
264264
tfile = tempfile.NamedTemporaryFile(delete=False)
265265
cfg.HistoryManager.hist_file = Path(tfile.name)
266+
hm = None
266267
try:
267268
hm = HistoryManager(shell=get_ipython(), config=cfg)
268269
assert hm.hist_file == cfg.HistoryManager.hist_file
269270
finally:
271+
if hm is not None:
272+
# Stop the saving thread and close the database, otherwise the
273+
# thread can briefly hold a strong reference to the manager,
274+
# making the instance-leak check in the fixture teardown flaky
275+
# (gh-15161).
276+
hm.save_thread.stop()
277+
hm.db.close()
270278
try:
271279
Path(tfile.name).unlink()
272280
except OSError:
273281
# same catch as in testing.tools.TempFileMixin
274282
# On Windows, even though we close the file, we still can't
275283
# delete it. I have no clue why
276284
pass
277-
HistoryManager.__max_inst = 1
278285

279286

280287
def test_histmanager_memory_fallback_reopens_db(hmmax3, tmp_path, caplog):

0 commit comments

Comments
 (0)