Esempio n. 1
0
def test_cancel_runs_local(local_service, hello_world):
    """Test canceling runs using a local service."""
    # -- Setup ----------------------------------------------------------------
    #
    # Start two runs for the same group of the 'Hello World' workflow.
    with local_service() as api:
        user_1 = create_user(api)
        user_2 = create_user(api)
        workflow_id = hello_world(api).workflow_id
    with local_service(user_id=user_1) as api:
        group_id = create_group(api, workflow_id=workflow_id)
        run_1, _ = start_hello_world(api, group_id)
        run_2, _ = start_hello_world(api, group_id)
        # -- Ensure that there are two active runs
        r = api.runs().list_runs(group_id=group_id)
        assert len(r['runs']) == 2
    # -- Ensure that user 2 cannot cancel run 2 -------------------------------
    with local_service(user_id=user_2) as api:
        with pytest.raises(err.UnauthorizedAccessError):
            api.runs().cancel_run(run_id=run_1)
    with local_service(user_id=user_1) as api:
        # There are still two active runs.
        r = api.runs().list_runs(group_id=group_id, state=STATE_PENDING)
        assert len(r['runs']) == 2
    # -- Cancel run 2 ---------------------------------------------------------
    with local_service(user_id=user_1) as api:
        api.runs().cancel_run(run_id=run_2)
        r = api.runs().list_runs(group_id=group_id, state=STATE_PENDING)
        runs = r['runs']
        assert len(runs) == 1
        assert run_1 in [r['id'] for r in runs]
    # -- Error when canceling an inactive run ---------------------------------
    with local_service(user_id=user_1) as api:
        with pytest.raises(err.InvalidRunStateError):
            api.runs().cancel_run(run_id=run_2)
Esempio n. 2
0
def test_delete_runs_local(local_service, hello_world):
    """Test deleting runs."""
    # -- Setup ----------------------------------------------------------------
    #
    # Start two runs for a group of the 'Hello World' workflow. The first run
    # is active and the second run canceled.
    with local_service() as api:
        user_1 = create_user(api)
        user_2 = create_user(api)
        workflow_id = hello_world(api).workflow_id
    with local_service(user_id=user_1) as api:
        group_id = create_group(api, workflow_id=workflow_id)
        run_1, _ = start_hello_world(api, group_id)
        run_2, _ = start_hello_world(api, group_id)
        api.runs().cancel_run(run_id=run_2)
    # -- Ensure that we cannot delete an active run ---------------------------
    with local_service(user_id=user_1) as api:
        with pytest.raises(err.InvalidRunStateError):
            api.runs().delete_run(run_id=run_1)
        r = api.runs().list_runs(group_id=group_id, state=STATE_PENDING)
        assert len(r['runs']) == 1
    # -- Ensure that user 2 cannot delete run 1 -------------------------------
    with local_service(user_id=user_2) as api:
        with pytest.raises(err.UnauthorizedAccessError):
            api.runs().delete_run(run_id=run_2)
    # -- Delete run 1 ---------------------------------------------------------
    with local_service(user_id=user_1) as api:
        api.runs().delete_run(run_id=run_2)
        r = api.runs().list_runs(group_id=group_id)
        # The active run is not affected.
        assert len(r['runs']) == 1
    # -- Error when deleting an unknown run -----------------------------------
    with local_service(user_id=user_1) as api:
        with pytest.raises(err.UnknownRunError):
            api.runs().delete_run(run_id=run_2)
Esempio n. 3
0
def test_create_run_local(local_service, hello_world):
    """Test life cycle for successful run using the local service."""
    # -- Setup ----------------------------------------------------------------
    #
    # Start a new run for a group of the 'Hello World' workflow and set it into
    # success state.
    tmpdir = tempfile.mkdtemp()
    with local_service() as api:
        user_1 = create_user(api)
        user_2 = create_user(api)
        workflow_id = hello_world(api).workflow_id
    with local_service(user_id=user_1) as api:
        group_id = create_group(api, workflow_id=workflow_id, users=[user_1])
        run_id, file_id = start_hello_world(api, group_id)
        result = {'group': group_id, 'run': run_id}
        write_results(rundir=tmpdir,
                      files=[(result, None, 'results/data.json'),
                             ([group_id, run_id], 'txt/plain', 'values.txt')])
        api.runs().update_run(run_id=run_id,
                              state=api.runs().backend.success(
                                  run_id,
                                  files=['results/data.json', 'values.txt']),
                              rundir=tmpdir)
    assert not os.path.exists(tmpdir)
    # -- Validate run handle --------------------------------------------------
    with local_service(user_id=user_1) as api:
        r = api.runs().get_run(run_id=run_id)
        serialize.validate_run_handle(r, st.STATE_SUCCESS)
        assert is_fh(r['arguments'][0]['value'])
    # -- Error when non-member attempts to access run -------------------------
    with local_service(user_id=user_2) as api:
        with pytest.raises(err.UnauthorizedAccessError):
            api.runs().get_run(run_id=run_id)
Esempio n. 4
0
def test_list_runs_local(local_service, hello_world):
    """Test listing runs."""
    # -- Setup ----------------------------------------------------------------
    #
    # Start one run each for two separate groups of the 'Hello World' workflow.
    with local_service() as api:
        user_1 = create_user(api)
        user_2 = create_user(api)
        workflow_id = hello_world(api).workflow_id
    with local_service(user_id=user_1) as api:
        group_1 = create_group(api, workflow_id=workflow_id)
        run_1, _ = start_hello_world(api, group_1)
    with local_service(user_id=user_2) as api:
        group_2 = create_group(api, workflow_id=workflow_id)
        run_2, _ = start_hello_world(api, group_2)
    # Define expected run listing for each group.
    runs = [(group_1, run_1, user_1), (group_2, run_2, user_2)]
    for group_id, run_id, user_id in runs:
        # -- Get run listing for group ----------------------------------------
        with local_service(user_id=user_id) as api:
            r = api.runs().list_runs(group_id)
            serialize.validate_run_listing(r)
            assert len(r['runs']) == 1
            r['runs'][0]['id'] == run_id
    # Start additional runs for group 1. Then set the run into error state.
    with local_service(user_id=user_1) as api:
        run_3, _ = start_hello_world(api, group_1)
        error_state = api.runs().backend.error(run_3, ['some errors'])
        api.runs().update_run(run_3, error_state)
    # -- Group 1 now has two runs, one in pending state and one in error state
    with local_service(user_id=user_1) as api:
        r = api.runs().list_runs(group_1)
        assert len(r['runs']) == 2
        runs = [(r['id'], r['state']) for r in r['runs']]
        assert (run_1, st.STATE_PENDING) in runs
        assert (run_3, st.STATE_ERROR) in runs
    # -- Group 2 remains unchnaged --------------------------------------------
    with local_service(user_id=user_2) as api:
        r = api.runs().list_runs(group_2)
        assert len(r['runs']) == 1
    # -- Error when listing runs for group as non-member ----------------------
    with local_service(user_id=user_2) as api:
        with pytest.raises(err.UnauthorizedAccessError):
            api.runs().list_runs(group_1)
Esempio n. 5
0
def test_create_run_local(local_service, hello_world):
    """Test life cycle for successful run using the local service."""
    # -- Setup ----------------------------------------------------------------
    #
    # Start a new run for a group of the 'Hello World' workflow and set it into
    # success state.
    fs = FileSystemStorage(basedir=tempfile.mkdtemp())
    with local_service() as api:
        user_1 = create_user(api)
        user_2 = create_user(api)
        workflow_id = hello_world(api).workflow_id
    with local_service(user_id=user_1) as api:
        group_id = create_group(api, workflow_id=workflow_id, users=[user_1])
        run_id, file_id = start_hello_world(api, group_id)
        result = {'group': group_id, 'run': run_id}
        write_results(runstore=fs,
                      files=[(result, None, 'results/data.json'),
                             ({
                                 'avg_count': 3.5,
                                 'max_len': 30
                             }, None, 'results/analytics.json'),
                             ([group_id, run_id], 'txt/plain', 'values.txt')])
        api.runs().update_run(run_id=run_id,
                              state=api.runs().backend.success(
                                  run_id,
                                  files=['results/data.json', 'values.txt']),
                              runstore=fs)
    # -- Validate run handle --------------------------------------------------
    with local_service(user_id=user_1) as api:
        r = api.runs().get_run(run_id=run_id)
        serialize.validate_run_handle(r, st.STATE_SUCCESS)
        assert is_fh(r['arguments'][0]['value'])
    # -- Error when non-member attempts to access run -------------------------
    with local_service(user_id=user_2) as api:
        with pytest.raises(err.UnauthorizedAccessError):
            api.runs().get_run(run_id=run_id)
    # -- Error for run with invalid arguments ---------------------------------
    with local_service(user_id=user_1) as api:
        with pytest.raises(err.DuplicateArgumentError):
            api.runs().start_run(group_id=group_id,
                                 arguments=[{
                                     'name': 'sleeptime',
                                     'value': 1
                                 }, {
                                     'name': 'sleeptime',
                                     'value': 2
                                 }])['id']