Skip to content

p2p: tighten up Router and add tests#6044

Merged
mergify[bot] merged 30 commits intomasterfrom
erik/router-tests
Feb 3, 2021
Merged

p2p: tighten up Router and add tests#6044
mergify[bot] merged 30 commits intomasterfrom
erik/router-tests

Conversation

@erikgrinaker
Copy link
Contributor

@erikgrinaker erikgrinaker commented Feb 3, 2021

This cleans up the Router code and adds a bunch of tests. These sorts of systems are a real pain to test, since they have a bunch of asynchronous goroutines living their own lives, so the test coverage is decent but not fantastic. Luckily we've been able to move all of the complex peer management and transport logic outside of the router, as synchronous components that are much easier to test, so the core router logic is fairly small and simple.

This also provides some initial test tooling in p2p/p2ptest that automatically sets up in-memory networks and channels for use in integration tests. It also includes channel-oriented test asserters in p2p/p2ptest/require.go, but these have primarily been written for router testing and should probably be adapted or extended for reactor testing.

@erikgrinaker erikgrinaker added C:p2p Component: P2P pkg T:test Type: Tests that need love S:automerge Automatically merge PR when requirements pass labels Feb 3, 2021
@erikgrinaker erikgrinaker self-assigned this Feb 3, 2021
@erikgrinaker
Copy link
Contributor Author

erikgrinaker commented Feb 3, 2021

The race detector is triggering on Testify mocks accessing context.Context internals, which I believe is this bug:

stretchr/testify#625

Will look into workarounds tomorrow.

EDIT: Nevermind, the race happens when there is a mock failure and it's trying to display details, specifically this line:

m.fail("\nassert: mock: The method has been called over %d times.\n\tEither do one more Mock.On(\"%s\").Return(...), or remove extra call.\n\tThis call was unexpected:\n\t\t%s\n\tat: %s", call.totalCalls, methodName, callString(methodName, arguments, true), assert.CallerInfo())

@codecov
Copy link

codecov bot commented Feb 3, 2021

Codecov Report

Merging #6044 (f393558) into master (5f88d6a) will increase coverage by 1.02%.
The diff coverage is 79.28%.

@@            Coverage Diff             @@
##           master    #6044      +/-   ##
==========================================
+ Coverage   59.85%   60.88%   +1.02%     
==========================================
  Files         274      275       +1     
  Lines       25248    25334      +86     
==========================================
+ Hits        15112    15424     +312     
+ Misses       8520     8317     -203     
+ Partials     1616     1593      -23     
Impacted Files Coverage Δ
p2p/address.go 97.82% <ø> (-0.03%) ⬇️
p2p/peer.go 48.76% <ø> (+1.22%) ⬆️
p2p/pex/reactor.go 0.00% <0.00%> (ø)
p2p/transport.go 100.00% <ø> (ø)
blockchain/v0/reactor.go 63.20% <33.33%> (+0.99%) ⬆️
evidence/reactor.go 72.80% <61.53%> (+0.63%) ⬆️
statesync/reactor.go 57.01% <66.66%> (-0.38%) ⬇️
p2p/router.go 78.28% <77.51%> (+19.40%) ⬆️
p2p/shim.go 54.01% <81.25%> (+2.10%) ⬆️
p2p/peermanager.go 83.95% <83.95%> (ø)
... and 20 more

Copy link
Contributor

@tessr tessr left a comment

Choose a reason for hiding this comment

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

This (huge) PR was (still) very readable! Nice work.

// Validate validates the options.
// Validate validates router options.
func (o *RouterOptions) Validate() error {
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there anticipated future RouterOptions that might need to be validated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No idea, but possible. Could just remove it until it's needed too.

@mergify mergify bot merged commit 9b6d6a3 into master Feb 3, 2021
@mergify mergify bot deleted the erik/router-tests branch February 3, 2021 23:03
@erikgrinaker
Copy link
Contributor Author

This (huge) PR was (still) very readable! Nice work.

Thanks! Should ideally have split out some of the changes, but there were a bunch of fairly minor changes and I was short on time. Thanks for reviewing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C:p2p Component: P2P pkg S:automerge Automatically merge PR when requirements pass T:test Type: Tests that need love

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants