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

Integration tests for unstable-reconnecting-rpc-client #1711

Merged
merged 8 commits into from
Aug 30, 2024

Conversation

pkhry
Copy link
Contributor

@pkhry pkhry commented Aug 15, 2024

Description

Issue link

  1. Making sure that the reconnecting logic in Subxt is tested. This means testing the Backend impls, but also some of the structs returned that hande eg storage streams and making sure that they all work as expected. Let's unit test what we can, and if needbe we can create a mock RpcClient implementation and see how things respond to that returning an error or disconnecting.

I've plugged the new rpc client into integration tests behind a feature-flag.

Reconnection testing

I've added a few functions to have the ability to restart the substrate-node when needed in client tests, but so far it seems like handwriting a server with predetermined responses might be a better idea as node restarts can take upwards of 30-60s inside a test.

Copy link
Member

@niklasad1 niklasad1 left a comment

Choose a reason for hiding this comment

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

Cool,

So for me the MVP is to add one extra test for the unstable and stable backend where we restart the node and see that it's works as intended i.e, running all existing tests with reconnecting rpc client is not needed. I don't know what's the best to test for this but I suggest 1) block subscription, 2) kill/restart the node 3) check that block subscription works after reconnect

AFAIU, that may take 1-3 minutes to do as starting the node can be slow which should be acceptable since some other jobs are already quite slow because they run in parallel.

Bonus stuff as the first step would be to test that unstable backend emit an error when the block subscription misses blocks during "reconnect".

@@ -121,6 +121,9 @@ async fn transaction_validation() {

wait_for_blocks(&api).await;

#[cfg(feature = "unstable-reconnecting-rpc-client")]
let _ctx = ctx.restart().await;
Copy link
Member

Choose a reason for hiding this comment

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

I would rather create a separate test for unstable-reconnecting stuff than injecting it here.

Also this would remove all feature-gated stuff in this PR and just feature-gate the test itself

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed all the feature gating stuff and moved this to a separate test

@pkhry pkhry requested a review from niklasad1 August 22, 2024 23:19
Copy link
Member

@niklasad1 niklasad1 left a comment

Choose a reason for hiding this comment

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

nice, looks good

@pkhry pkhry marked this pull request as ready for review August 25, 2024 15:04
@pkhry pkhry requested a review from a team as a code owner August 25, 2024 15:04
Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
Comment on lines 436 to 439
signed_extrinsic
.validate()
.await
.expect("validation failed");
Copy link
Collaborator

Choose a reason for hiding this comment

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

.validate() obtains the latest block ref and then calls some runtime API, but I'm not sure how much that is testing the reconnecting logic, so curious what you think about this? I guess the point is that Subxt reconnects and doesn't start throwing out errors for every call, which is definitely a good start!

A couple of other tests that we might want to add:

  • Subscribe to storage entries and restart the node while streaming them, checking that you don't miss any inbetween or start over or whatever. (might require some setup though to get some storage entries of interest, or maybe subscribe to accountIds and expect the dev ones or something).

  • Subscribe to finalized blocks and restart while this is happening, checking that the block numbers of returned blocks follow eachother nicely regardless (though 6s block times means you'd probably not often screw up)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Subscribe to finalized blocks and restart while this is happening, checking that the block numbers of returned blocks follow eachother nicely regardless (though 6s block times means you'd probably not often screw up)

This will return a toplevel error instead of retrying in the stream currently.

Subscribe to storage entries and restart the node while streaming them, checking that you don't miss any inbetween or start over or whatever. (might require some setup though to get some storage entries of interest, or maybe subscribe to accountIds and expect the dev ones or something).
I've rewritten the test to check that clients follow the same rules for streaming finalized blocks

Copy link
Collaborator

@jsdw jsdw left a comment

Choose a reason for hiding this comment

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

Generally looks good to me, and a good foundation for adding some more integration tests around restarting! Mainly I just have a Q about whether we need the feature flag, and what test(s) are best to have (though happy to start with the test you added and then add some more)!

@pkhry pkhry merged commit 9ea7b14 into master Aug 30, 2024
13 checks passed
@pkhry pkhry deleted the pkhry/test-unstable-reconnecting-rpc branch August 30, 2024 08:16
@jsdw jsdw mentioned this pull request Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants