Example #1
0
def test_chain_concat(test_env):
    test_env.start(1)
    with test_env.client.new_session() as s:
        t1 = tasks.Concat((blob("a"), blob("b")))
        t2 = tasks.Concat((t1, blob("c")))
        t3 = tasks.Concat((t2, blob("d")))
        t4 = tasks.Concat((t3, blob("e")))
        t5 = tasks.Concat((t4, blob("f")))
        t5.output.keep()
        s.submit()
        assert t5.output.fetch().get_bytes() == b"abcdef"
Example #2
0
def run_small_gridcat(session):
    BLOB_SIZE = 5000
    BLOB_COUNT = 10

    rnd = test_rnd()

    def random_string(rnd, length):
        return "".join(rnd.choice(CHARS) for i in range(length))

    cat = Program(("cat", Input("input1"), Input("input2")),
                  stdout="output")
    md5sum = Program("md5sum", stdin="input", stdout="output")

    @remote()
    def take_first(ctx, data):
        return data.get_bytes().split()[0]

    consts = [blob(random_string(rnd, BLOB_SIZE)) for i in range(BLOB_COUNT)]
    ts = []
    for i in range(BLOB_COUNT):
        for j in range(BLOB_COUNT):
            t1 = cat(input1=consts[i], input2=consts[j])
            t2 = md5sum(input=t1)
            t3 = take_first(t2)
            ts.append(t3.output)
    result = md5sum(input=tasks.Concat(ts))
    result.output.keep()
    #  session.pending_graph().write("/home/spirali/tmp/graph.dot")
    session.submit()
    result.output.fetch() == b"0a9612a2e855278d336a9e1a1589478f  -\n"
Example #3
0
def test_wait_unsubmitted_task(test_env):
    test_env.start(1)
    client = test_env.client
    s = client.new_session()
    with s:
        t1 = tasks.Concat(())
        with pytest.raises(RainException):
            t1.wait()
Example #4
0
def test_concat2(test_env):
    """Merge empty list of blobs"""
    test_env.start(1)
    with test_env.client.new_session() as s:
        t1 = tasks.Concat(())
        t1.output.keep()
        s.submit()
        assert t1.output.fetch().get_bytes() == b""
Example #5
0
def test_concat1(test_env):
    """Merge several short blobs"""
    test_env.start(1)
    with test_env.client.new_session() as s:
        t1 = tasks.Concat(
            [blob(x) for x in ("Hello ", "", "", "world", "!", "")])
        t1.output.keep()
        s.submit()
        assert t1.output.fetch().get_bytes() == b"Hello world!"
Example #6
0
def test_fetch_unsubmitted_task(test_env):
    test_env.start(1)
    client = test_env.client
    s = client.new_session()
    with s:
        t1 = tasks.Concat(())
        t1.keep_outputs()
        with pytest.raises(RainException):
            t1.fetch_outputs()
Example #7
0
def test_update(test_env):
    test_env.start(1)
    client = test_env.client
    s = client.new_session()
    with s:
        t1 = tasks.Concat((blob("a"), blob("b")))
        s.submit()
        s.update((t1,))
        t1.wait()
        s.update((t1,))
Example #8
0
def test_task_wait(test_env):
    test_env.start(1)
    client = test_env.client
    s = client.new_session()
    with s.bind_only():
        t1 = tasks.Concat((blob("a"), blob("b")))
    assert t1.state is None
    s.submit()
    assert t1.state == rpc.common.TaskState.notAssigned
    t1.wait()
    assert t1.state == rpc.common.TaskState.finished
Example #9
0
def test_dataobj_wait(test_env):
    test_env.start(1)
    client = test_env.client
    s = client.new_session()
    with s:
        t1 = tasks.Concat((blob("a"), blob("b")))
        o1 = t1.output
        assert t1.state is None
        s.submit()
        assert o1.state == rpc.common.DataObjectState.unfinished
        o1.wait()
        assert o1.state == rpc.common.DataObjectState.finished
Example #10
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())
Example #11
0
def test_concat3(test_env):
    """Merge large blobs"""
    test_env.start(1)
    a = b"a123456789" * 1024 * 1024
    b = b"b43" * 2500000
    c = b"c" * 1000
    d = b"d"
    with test_env.client.new_session() as s:
        t1 = tasks.Concat(
            (blob(a), blob(c), blob(d), blob(b), blob(c), blob(a)))
        t1.output.keep()
        s.submit()
        assert t1.output.fetch().get_bytes() == a + c + d + b + c + a
Example #12
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()
Example #13
0
def test_execute_termination(test_env):
    test_env.start(1)
    import time

    with test_env.client.new_session() as s:
        tasks.Execute("sleep 5")
        s.submit()
        time.sleep(0.5)

    with test_env.client.new_session() as s:
        t1 = tasks.Concat((blob("a"), blob("b")))
        t1.keep_outputs()
        s.submit()
        r = test_env.assert_max_duration(0.2, lambda: t1.output.fetch())
        assert b"ab" == r.get_bytes()
Example #14
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
Example #15
0
def test_task_export(test_env):
    import os.path
    test1 = os.path.join(test_env.work_dir, "TEST1")
    test2 = os.path.join(test_env.work_dir, "TEST2")
    test_env.start(1)
    with test_env.client.new_session() as s:
        a = blob("Hello ")
        b = blob("World!")
        tasks.Store(tasks.Concat((a, b)), test1)
        tasks.Store(tasks.Execute("ls /", stdout="output"), test2)
        s.submit()
        s.wait_all()
        with open(test1) as f:
            assert f.read() == "Hello World!"
        with open(test2) as f:
            assert "bin" in f.read()
Example #16
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()
Example #17
0
def test_big_diamond(test_env):

    @remote(outputs=("out1", "out2"))
    def splitter(ctx, data):
        data = data.get_bytes()
        left = data[0:len(data)]
        right = data[len(data):]
        return {"out1": left, "out2": right}

    @remote()
    def upper(ctx, data):
        return data.get_bytes().upper()

    LAYERS = 6
    rnd = test_rnd()
    data = random_string(rnd, 100).lower().encode()

    test_env.start(4)
    with test_env.client.new_session() as s:
        layer = [blob(data)]
        for i in range(LAYERS):
            new_layer = []
            for l in layer:
                task = splitter(l)
                new_layer.append(task.outputs["out1"])
                new_layer.append(task.outputs["out2"])
            layer = new_layer
        layer = [upper(t) for t in layer]

        for i in range(LAYERS):
            new_layer = []
            for j in range(0, len(layer), 2):
                new_layer.append(tasks.Concat((layer[j], layer[j + 1])))
            layer = new_layer
        #  s.pending_graph().write("test.dot")
        assert len(layer) == 1
        result = layer[0]
        result.output.keep()
        s.submit()
        result = result.output.fetch()
        assert result.get_bytes() == data.upper()