[Notes] [Git][BuildStream/buildstream][Qinusty/531-fetch-retries-on-terminate] tests: Add tests for interrupting a fetch operation



Title: GitLab

Qinusty pushed to branch Qinusty/531-fetch-retries-on-terminate at BuildStream / buildstream

Commits:

3 changed files:

Changes:

  • tests/frontend/interruptions.py
    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"

  • tests/frontend/interruptions/elements/remote.bst
    1
    +kind: import
    
    2
    +
    
    3
    +sources:
    
    4
    +  - kind: git
    
    5
    +    track: master
    
    6
    +    ref: 03527d5afd967a94f95f2ee8f035236b387dd335
    
    7
    +    url: https://gitlab.com/BuildStream/buildstream.git
    \ No newline at end of file

  • tests/frontend/interruptions/project.conf
    1
    +name: interruptions
    
    2
    +element-path: elements
    \ No newline at end of file



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]