From 4821026db62c8a7f3a164eb906e260fe8e8a3e5c Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Tue, 5 Jun 2018 11:23:37 -0700 Subject: [PATCH] Fix bwrap leak test Our checking of processes during bwrap leak testing is racy. We handle these races by ignoring a couple exceptions that may happen due to things moving while we iterate over them. However if this happens the first time through the loop sleep_proc won't ever be set then we check its value which is itself an exception. Address this by checking the value of sleep_proc within the try block so that we know no exceptions due to races occured and the value is set. Change-Id: Iea6c7539dceaa3939dcdef5abeccff6481f837f8 --- tests/unit/test_bubblewrap.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_bubblewrap.py b/tests/unit/test_bubblewrap.py index 8642bcfbfe..03d3eaba5b 100644 --- a/tests/unit/test_bubblewrap.py +++ b/tests/unit/test_bubblewrap.py @@ -74,10 +74,10 @@ class TestBubblewrap(testtools.TestCase): sleep_proc = [pid for pid in os.listdir("/proc") if os.path.isfile("/proc/%s/cmdline" % pid) and open("/proc/%s/cmdline" % pid).read() == cmdline] + if not sleep_proc: + break except FileNotFoundError: pass except ProcessLookupError: pass - if not sleep_proc: - break time.sleep(1)