Skip to content
Snippets Groups Projects
Commit f84d4ffe authored by Qinusty's avatar Qinusty
Browse files

tests: Add tests for interrupting a fetch operation

This test is to help avoid a regression in this area, fetching should
terminate and not retry.
parent e218e4f5
No related branches found
No related tags found
No related merge requests found
Pipeline #28015278 failed
import pytest
import os
import signal
import re
import time
import multiprocessing as mp
from multiprocessing import Process
from multiprocessing.queues import Queue
from buildstream import _yaml
from tests.testutils import cli
DATA_DIR = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"interruptions",
)
def cli_run_in_process(cli, path, args):
def do_run(cli, path, args, queue):
result = cli.run(project=path, args=args)
queue.put(result.output)
queue.put(result.stderr)
queue = mp.Queue()
p = mp.Process(target=do_run, args=[cli, path, args, queue])
p.start()
return queue, p
@pytest.mark.datafiles(DATA_DIR)
def test_interrupt_fetch(cli, datafiles):
path = os.path.join(datafiles.dirname, datafiles.basename)
queue, proc = cli_run_in_process(cli, path, args=['--on-error', 'terminate',
'fetch', 'delaymock.bst'])
# Wait a few seconds, fetch should then be in progress. With DelayedMockSource
# fetch should take 20s unless terminated
time.sleep(3)
os.kill(proc.pid, signal.SIGINT)
# 10 second timeout
try:
output = queue.get(timeout=10)
stderr = queue.get(timeout=10)
except mp.queues.Empty:
assert False, 'Fetch failed to terminate'
matches = re.findall(r'FAILURE\s*Fetch', stderr)
assert len(matches), "Unexpected success"
matches = re.findall(r'STATUS\s*Fetch terminating', stderr)
assert len(matches) != 0, "Fetch failed to terminate"
assert len(matches) == 1, "Fetch attempted to terminate more than once"
kind: import
sources:
- kind: delayed
\ No newline at end of file
import time
from buildstream import Source, SourceError, Consistency
class DelayedMockSource(Source):
def configure(self, node):
pass
def preflight(self):
pass
def get_unique_key(self):
return {}
def get_consistency(self):
return Consistency.RESOLVED
def get_ref(self):
return None
def set_ref(self, ref, node):
pass
def fetch(self):
LOOP_FOR = 40
def prog_percent(prog):
return "{}%".format(float(i)/float(LOOP_FOR) * 100)
for i in range(LOOP_FOR):
time.sleep(0.5)
self.status("Mock Source progress {}".format(prog_percent(i)))
def stage(self, directory):
pass
def setup():
return DelayedMockSource
name: interruptions
element-path: elements
plugins:
- origin: local
path: plugins
sources:
delayed: 0
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment