예제 #1
0
    async def _get_outputs(self, examples: List[Example]):
        """
    Run beam examples and keep their output.

    Call the backend to start code processing for the examples.
    Then receive code output.

    Args:
        examples: beam examples that should be run
    """
        await get_statuses(
            examples)  # run examples code and wait until all are executed
        client = GRPCClient()
        tasks = [
            client.get_run_output(example.pipeline_id) for example in examples
        ]
        outputs = await asyncio.gather(*tasks)

        tasks = [client.get_log(example.pipeline_id) for example in examples]
        logs = await asyncio.gather(*tasks)

        for output, example in zip(outputs, examples):
            example.output = output

        for log, example in zip(logs, examples):
            example.logs = log
예제 #2
0
파일: test_helper.py 프로젝트: umanium/beam
async def test__update_example_status(mock_grpc_client_run_code,
                                      mock_grpc_client_check_status):
    example = Example(name="file",
                      pipeline_id="pipeline_id",
                      sdk=SDK_UNSPECIFIED,
                      filepath="root/file.extension",
                      code="code",
                      output="output",
                      status=STATUS_UNSPECIFIED,
                      tag={"pipeline_options": "--key value"},
                      link="link")

    mock_grpc_client_run_code.return_value = "pipeline_id"
    mock_grpc_client_check_status.side_effect = [
        STATUS_VALIDATING, STATUS_FINISHED
    ]

    await _update_example_status(example, GRPCClient())

    assert example.pipeline_id == "pipeline_id"
    assert example.status == STATUS_FINISHED
    mock_grpc_client_run_code.assert_called_once_with(example.code,
                                                      example.sdk,
                                                      "--key value")
    mock_grpc_client_check_status.assert_has_calls([mock.call("pipeline_id")])
예제 #3
0
파일: helper.py 프로젝트: ecapoccia/beam
async def get_statuses(examples: List[Example]):
    """
  Receive status and update example.status and example.pipeline_id for
  each example

  Args:
      examples: beam examples for processing and updating statuses and
      pipeline_id values.
  """
    tasks = []
    client = GRPCClient()
    for example in examples:
        tasks.append(_update_example_status(example, client))
    await asyncio.gather(*tasks)
예제 #4
0
파일: ci_helper.py 프로젝트: kileys/beam
    async def _verify_examples_status(self, examples: List[Example]):
        """
    Verify statuses of beam examples.

    Check example.status for each examples. If the status of the example is:
    - STATUS_VALIDATION_ERROR/STATUS_PREPARATION_ERROR
      /STATUS_ERROR/STATUS_RUN_TIMEOUT: log error
    - STATUS_COMPILE_ERROR: get logs using GetCompileOutput request and
      log them with error.
    - STATUS_RUN_ERROR: get logs using GetRunError request and
      log them with error.

    Args:
        examples: beam examples that should be verified
    """
        count_of_verified = 0
        client = GRPCClient()
        verify_failed = False
        for example in examples:
            if example.status not in Config.ERROR_STATUSES:
                count_of_verified += 1
                continue
            if example.status == STATUS_VALIDATION_ERROR:
                logging.error("Example: %s has validation error",
                              example.filepath)
            elif example.status == STATUS_PREPARATION_ERROR:
                logging.error("Example: %s has preparation error",
                              example.filepath)
            elif example.status == STATUS_ERROR:
                logging.error("Example: %s has error during setup run builder",
                              example.filepath)
            elif example.status == STATUS_RUN_TIMEOUT:
                logging.error("Example: %s failed because of timeout",
                              example.filepath)
            elif example.status == STATUS_COMPILE_ERROR:
                err = await client.get_compile_output(example.pipeline_id)
                logging.error("Example: %s has compilation error: %s",
                              example.filepath, err)
            elif example.status == STATUS_RUN_ERROR:
                err = await client.get_run_error(example.pipeline_id)
                logging.error("Example: %s has execution error: %s",
                              example.filepath, err)
            verify_failed = True

        logging.info("Number of verified Playground examples: %s / %s",
                     count_of_verified, len(examples))
        logging.info("Number of Playground examples with some error: %s / %s",
                     len(examples) - count_of_verified, len(examples))
        if verify_failed:
            raise Exception("CI step failed due to errors in the examples")
예제 #5
0
파일: test_helper.py 프로젝트: melap/beam
async def test__update_example_status(mock_grpc_client_run_code,
                                      mock_grpc_client_check_status):
    example = Example("file", "pipeline_id", SDK_UNSPECIFIED,
                      "root/file.extension", "code", "output",
                      STATUS_UNSPECIFIED, {"name": "Name"})

    mock_grpc_client_run_code.return_value = "pipeline_id"
    mock_grpc_client_check_status.side_effect = [
        STATUS_VALIDATING, STATUS_FINISHED
    ]

    await _update_example_status(example, GRPCClient())

    assert example.pipeline_id == "pipeline_id"
    assert example.status == STATUS_FINISHED
    mock_grpc_client_run_code.assert_called_once_with(example.code,
                                                      example.sdk)
    mock_grpc_client_check_status.assert_has_calls([mock.call("pipeline_id")])
예제 #6
0
def test_grpc_client():
    """
    This test is to test whether grpc client works well when
        - our go node is started
        - peer's go node is started
        - peer's python grpc server is started
    To run this test, please ensure
        - we have started a grpc_server, by running `python grpc_server.py`
        - we have started two `sharding-p2p-poc` nodes, one with seed=0, rpcport=13000, and another
            with seed=1, rpcport=13001
    Scenario `broadcast`:
        When we call `grpc_client.broadcast`, it first calls our go node's `pubsub.publish`.
        Our go node will broadcast the data and return `is_successful`. After the data is relayed
        to peer's go node, the node will call its python's `grpc_server.receive`, and therefore
        peer's python side receive the data, and then returns `is_valid` to peer's go node.
    Scenario `request`:
        When we call `grpc_client.request`, it first calls our go node's `shardmanager.reuqest`.
        Our go node will ask peer's go node for the data. Peer's go node will call its
        python's `grpc_server.receive`, and therefore peer's python side receive the request,
        parse and handle the request, and then returns the corresponding data.
    """
    stub = make_grpc_stub()
    rpc_client = GRPCClient(stub)
    rpc_client.subscribe_shards([0, 1])
    rpc_client.unsubscribe_shards([0])
    assert 1 in rpc_client.get_subscribed_shards()
    # print(rpc_client.get_subscribed_shards())
    # print(rpc_client.subscribe_shards([40, 56]))  # RPC should fail when subscribing an invalid shard
    # print(rpc_client.get_subscribed_shards())
    # print(rpc_client.unsubscribe_shards([40]))
    # print(rpc_client.get_subscribed_shards())
    # print(rpc_client.broadcast_collation(56, 10, 5566, 100))
    # print(rpc_client.send_collation(56, 1, b'123'))

    # peer_id_0 = "QmS5QmciTXXnCUCyxud5eWFenUMAmvAWSDa1c7dvdXRMZ7"
    peer_id_1 = "QmexAnfpHrhMmAC5UNQVS8iBuUUgDrMbMY17Cck2gKrqeX"

    p2p_client = P2PClient(rpc_client)
    c1 = Collation(1, 2, b"\xbe\xef")
    assert p2p_client.broadcast_collation(c1)
    c2 = p2p_client.request_collation(peer_id_1, 1, 2, "")
    assert c2.shard_id == 1
    assert c2.period == 2