File: test_runners.py

package info (click to toggle)
hiro 1.1.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 452 kB
  • sloc: python: 2,006; sh: 54; makefile: 30
file content (70 lines) | stat: -rw-r--r-- 1,481 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""

"""
import time

import pytest

import hiro
from hiro.errors import SegmentNotComplete


def test_scale_up_sync_runner():
    def _slow_func():
        time.sleep(1)
        return 1

    f = hiro.run_sync(4, _slow_func)
    assert f.get_execution_time() < 1
    assert f.get_response() == 1


def test_scale_up_sync_runner_fail():
    def _slow_func():
        time.sleep(1)
        raise Exception("foo")

    f = hiro.run_sync(4, _slow_func)
    with pytest.raises(Exception):
        f.get_response()
    assert f.get_execution_time() < 1


def test_scale_up_async_runner():
    def _slow_func():
        time.sleep(1)

    f = hiro.run_threaded(4, _slow_func)
    assert f.is_running()
    f.join()
    assert f.get_execution_time() < 1


def test_scale_up_async_runner_fail():
    def _slow_func():
        time.sleep(1)
        raise Exception("foo")

    f = hiro.run_threaded(4, _slow_func)
    assert f.is_running()
    f.join()
    with pytest.raises(Exception):
        f.get_response()
    assert f.get_execution_time() < 1


def test_segment_not_complete_error():
    def _slow_func():
        time.sleep(1)
        raise Exception("foo")

    f = hiro.run_threaded(4, _slow_func)
    with pytest.raises(SegmentNotComplete):
        f.get_execution_time()
    with pytest.raises(SegmentNotComplete):
        f.get_response()
    assert f.is_running()
    f.join()
    with pytest.raises(Exception):
        f.get_response()
    assert f.get_execution_time() < 1