-
Notifications
You must be signed in to change notification settings - Fork 129
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
chore(tests): refactor tests/utils/request_utils.go #2385
Conversation
Codecov Report
@@ Coverage Diff @@
## development #2385 +/- ##
===============================================
- Coverage 58.50% 58.47% -0.03%
===============================================
Files 214 214
Lines 28004 28004
===============================================
- Hits 16383 16375 -8
- Misses 9963 9971 +8
Partials 1658 1658
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
9342740
to
57016d9
Compare
@@ -38,13 +39,14 @@ type testCase struct { | |||
skip bool | |||
} | |||
|
|||
func getResponse(t *testing.T, test *testCase) interface{} { | |||
func getResponse(ctx context.Context, t *testing.T, test *testCase) interface{} { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could this function not just accept a time.Duration
for timeout and handle context creation and cancellation within this function? Doesn't look like the contexts are used for anything other than timeout functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes for now, but the idea I have at the back of my head is to use it with cancel()
in the future once it's more event-driven.
Context offer the flexibility of timeouts + event driven cancellation, and inherit from each other, so we should really be using them in e2e tests instead of timers/signal channels which would make a mess of a code especially regarding 'cascaded cancelation'.
Also contexts are part of the std library, and most standard library use them like http.NewRequestWithContext
or exec.CommandContext
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Further down the line in my branches, this context is actually used to cancel operations, for example if a node crashes unexpectedly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd argue that we shouldn't be using context for cancellation. Dave Cheney wrote about it in his blog.
The documentation for the context package strongly recommends that context.Context is only for request scoped values:
With regards to cascading cancellation, you can just have a cancel channel that is closed and can be listened on by multiple goroutines.
I know using contexts for cancellation is a common pattern. It's something to keep an eye on for Go 2. They may remove the cancellation from the context package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting blog post, and I 100% agree context values are the fruit of demoniac developers 👿 (except they're 100% needed for i.e. a server metrics given restrictive signatures of handlers).
It's also sad they didn't figure out how to wait for a goroutine to finish on context cancellation, forcing to still have another signal/error channel to wait.
Now for the closing of a signal channel, there are 3 limitations I can think of:
- Handling timers to close a channel is painful (always need to check to empty the timer channel as well), and even more when nesting them.
- You cannot close a channel multiple times, so you would have to pretty much re-invent contexts for this (check if the channel is closed etc.)
- The standard library accepts contexts to cancel IO operations, but not close channels and often have no easy
Stop
method. One could use a signal channel to cancel a context down the callers, but it feels wrong to me.
fd9d785
to
dc9ee5f
Compare
- Inject context to `PostRPC` and `PostRPCWithRetry` - Swap method and url arguments for `PostRPC` and `PostRPCWithRetry` - Remove some global variables - Wrap all possible errors - `PostRPCWithRetry` retries until context is canceled - Keep 1s timeout for RPC calls
Co-authored-by: Eclésio Junior <[email protected]>
dc9ee5f
to
1490e42
Compare
abd4bf0
to
318ed49
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm! just a small change
Co-authored-by: Eclésio Junior <[email protected]>
2072f51
to
13fcf3e
Compare
I am Quentin Mc Gaw, a software engineer working the Go Polkadot host **Gossamer**. I have been working full time on Gossamer since October 2021, mostly on the state trie and storage. I have also made a [few minor pull requests](https://github.com/w3f/polkadot-spec/pulls?q=is%3Apr+is%3Aclosed+author%3Aqdm12) to the Polkadot specification repository. I am requesting to join the Fellowship at rank 1. ## Main contributions ### Gossamer - Fix memory leaks - Trie encoding buffer pools usage fixed [#2009](ChainSafe/gossamer#2009) - Fix state map of tries memory leak [#2286](ChainSafe/gossamer#2286) - Fix sync benchmark [#2234](ChainSafe/gossamer#2234) - Trie proof fixes ([#2604](ChainSafe/gossamer#2604), [#2661](ChainSafe/gossamer#2661)) - Fix end to end tests orchestration ([#2470](ChainSafe/gossamer#2470), [#2452](ChainSafe/gossamer#2452), [#2385](ChainSafe/gossamer#2385), [#2370](ChainSafe/gossamer#2370)) - State trie statistics ([#2378](ChainSafe/gossamer#2378), [#2310](ChainSafe/gossamer#2310), [#2272](ChainSafe/gossamer#2272)) - State trie fixes and improvements - Only deep copy nodes when mutation is certain [#2352](ChainSafe/gossamer#2352) and [#2223](ChainSafe/gossamer#2223) - Only deep copy necessary fields of a node [#2384](ChainSafe/gossamer#2384) - Use Merkle values for database keys instead of always hash [#2725](ChainSafe/gossamer#2725) - Opportunistic parallel Merkle value commputing [#2081](ChainSafe/gossamer#2081) - Grandpa capped number of tracked messages ([#2490](ChainSafe/gossamer#2490), [#2485](ChainSafe/gossamer#2485)) - Add pprof HTTP service for profiling [#1991](ChainSafe/gossamer#1991) Ongoing work: - State trie lazy loading and caching - State trie v1 support ([#2736](ChainSafe/gossamer#2736), [#2747](ChainSafe/gossamer#2747), [#2687](ChainSafe/gossamer#2687), [#2686](ChainSafe/gossamer#2686), [#2685](ChainSafe/gossamer#2685), [#2673](ChainSafe/gossamer#2673), [#2611](ChainSafe/gossamer#2611), [#2530](ChainSafe/gossamer#2530)) ### Polkadot specification ➡️ [Pull requests from qdm12](https://github.com/w3f/polkadot-spec/pulls?q=is%3Apr+is%3Aclosed+author%3Aqdm12)
Changes
PostRPC
andPostRPCWithRetry
PostRPC
andPostRPCWithRetry
PostRPCWithRetry
retries until context is canceledTests
Existing tests suites passing
Issues
Primary Reviewer