示例#1
0
def test_cpu_resources1(test_env):
    """2x 1cpu tasks on 1 cpu worker"""
    test_env.start(1)
    with test_env.client.new_session() as s:
        tasks.sleep(1.0, blob("first"))
        tasks.sleep(1.0, blob("second"))
        s.submit()
        test_env.assert_duration(1.9, 2.1, lambda: s.wait_all())
示例#2
0
def test_sleep3_last(test_env):
    test_env.start(1)
    with test_env.client.new_session() as s:
        t1 = tasks.sleep(0.2, blob("b"))
        t2 = tasks.sleep(0.2, t1)
        t3 = tasks.sleep(0.2, t2)
        s.submit()
        test_env.assert_duration(0.4, 0.8, lambda: t3.wait())
示例#3
0
def test_cpu_resources4(test_env):
    """1cpu + 2cpu tasks on 3 cpu worker"""
    test_env.start(1, n_cpus=3)
    with test_env.client.new_session() as s:
        tasks.sleep(1.0, blob("first"))
        tasks.sleep(1.0, blob("second"), cpus=2)
        s.submit()
        test_env.assert_duration(0.9, 1.1, lambda: s.wait_all())
示例#4
0
def test_cpu_resources2(test_env):
    """2x 1cpu tasks on 2 cpu governor"""
    test_env.start(1, n_cpus=2)
    with test_env.client.new_session() as s:
        tasks.sleep(1.0, blob("first"))
        tasks.sleep(1.0, blob("second"))
        s.submit()
        test_env.assert_duration(0.9, 1.1, lambda: s.wait_all())
示例#5
0
def test_fetch_removed_object_fails(test_env):
    test_env.start(1)
    with test_env.client.new_session() as s:
        t1 = tasks.sleep(0.01, blob("abc123456"))
        s.submit()
        with pytest.raises(RainException):
            t1.output.fetch()
        t1.wait()
示例#6
0
def test_sleep2(test_env):
    """Sleep followed by fetch (without explicit wait)"""
    test_env.start(1)
    with test_env.client.new_session() as s:
        t1 = tasks.sleep(0.3, blob("abc123456"))
        t1.output.keep()
        s.submit()
        result = test_env.assert_duration(0.028, 0.45,
                                          lambda: t1.output.fetch())
        assert result.get_bytes() == b"abc123456"
示例#7
0
def test_sleep1(test_env):
    """Sleep followed by wait"""
    test_env.start(1)
    with test_env.client.new_session() as s:
        t1 = tasks.sleep(0.3, blob("abc123456"))
        t1.output.keep()
        s.submit()
        test_env.assert_duration(0.2, 0.4, lambda: t1.wait())
        result = test_env.assert_max_duration(0.2, lambda: t1.output.fetch())
        assert result.get_bytes() == b"abc123456"
示例#8
0
def test_wait_all(test_env):
    test_env.start(1)
    client = test_env.client
    s = client.new_session()
    with s:
        t1 = tasks.concat((blob("a"), blob("b")))
        t2 = tasks.sleep(0.5, t1)
        s.submit()
        test_env.assert_duration(0.35, 0.65, lambda: s.wait_all())
        assert t1.state == rpc.common.TaskState.finished
        assert t2.state == rpc.common.TaskState.finished
        test_env.assert_max_duration(0.1, lambda: t2.wait())
示例#9
0
def test_unkeep_unfinished(test_env):
    test_env.start(1)
    client = test_env.client
    s = client.new_session()
    with s:
        t1 = tasks.concat((blob("a"), blob("b")))
        t1_output = t1.output
        t1_output.keep()
        t2 = tasks.sleep(0.3, t1)
        s.submit()
        assert t1_output.is_kept() is True
        t1_output.unkeep()
        assert t1_output.is_kept() is False
        t2.wait()
示例#10
0
def test_early_wait_all_failed_(test_env):
    test_env.start(1)
    client = test_env.client
    s = client.new_session()
    with s:
        t0 = tasks.sleep(0.4, blob("test"))
        args = ("/bin/non-existing-program")
        program = Program(args, stdout="output", stdin="input")
        t1 = program(input=t0)
        t1_output = t1.output
        t1_output.keep()
        s.submit()
        with pytest.raises(TaskException):
            s.wait_all()
示例#11
0
def test_submit(test_env):
    test_env.no_final_check()
    test_env.start(1)
    client = test_env.client
    s = client.new_session()
    with s:
        t1 = tasks.concat((blob("a"), blob("b")))
        t2 = tasks.sleep(1, t1)
        assert s.task_count == 2
        assert s.dataobj_count == 4  # "a", "b", "ab", "ab"
        s.submit()
        assert s.task_count == 0
        assert s.dataobj_count == 0
        assert t1.state == rpc.common.TaskState.notAssigned
        assert t2.state == rpc.common.TaskState.notAssigned
示例#12
0
def test_wait_some(test_env):
    test_env.start(1)
    client = test_env.client
    s = client.new_session()
    with s:
        t1 = tasks.concat(("a", "b"))
        t2 = tasks.sleep(0.4, t1)
        s.submit()
        finished = s.wait_some((t1, ), ())
        assert t1.state == rpc.common.TaskState.finished
        assert t2.state == rpc.common.TaskState.notAssigned
        assert len(finished) == 2
        assert len(finished[0]) == 1
        assert len(finished[1]) == 0
        assert finished[0][0].id == t1.id
        t2.wait()
示例#13
0
def test_number_of_tasks_and_objects(test_env):
    """Sleep followed by wait"""
    test_env.start(1, delete_list_timeout=0)
    with test_env.client.new_session() as s:
        t1 = tasks.sleep(0.4, blob("abc123456"))
        t1.output.keep()
        s.submit()
        time.sleep(0.2)

        info = test_env.client.get_server_info()
        workers = info["workers"]
        assert len(workers) == 1
        assert workers[0]["tasks"] == [(1, 12)]
        assert sorted(workers[0]["objects"]) == [(1, 10), (1, 11)]

        t1.wait()

        # Timeout is expected as big as necessary to cleanup
        # Worker caches
        time.sleep(2)

        info = test_env.client.get_server_info()
        workers = info["workers"]
        assert len(workers) == 1
        assert workers[0]["tasks"] == []
        assert workers[0]["objects"] == [(1, 11)]

        t1.output.unkeep()

        # Timeout is expected as big as necessary to cleanup
        # Worker caches
        time.sleep(4)

        info = test_env.client.get_server_info()
        workers = info["workers"]
        assert len(workers) == 1
        assert workers[0]["tasks"] == []
        assert workers[0]["objects"] == []