Skip to content

Commit 59c40cd

Browse files
authored
Use SIGTERM to end test process for yaml tests (#31650)
* Use SIGTERM to end test process for yaml tests fixes #31574 I tested it with chip all clusters-app and also matter.js and it works, also the case where it falls back to killing if process did not terminates after 10s * styling * typo fix
1 parent 57898b9 commit 59c40cd

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

scripts/tests/chiptest/test_definition.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import logging
1717
import os
1818
import shutil
19+
import subprocess
1920
import tempfile
2021
import threading
2122
import time
@@ -63,10 +64,7 @@ def stop(self):
6364
with self.cv_stopped:
6465
self.stopped = True
6566
self.cv_stopped.notify()
66-
self.process.kill()
67-
self.process.wait(10)
68-
self.process = None
69-
self.outpipe = None
67+
self.__terminateProcess()
7068
return True
7169
return False
7270

@@ -90,8 +88,7 @@ def waitForMessage(self, message):
9088
return True
9189

9290
def kill(self):
93-
if self.process:
94-
self.process.kill()
91+
self.__terminateProcess()
9592
self.killed = True
9693

9794
def wait(self, timeout=None):
@@ -158,6 +155,18 @@ def __updateSetUpCode(self):
158155
raise Exception("Unable to find QR code")
159156
self.setupCode = qrLine.group(1)
160157

158+
def __terminateProcess(self):
159+
if self.process:
160+
self.process.terminate() # sends SIGTERM
161+
try:
162+
self.process.wait(10)
163+
except subprocess.TimeoutExpired:
164+
logging.debug('Subprocess did not terminated on SIGTERM, killing it now')
165+
self.process.kill()
166+
self.process.wait(10)
167+
self.process = None
168+
self.outpipe = None
169+
161170

162171
class TestTarget(Enum):
163172
ALL_CLUSTERS = auto()

0 commit comments

Comments
 (0)