Exemple #1
0
def test_cpu_resources1(test_env):
    """2x 1cpu tasks on 1 cpu governor"""
    test_env.start(1)
    with test_env.client.new_session() as s:
        tasks.Sleep(blob("first"), 1.0)
        tasks.Sleep(blob("second"), 1.0)
        s.submit()
        test_env.assert_duration(1.9, 2.1, lambda: s.wait_all())
Exemple #2
0
def test_cpu_resources4(test_env):
    """1cpu + 2cpu tasks on 3 cpu governor"""
    test_env.start(1, n_cpus=3)
    with test_env.client.new_session() as s:
        tasks.Sleep(blob("first"), 1.0)
        tasks.Sleep(blob("second"), 1.0, cpus=2)
        s.submit()
        test_env.assert_duration(0.9, 1.1, lambda: s.wait_all())
Exemple #3
0
def test_sleep3_last(test_env):
    test_env.start(1)
    with test_env.client.new_session() as s:
        t1 = tasks.Sleep(blob("b"), 0.2)
        t2 = tasks.Sleep(t1, 0.2)
        t3 = tasks.Sleep(t2, 0.2)
        s.submit()
        test_env.assert_duration(0.4, 0.8, lambda: t3.wait())
Exemple #4
0
def test_fetch_removed_object_fails(test_env):
    test_env.start(1)
    with test_env.client.new_session() as s:
        t1 = tasks.Sleep(blob("abc123456"), 0.1)
        s.submit()
        with pytest.raises(RainException):
            t1.output.fetch()
        t1.wait()
Exemple #5
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(blob("abc123456"), 0.3)
        t1.output.keep()
        s.submit()
        result = test_env.assert_duration(0.028, 0.45,
                                          lambda: t1.output.fetch())
        assert result.get_bytes() == b"abc123456"
Exemple #6
0
def test_sleep1(test_env):
    """Sleep followed by wait"""
    test_env.start(1)
    with test_env.client.new_session() as s:
        b = blob("abc123456")
        t1 = tasks.Sleep(b, 0.3)
        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"
Exemple #7
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(t1, 0.5)
        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())
Exemple #8
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(t1, 0.3)
        s.submit()
        assert t1_output.is_kept() is True
        t1_output.unkeep()
        assert t1_output.is_kept() is False
        t2.wait()
Exemple #9
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(blob("test"), 0.4)
        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()
Exemple #10
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(t1, 1)
        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
Exemple #11
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(t1, 0.4)
        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()
Exemple #12
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:
        o1 = blob("abc123456")
        t1 = tasks.Sleep(o1, 0.4)
        t1.output.keep()
        s.submit()
        time.sleep(0.2)

        info = test_env.client.get_server_info()
        governors = info["governors"]
        assert len(governors) == 1
        assert governors[0]["tasks"] == [t1.spec.id]
        assert sorted(governors[0]["objects"]) == [o1.spec.id, t1.output.id]

        t1.wait()

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

        info = test_env.client.get_server_info()
        governors = info["governors"]
        assert len(governors) == 1
        assert governors[0]["tasks"] == []
        assert governors[0]["objects"] == [t1.output.id]

        t1.output.unkeep()

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

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