nixos/test-runner: Fix thread cleanup

This commit is contained in:
Janne Heß 2021-10-23 18:46:51 +02:00
parent 663a0f328f
commit 1ed5606d8a
No known key found for this signature in database
GPG Key ID: 69165158F05265DF

View File

@ -8,7 +8,6 @@ import queue
import io import io
import threading import threading
import argparse import argparse
import atexit
import base64 import base64
import codecs import codecs
import os import os
@ -1128,11 +1127,13 @@ class Driver:
for cmd in cmd(start_scripts) for cmd in cmd(start_scripts)
] ]
@atexit.register def __enter__(self) -> "Driver":
def clean_up() -> None: return self
with rootlog.nested("clean up"):
for machine in self.machines: def __exit__(self, *_: Any) -> None:
machine.release() with rootlog.nested("cleanup"):
for machine in self.machines:
machine.release()
def subtest(self, name: str) -> Iterator[None]: def subtest(self, name: str) -> Iterator[None]:
"""Group logs under a given test name""" """Group logs under a given test name"""
@ -1307,14 +1308,13 @@ if __name__ == "__main__":
if not args.keep_vm_state: if not args.keep_vm_state:
rootlog.info("Machine state will be reset. To keep it, pass --keep-vm-state") rootlog.info("Machine state will be reset. To keep it, pass --keep-vm-state")
driver = Driver( with Driver(
args.start_scripts, args.vlans, args.testscript.read_text(), args.keep_vm_state args.start_scripts, args.vlans, args.testscript.read_text(), args.keep_vm_state
) ) as driver:
if args.interactive:
if args.interactive: ptpython.repl.embed(driver.test_symbols(), {})
ptpython.repl.embed(driver.test_symbols(), {}) else:
else: tic = time.time()
tic = time.time() driver.run_tests()
driver.run_tests() toc = time.time()
toc = time.time() rootlog.info(f"test script finished in {(toc-tic):.2f}s")
rootlog.info(f"test script finished in {(toc-tic):.2f}s")