test: test buildroot read_with_timeout function
- Added a new stage that is stuck in an infinite loop - Added two tests that use this stage and force a timeout
This commit is contained in:
parent
cd8f8681ad
commit
99c739fd60
2 changed files with 50 additions and 0 deletions
20
stages/org.osbuild.test.timeout
Normal file
20
stages/org.osbuild.test.timeout
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
"""
|
||||||
|
Test stage that is used for timeout tests
|
||||||
|
"""
|
||||||
|
|
||||||
|
import time
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def main():
|
||||||
|
|
||||||
|
print('Test stage output.')
|
||||||
|
while True:
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
r = main()
|
||||||
|
sys.exit(r)
|
||||||
|
|
@ -4,7 +4,10 @@
|
||||||
|
|
||||||
import pathlib
|
import pathlib
|
||||||
import os
|
import os
|
||||||
|
import select
|
||||||
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
from tempfile import TemporaryDirectory
|
from tempfile import TemporaryDirectory
|
||||||
|
|
||||||
|
|
@ -164,3 +167,30 @@ def test_proc_overrides(tempdir):
|
||||||
r = root.run(["cat", "/proc/cmdline"], monitor)
|
r = root.run(["cat", "/proc/cmdline"], monitor)
|
||||||
assert r.returncode == 0
|
assert r.returncode == 0
|
||||||
assert cmdline in r.output.strip()
|
assert cmdline in r.output.strip()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(not TestBase.can_bind_mount(), reason="root only")
|
||||||
|
def test_timeout(tempdir):
|
||||||
|
runner = detect_host_runner()
|
||||||
|
libdir = os.path.abspath(os.curdir)
|
||||||
|
var = pathlib.Path(tempdir, "var")
|
||||||
|
var.mkdir()
|
||||||
|
|
||||||
|
with BuildRoot("/", runner, libdir, var) as root:
|
||||||
|
|
||||||
|
READ_ONLY = select.POLLIN | select.POLLPRI | select.POLLHUP | select.POLLERR
|
||||||
|
poller = select.poll()
|
||||||
|
|
||||||
|
proc = subprocess.Popen(['python3', libdir + '/stages/org.osbuild.test.timeout'], stdout = subprocess.PIPE)
|
||||||
|
start = time.monotonic()
|
||||||
|
timeout = 4
|
||||||
|
poller.register(proc.stdout.fileno(), READ_ONLY)
|
||||||
|
with pytest.raises(TimeoutError):
|
||||||
|
root.read_with_timeout(proc, poller, start, timeout)
|
||||||
|
|
||||||
|
proc = subprocess.Popen(['python3', libdir + '/stages/org.osbuild.test.timeout'], stdout = subprocess.PIPE)
|
||||||
|
start = time.monotonic()
|
||||||
|
timeout = 0
|
||||||
|
poller.register(proc.stdout.fileno(), READ_ONLY)
|
||||||
|
with pytest.raises(TimeoutError):
|
||||||
|
root.read_with_timeout(proc, poller, start, timeout)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue