示例#1
0
def cluster_fixture_aux(config_path, data_folder, cmd):
    base_port = gen_base_port()
    print("init cluster at", data_folder, ", base port:", base_port)
    cluster.init_cluster(data_folder, config_path, base_port, cmd=cmd)

    config = yaml.safe_load(open(config_path))
    clis = {}
    for key in config:
        chain_id = key
        clis[chain_id] = cluster.ClusterCLI(data_folder, chain_id=chain_id, cmd=cmd)

    supervisord = cluster.start_cluster(data_folder)

    try:
        for cli in clis.values():
            # wait for first node rpc port available before start testing
            wait_for_port(rpc_port(cli.config["validators"][0]["base_port"]))
            # wait for first node grpc port available before start testing
            wait_for_port(grpc_port(cli.config["validators"][0]["base_port"]))
            # wait for the first block generated before start testing
            wait_for_block(cli, 2)

        if len(clis) == 1:
            yield list(clis.values())[0]
        else:
            yield clis
    finally:
        supervisord.terminate()
        supervisord.wait()
示例#2
0
def cluster_fixture(
    config_path,
    base_port,
    tmp_path_factory,
    quiet=False,
    post_init=None,
    enable_cov=None,
):
    if enable_cov is None:
        enable_cov = os.environ.get("GITHUB_ACTIONS") == "true"
    config = yaml.safe_load(open(config_path))
    data = tmp_path_factory.mktemp(config["chain_id"])
    print("init cluster at", data, ", base port:", base_port)
    cluster.init_cluster(data, config, base_port)

    if post_init:
        post_init(config, data)

    if enable_cov:
        # replace the first node with the instrumented binary
        ini = data / cluster.SUPERVISOR_CONFIG_FILE
        ini.write_text(
            re.sub(
                r"^command = (.*/)?chain-maind",
                "command = chain-maind-inst -test.coverprofile=%(here)s/coverage.txt",
                ini.read_text(),
                count=1,
                flags=re.M,
            )
        )
        begin = time.time()

    supervisord = cluster.start_cluster(data)
    if not quiet:
        tailer = cluster.TailLogsThread([str(data / "node*.log")])
        tailer.start()
    # wait for first node rpc port available before start testing
    wait_for_port(rpc_port(config["validators"][0]["base_port"]))
    cli = cluster.ClusterCLI(data)
    # wait for first block generated before start testing
    wait_for_block(cli, 1)

    yield cli

    if enable_cov:
        # wait for server startup complete to generate the coverage report
        duration = time.time() - begin
        if duration < 15:
            time.sleep(15 - duration)

    supervisord.terminate()
    supervisord.wait()

    if not quiet:
        tailer.stop()
        tailer.join()

    if enable_cov:
        # collect the coverage results
        shutil.move(str(data / "coverage.txt"), f"coverage.{uuid.uuid1()}.txt")
示例#3
0
def cluster_fixture(config_path, base_port, tmp_path_factory, quiet=False):
    config = yaml.safe_load(open(config_path))
    data = tmp_path_factory.mktemp(config["chain_id"])
    print("init cluster at", data, ", base port:", base_port)
    cluster.init_cluster(data, config, base_port)

    # replace the first node with the instrumented binary
    ini = data / cluster.SUPERVISOR_CONFIG_FILE
    ini.write_text(
        re.sub(
            r"^command = (.*/)?chain-maind",
            "command = chain-maind-inst -test.coverprofile=%(here)s/coverage.txt",
            ini.read_text(),
            count=1,
            flags=re.M,
        ))
    begin = time.time()

    supervisord = cluster.start_cluster(data, quiet=quiet)
    # wait for first node rpc port available before start testing
    wait_for_port(rpc_port(config["validators"][0]["base_port"]))
    cli = cluster.ClusterCLI(data)
    # wait for first block generated before start testing
    wait_for_block(cli, 1)

    yield cli

    duration = time.time() - begin
    # wait for server startup complete to generate the coverage report
    if duration < 15:
        time.sleep(15 - duration)

    supervisord.terminate()
    supervisord.wait()

    # collect the coverage results
    shutil.move(str(data / "coverage.txt"), f"coverage.{uuid.uuid1()}.txt")
示例#4
0
def cluster_fixture(
    config_path,
    base_port,
    tmp_path_factory,
    quiet=False,
    post_init=None,
    enable_cov=None,
):
    """
    init a single devnet
    """
    if enable_cov is None:
        enable_cov = os.environ.get("GITHUB_ACTIONS") == "true"
    data = tmp_path_factory.mktemp("data")
    print("init cluster at", data, ", base port:", base_port)
    cluster.init_cluster(data, config_path, base_port)

    config = yaml.safe_load(open(config_path))
    clis = {}
    for key in config:
        if key == "relayer":
            continue

        chain_id = key
        chain_data = data / chain_id

        if post_init:
            post_init(chain_id, chain_data)

        if enable_cov:
            # replace the first node with the instrumented binary
            ini = chain_data / cluster.SUPERVISOR_CONFIG_FILE
            ini.write_text(
                re.sub(
                    r"^command = (.*/)?chain-maind",
                    "command = chain-maind-inst "
                    "-test.coverprofile=%(here)s/coverage.txt",
                    ini.read_text(),
                    count=1,
                    flags=re.M,
                )
            )
        clis[chain_id] = cluster.ClusterCLI(data, chain_id)

    supervisord = cluster.start_cluster(data)
    if not quiet:
        tailer = cluster.start_tail_logs_thread(data)

    try:
        begin = time.time()
        for cli in clis.values():
            # wait for first node rpc port available before start testing
            wait_for_port(rpc_port(cli.config["validators"][0]["base_port"]))
            # wait for the first block generated before start testing
            wait_for_block(cli, 1)

        if len(clis) == 1:
            yield list(clis.values())[0]
        else:
            yield clis

        if enable_cov:
            # wait for server startup complete to generate the coverage report
            duration = time.time() - begin
            if duration < 15:
                time.sleep(15 - duration)
    finally:
        supervisord.terminate()
        supervisord.wait()
        if not quiet:
            tailer.stop()
            tailer.join()

    if enable_cov:
        # collect the coverage results
        shutil.move(str(chain_data / "coverage.txt"), f"coverage.{uuid.uuid1()}.txt")
示例#5
0
def cluster_fixture(
    config_path,
    worker_index,
    data,
    post_init=None,
    enable_cov=None,
    cmd=None,
):
    """
    init a single devnet
    """
    if enable_cov is None:
        enable_cov = os.environ.get("GITHUB_ACTIONS") == "true"
    base_port = gen_base_port(worker_index)
    print("init cluster at", data, ", base port:", base_port)
    cluster.init_cluster(data, config_path, base_port, cmd=cmd)

    config = yaml.safe_load(open(config_path))
    clis = {}
    for key in config:
        if key == "relayer":
            continue

        chain_id = key
        chain_data = data / chain_id

        if post_init:
            post_init(chain_id, chain_data)

        if enable_cov:
            # replace the first node with the instrumented binary
            ini = chain_data / cluster.SUPERVISOR_CONFIG_FILE
            ini.write_text(
                re.sub(
                    r"^command = (.*/)?chain-maind",
                    "command = chain-maind-inst "
                    "-test.coverprofile=%(here)s/coverage.txt",
                    ini.read_text(),
                    count=1,
                    flags=re.M,
                ))
        clis[chain_id] = cluster.ClusterCLI(data, chain_id=chain_id)

    supervisord = cluster.start_cluster(data)

    try:
        begin = time.time()
        for cli in clis.values():
            # wait for first node rpc port available before start testing
            wait_for_port(rpc_port(cli.config["validators"][0]["base_port"]))
            # wait for the first block generated before start testing
            wait_for_block(cli, 2)

        if len(clis) == 1:
            yield list(clis.values())[0]
        else:
            yield clis

        if enable_cov:
            # wait for server startup complete to generate the coverage report
            duration = time.time() - begin
            if duration < 15:
                time.sleep(15 - duration)
    finally:
        supervisord.terminate()
        supervisord.wait()

    if enable_cov:
        # collect the coverage results
        try:
            shutil.move(str(chain_data / "coverage.txt"),
                        f"coverage.{uuid.uuid1()}.txt")
        except FileNotFoundError:
            ts = time.time()
            st = datetime.datetime.fromtimestamp(ts).strftime(
                "%Y-%m-%d %H:%M:%S")
            print(st + " FAILED TO FIND COVERAGE")
            print(os.listdir(chain_data))
            data = [(int(p), c) for p, c in [
                x.rstrip("\n").split(" ", 1)
                for x in os.popen("ps h -eo pid:1,command")
            ]]
            print(data)