|
1
|
+import pytest
|
|
2
|
+import os
|
|
3
|
+import signal
|
|
4
|
+import re
|
|
5
|
+import time
|
|
6
|
+import multiprocessing as mp
|
|
7
|
+from multiprocessing import Process
|
|
8
|
+from multiprocessing.queues import Queue
|
|
9
|
+
|
|
10
|
+from buildstream import _yaml
|
|
11
|
+from tests.testutils import cli
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+DATA_DIR = os.path.join(
|
|
15
|
+ os.path.dirname(os.path.realpath(__file__)),
|
|
16
|
+ "interruptions",
|
|
17
|
+)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+def cli_run_in_process(cli, path, args):
|
|
21
|
+ def do_run(cli, path, args, queue):
|
|
22
|
+ result = cli.run(project=path, args=args)
|
|
23
|
+ queue.put(result.output)
|
|
24
|
+ queue.put(result.stderr)
|
|
25
|
+
|
|
26
|
+ queue = mp.Queue()
|
|
27
|
+ p = mp.Process(target=do_run, args=[cli, path, args, queue])
|
|
28
|
+ p.start()
|
|
29
|
+ return queue, p
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+@pytest.mark.datafiles(DATA_DIR)
|
|
33
|
+def test_interrupt_fetch(cli, datafiles):
|
|
34
|
+ path = os.path.join(datafiles.dirname, datafiles.basename)
|
|
35
|
+
|
|
36
|
+ queue, proc = cli_run_in_process(cli, path, args=['--on-error', 'terminate',
|
|
37
|
+ 'fetch', 'remote.bst'])
|
|
38
|
+ time.sleep(1)
|
|
39
|
+ os.kill(proc.pid, signal.SIGINT)
|
|
40
|
+
|
|
41
|
+ # 5 second timeout
|
|
42
|
+ try:
|
|
43
|
+ output = queue.get(timeout=3)
|
|
44
|
+ stderr = queue.get(timeout=3)
|
|
45
|
+ except mp.queues.Empty:
|
|
46
|
+ assert False, 'Fetch failed to terminate'
|
|
47
|
+ assert output is not None
|
|
48
|
+
|
|
49
|
+ matches = re.findall('FAILURE Fetch', stderr)
|
|
50
|
+ assert len(matches), "Unexpected success"
|
|
51
|
+
|
|
52
|
+ matches = re.findall(r'STATUS\s*Fetch terminating', stderr)
|
|
53
|
+ assert len(matches) != 0, "Fetch failed to terminate"
|
|
54
|
+ assert len(matches) == 1, "Fetch attempted to terminate more than once"
|