Skip to content

Commit

Permalink
Bug 1846619 - Use mozprocess.run_and_wait in startup_test r=hneiva
Browse files Browse the repository at this point in the history
  • Loading branch information
gbrownmozilla committed Aug 16, 2023
1 parent 64c2363 commit 11d6514
Showing 1 changed file with 37 additions and 15 deletions.
52 changes: 37 additions & 15 deletions testing/mozharness/scripts/does_it_crash.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
Runs a thing to see if it crashes within a set period.
"""
import os
import signal
import subprocess
import sys

import requests

sys.path.insert(1, os.path.dirname(sys.path[0]))

import mozinstall
import mozprocess
from mozharness.base.script import BaseScript
from mozprocess import ProcessHandler


class DoesItCrash(BaseScript):
Expand Down Expand Up @@ -105,7 +107,32 @@ def download(self):
else:
self.install_dir = ""

def kill(self, proc):
is_win = os.name == "nt"
if is_win:
proc.send_signal(signal.CTRL_BREAK_EVENT)
else:
os.killpg(proc.pid, signal.SIGKILL)
try:
proc.wait(5)
self.log("process terminated")
except subprocess.TimeoutExpired:
self.error("unable to terminate process!")

def run_thing(self):

self.timed_out = False

def timeout_handler(proc):
self.log(f"timeout detected: killing pid {proc.pid}")
self.timed_out = True
self.kill(proc)

self.output = []

def output_line_handler(proc, line):
self.output.append(line)

thing = os.path.abspath(
os.path.join(self.install_dir, self.config["thing_to_run"])
)
Expand All @@ -114,26 +141,21 @@ def run_thing(self):
timeout = self.config["run_for"]

self.log(f"Running {thing} with args {args}")
p = ProcessHandler(
thing,
args=args,
shell=False,
storeOutput=True,
kill_on_timeout=True,
stream=False,
cmd = [thing]
cmd.extend(args)
mozprocess.run_and_wait(
cmd,
timeout=timeout,
timeout_handler=timeout_handler,
output_line_handler=output_line_handler,
)
p.run(timeout)
# Wait for the timeout + a grace period (to make sure we don't interrupt
# process tear down).
# Without this, this script could potentially hang
p.wait(timeout + 10)
if not p.timedOut:
if not self.timed_out:
# It crashed, oh no!
self.critical(
f"TEST-UNEXPECTED-FAIL: {thing} did not run for {timeout} seconds"
)
self.critical("Output was:")
for l in p.output:
for l in self.output:
self.critical(l)
self.fatal("fail")
else:
Expand Down

0 comments on commit 11d6514

Please sign in to comment.