From e76b9f3dde800b44c4151ebee9ff469b6714d8aa Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Fri, 21 Oct 2016 12:40:42 -0700 Subject: [PATCH 1/2] adb: fix race condition in test_non_interactive_sigint. Fix race condition in the test_non_interactive_sigint test by looping for a while. Bug: http://b/32336914 Test: python test_device.py Change-Id: Ie65a762ad6f04815231add5444762c4c0ffd31cb --- adb/test_device.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/adb/test_device.py b/adb/test_device.py index b12bf88b5..2f2a823bf 100644 --- a/adb/test_device.py +++ b/adb/test_device.py @@ -473,8 +473,12 @@ class ShellTest(DeviceTest): self.device.shell(proc_query) os.kill(sleep_proc.pid, signal.SIGINT) sleep_proc.communicate() - self.assertEqual(1, self.device.shell_nocheck(proc_query)[0], - 'subprocess failed to terminate') + + # It can take some time for the process to receive the signal and die. + end_time = time.time() + 3 + while self.device.shell_nocheck(proc_query)[0] != 1: + self.assertFalse(time.time() > end_time, + 'subprocess failed to terminate in time') def test_non_interactive_stdin(self): """Tests that non-interactive shells send stdin.""" From 470622f064a777e86f14079ff2864d3166980c16 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Fri, 21 Oct 2016 13:17:32 -0700 Subject: [PATCH 2/2] adb: fix test_sighup. Bug: http://b/32336914 Test: python test_device.py Change-Id: I34ba5757b5e650d79327dc6779064acd850ce28e --- adb/test_device.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/adb/test_device.py b/adb/test_device.py index 2f2a823bf..291e32929 100644 --- a/adb/test_device.py +++ b/adb/test_device.py @@ -511,13 +511,14 @@ class ShellTest(DeviceTest): trap "echo SIGINT > {path}; exit 0" SIGINT trap "echo SIGHUP > {path}; exit 0" SIGHUP echo Waiting - while true; do sleep 100; done + read """.format(path=log_path) script = ";".join([x.strip() for x in script.strip().splitlines()]) - process = self.device.shell_popen( - ["sh", "-c", "'{}'".format(script)], kill_atexit=False, stdout=subprocess.PIPE) + process = self.device.shell_popen([script], kill_atexit=False, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE) self.assertEqual("Waiting\n", process.stdout.readline()) process.send_signal(signal.SIGINT) @@ -525,7 +526,7 @@ class ShellTest(DeviceTest): # Waiting for the local adb to finish is insufficient, since it hangs # up immediately. - time.sleep(0.25) + time.sleep(1) stdout, _ = self.device.shell(["cat", log_path]) self.assertEqual(stdout.strip(), "SIGHUP")