Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

feat: reworking test util #296

Merged
merged 6 commits into from
Oct 14, 2022
Merged

feat: reworking test util #296

merged 6 commits into from
Oct 14, 2022

Conversation

harrysolovay
Copy link
Contributor

@harrysolovay harrysolovay commented Oct 14, 2022

Reworks our approach to spawning test chains. Before, we were spawning in the same place that we were using. This excessive spawn/kill slowed down test execution. For our testing purposes, isolated test networks don't necessarily matter. If/when this becomes a requirement, we can manage this within test_ctx as well.

To run a network-dependent command, prefix the command with usage of the test_ctx CLI.

deno task run test_ctx.ts <your command here>

The test_ctx.ts starts a server, which is responsible for opening polkadot CLI processes on-demand. It also runs your command, passing in the server's hostname and port as env vars. Configs within test_util/configs use these env vars to request their respective runtimes' dev net ports. The subprocess then uses the config as normal. Upon the subprocess's exit, the test ctx process kills all polkadot process instances.

Sounds like a mouthful, I know. So why this approach?

The main reason is to support our codegen vision #226. Developers will be able to test their code with ease.

main.ts

import { polkadotPattern } from "https://deno.land/x/some-polkadot-pattern-lib/mod.ts";

const root = polkadotPattern(/* some usage here */);

Normally, the developer would run this with something such as deno run -A main.ts

To make use of the test env and configs, they need not touch the actual code:

deno run -A https://deno.land/x/capi/test_ctx.ts \
  deno run -A main.ts --import-map=./test_config_remappings.json

Related changes:

  • Moved the codegen CLI entrypoint to the root. Felt necessary given that we now expose a root-level test_ctx.ts CLI as well
  • Test util import alias t -> T (was conflicting with t context exposed from Deno.test)

@harrysolovay harrysolovay marked this pull request as ready for review October 14, 2022 15:54
test_ctx.ts Outdated Show resolved Hide resolved
kratico
kratico previously approved these changes Oct 14, 2022
Copy link
Contributor

@kratico kratico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

Co-authored-by: Matias Volpe <kratico@users.noreply.github.com>
kratico
kratico previously approved these changes Oct 14, 2022
@harrysolovay harrysolovay merged commit 8fe8176 into main Oct 14, 2022
@harrysolovay harrysolovay deleted the reworking_test_util branch October 14, 2022 21:57
harrysolovay added a commit that referenced this pull request Oct 19, 2022
Co-authored-by: Matias Volpe <kratico@users.noreply.github.com>
harrysolovay added a commit that referenced this pull request Oct 19, 2022
Co-authored-by: Matias Volpe <kratico@users.noreply.github.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants