Fix test_bubblewrap_leak
We've seen this test return a false positive, presumably because
the sleep process is not immediately reaped by the bubblewrap
pid 1 process. To compensate, sleep for much longer (60s), and
give bwrap 30 seconds to actually terminate the sleep. As long
as we verify the sleep ends early, this test should be valid.
Change-Id: I828cc0b9c34a4ebc34d8432a776f2cd6e642b399
diff --git a/tests/unit/test_bubblewrap.py b/tests/unit/test_bubblewrap.py
index 675221e..d94b3f2 100644
--- a/tests/unit/test_bubblewrap.py
+++ b/tests/unit/test_bubblewrap.py
@@ -15,10 +15,12 @@
import subprocess
import tempfile
import testtools
+import time
import os
from zuul.driver import bubblewrap
from zuul.executor.server import SshAgent
+from tests.base import iterate_timeout
class TestBubblewrap(testtools.TestCase):
@@ -61,12 +63,15 @@
po = bwrap.getPopen(work_dir=work_dir,
ansible_dir=ansible_dir,
ssh_auth_sock=ssh_agent.env['SSH_AUTH_SOCK'])
- leak_time = 7
+ leak_time = 60
# Use hexadecimal notation to avoid false-positive
true_proc = po(['bash', '-c', 'sleep 0x%X & disown' % leak_time])
self.assertEqual(0, true_proc.wait())
cmdline = "sleep\x000x%X\x00" % leak_time
- 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]
- self.assertEqual(len(sleep_proc), 0, "Processes leaked")
+ for x in iterate_timeout(30, "process to exit"):
+ 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
+ time.sleep(1)