Skip to content

Refactoring of P2P unit tests - #30

Merged
tzdybal merged 3 commits into
mainfrom
tzdybal/p2p/refactor_tests
Mar 23, 2021
Merged

Refactoring of P2P unit tests#30
tzdybal merged 3 commits into
mainfrom
tzdybal/p2p/refactor_tests

Conversation

@tzdybal

@tzdybaltzdybal commented Mar 23, 2021

Copy link
Copy Markdown
Contributor

Refactoring of P2P layer tests.

  • replace manual creation of clients with some "factory" function
  • use libp2p mock network

Resolves#26, #27.

@tzdybaltzdybal added the C:p2p p2p networking related label Mar 23, 2021
@tzdybal
tzdybal requested review from Wondertan and liamsiMarch 23, 2021 08:12
Comment threadp2p/utils_test.go Outdated
}
}

func makeTestNetowork(t *testing.T, n int, conns map[int][]int, logger log.Logger) testNet {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, this increases the readbility of the tests 👍🏼

Suggested change
funcmakeTestNetowork(t*testing.T, nint, connsmap[int][]int, logger log.Logger) testNet {
funcmakeTestNetwork(t*testing.T, nint, connsmap[int][]int, logger log.Logger) testNet {

And the calling code as well.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

There should be 🤦 reaction :D

Comment threadp2p/utils_test.go Outdated
@tzdybal
tzdybalforce-pushed the tzdybal/p2p/discovery branch from e97f4bf to 7777439CompareMarch 23, 2021 09:27
Base automatically changed from tzdybal/p2p/discovery to mainMarch 23, 2021 09:34
@tzdybal
tzdybalforce-pushed the tzdybal/p2p/refactor_tests branch from 94e7acc to 5ba2324CompareMarch 23, 2021 09:54
@codecov-io

Copy link
Copy Markdown

Codecov Report

Merging #30 (832ab56) into main (567292e) will decrease coverage by 0.25%.
The diff coverage is 77.77%.

Impacted file tree graph

@@ Coverage Diff @@## main #30 +/- ##
==========================================
- Coverage 72.07% 71.81% -0.26% 
==========================================
Files 3 3 Lines 111 110 -1 ==========================================
- Hits 80 79 -1 
Misses 16 16 Partials 15 15 
Impacted FilesCoverage Δ
p2p/client.go69.14% <77.77%> (-0.33%)⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 567292e...832ab56. Read the comment docs.

@tzdybal
tzdybal marked this pull request as ready for review March 23, 2021 10:16
@tzdybal
tzdybal requested a review from liamsiMarch 23, 2021 10:17
@tzdybaltzdybal mentioned this pull request Mar 23, 2021

@WondertanWondertan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good!

Comment threadp2p/utils_test.go Outdated
t.Helper()
require := require.New(t)

mnet, err := mocknet.FullMeshLinked(context.Background(), n)

@WondertanWondertanMar 23, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Better create context at the beginning of the test and pass it here. That might be helpful in some tests

@tzdybal
tzdybal merged commit 2ec85bb into mainMar 23, 2021
@tzdybal
tzdybal deleted the tzdybal/p2p/refactor_tests branch May 2, 2023 19:40
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C:p2pp2p networking related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use libp2p mocked network in tests

4 participants

@tzdybal@codecov-io@liamsi@Wondertan