mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2025-12-13 02:25:48 +08:00
mavsdk_tests: properly handle timeout
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import atexit
|
import atexit
|
||||||
import datetime
|
import datetime
|
||||||
|
import errno
|
||||||
import os
|
import os
|
||||||
import psutil
|
import psutil
|
||||||
import subprocess
|
import subprocess
|
||||||
@@ -55,11 +56,15 @@ class Runner:
|
|||||||
|
|
||||||
atexit.register(self.stop)
|
atexit.register(self.stop)
|
||||||
|
|
||||||
def wait(self, timeout_s):
|
def wait(self, timeout_min):
|
||||||
try:
|
try:
|
||||||
return self.process.wait(timeout=timeout_s)
|
return self.process.wait(timeout=timeout_min*60)
|
||||||
except subprocess.TimeoutExpired:
|
except subprocess.TimeoutExpired:
|
||||||
|
print("Timeout of {} min{} reached, stopping...".
|
||||||
|
format(timeout_min, "s" if timeout_min > 1 else ""))
|
||||||
self.stop()
|
self.stop()
|
||||||
|
print("stopped.")
|
||||||
|
return errno.ETIMEDOUT
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
atexit.unregister(self.stop)
|
atexit.unregister(self.stop)
|
||||||
@@ -166,7 +171,7 @@ def main():
|
|||||||
test_runner = TestRunner(os.getcwd(), args.log_dir, group)
|
test_runner = TestRunner(os.getcwd(), args.log_dir, group)
|
||||||
test_runner.start(group)
|
test_runner.start(group)
|
||||||
|
|
||||||
returncode = test_runner.wait(group['timeout_min']*60)
|
returncode = test_runner.wait(group['timeout_min'])
|
||||||
print("Test exited with {}".format(returncode))
|
print("Test exited with {}".format(returncode))
|
||||||
|
|
||||||
returncode = gazebo_runner.stop()
|
returncode = gazebo_runner.stop()
|
||||||
|
|||||||
Reference in New Issue
Block a user