Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(nervous-system): make the ic-nervous-system-integration-tests tests async #1814

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

anchpop
Copy link
Contributor

@anchpop anchpop commented Oct 3, 2024

The problem

block_on in general is a bad practice imo - it constantly causes issues because it doesn't compose. A function called with block_on (or an async context) cannot call another function with block_on. This is not symmetrical with async - a sync function can call an async function using block_on, but an async function cannot call a sync function that uses block_on.

This is revelant to the the tests in ic-nervous-system-integration-tests because PocketIc in blocking mode (the default) uses block_on. This excludes the possibility of using it in an async context.

For a concrete example, we can’t currently use sns-audit in integration tests since it must work with ic-agent (which is async). This means that any functions called from sns-audit must work in an async context. It would be very nice to be able to use sns-audit in integration tests, since it would mean that we could have a centralized place to do the checks for “did the SNS get deployed the way it was supposed to” that could be used on mainnet and in tests. Using sns-audit in tests that would also mean that we would not be able to make a change to how SNSes are deployed that is breaking w.r.t. sns-audit without also fixing sns-audit (which we currently basically do not test for IIUC)

The solution

Use PocketIC in non-blocking mode. What this means generally is that you need to add .await and async everywhere. There are a lot of changes in this PR, but they almost all very mechanical.

In some cases we had closures that called blocking pocket_ic functions. These generally could be fixed by using async move.

The only non-mechanical change is that some places that used iterators had to be changed to use streams or just use traditional for i in range iteration.

@anchpop anchpop force-pushed the @anchpop/async-integration-tests branch from d507d8c to e795e28 Compare October 3, 2024 02:30
@anchpop anchpop force-pushed the @anchpop/async-integration-tests branch from e795e28 to df03c6f Compare October 3, 2024 02:35
@anchpop anchpop marked this pull request as ready for review October 3, 2024 03:02
@anchpop anchpop requested a review from a team as a code owner October 3, 2024 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant