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

chore: adding NetConfig test suite #2091

Merged
merged 7 commits into from
Sep 29, 2023

Conversation

gabrielmer
Copy link
Contributor

Description

Added test suite to cover common NetConfig settings

Changes

  • Created new file ./tests/test_waku_netconfig.nim with a NetConfig test suite
  • Moved defaultTestWakuNodeConf from test_app.nim to external_config.nim
  • Updated defaultTestWakuNodeConfto use our current default listenAddress 0.0.0.0 and added more default parameters

Issue

closes #1540

@github-actions
Copy link

This PR may contain changes to configuration options of one of the apps.

If you are introducing a breaking change (i.e. the set of options in latest release would no longer be applicable) make sure the original option is preserved with a deprecation note for 2 following releases before it is actually removed.

Please also make sure the label release-notes is added to make sure any changes to the user interface are properly announced in changelog and release notes.

@github-actions
Copy link

github-actions bot commented Sep 28, 2023

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:2091

Built from a4ab1a8

../../apps/wakunode2/internal_config,
../wakunode2/test_app,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When importing defaultTestWakuNodeConf from test_app into other test suites, the test_app suite was being re-run as part of the suites importing it. For easier defaultTestWakuNodeConf's reusability, moved the function to external_config, mimicking newTestWakuNode, which is reused by many test suites and is defined in wakunode.nim

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, made a comment about this elsewhere before seeing this. wakunode.nim is a testlib - in other words, it's designed to be a utility module for functions useful in tests. newTestWakuNode defaultTestWakuNodeConf etc. shouldn't be defined in any "production" modules (test code should remain completely separate. The way to prevent test_app from being run multiple times for each import is to move defaultTestWakuNodeConf to a test helper module. I'd suggest just adding it to testlib/wakunode.nim and importing in both test_app and test_waku_netconfig

check:
netConfig.announcedAddresses.len == 2 # External address + wsHostAddress
netConfig.announcedAddresses[1] == (ip4TcpEndPoint(extIp,
conf.websocketPort) & wsFlag(wssEnabled))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that in order to configure WS using an extIp, the published port isn't extPort but conf.websocketPort. For websockets we bind to and announce the same port number.

Copy link
Contributor

@jm-clius jm-clius left a comment

Choose a reason for hiding this comment

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

Looks good and covers quite a lot! Thanks for this. Much better than what we have (which was noting 😅 ). Feel free to mark as ready for review once you think it can be merged.

check:
netConfigRes.isOk()

asyncTest "AnnouncedAddresses contains only bind address when no external addresses are provided":
Copy link
Contributor

Choose a reason for hiding this comment

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

Indentation seem a bit weird.

netConfig.announcedAddresses[0] == formatListenAddress(ip4TcpEndPoint(conf.listenAddress, conf.tcpPort))


asyncTest "AnnouncedAddresses contains external address if extIp/Port are provided":
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto in terms of indentation and for other tests (I think they should be single indented to be considered part of "Waku Netconfig" suite

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! For some reason the tests were still being run as part of the test suite with that indentation, which is pretty interesting. Just pushed a fix for it - thank you!

@gabrielmer gabrielmer marked this pull request as ready for review September 29, 2023 07:51
@gabrielmer gabrielmer self-assigned this Sep 29, 2023
Copy link
Contributor

@jm-clius jm-clius left a comment

Choose a reason for hiding this comment

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

LGTM. defaultTestWakuNodeConf should not be defined in a "production" module llike external_config.nim, but once this has been moved I'll be happy for the suite to be merged. No need to re-request review from my side. Great job!

Comment on lines 555 to 568
proc defaultTestWakuNodeConf*(): WakuNodeConf =
WakuNodeConf(
tcpPort: Port(60000),
websocketPort: Port(8000),
listenAddress: ValidIpAddress.init("0.0.0.0"),
rpcAddress: ValidIpAddress.init("127.0.0.1"),
restAddress: ValidIpAddress.init("127.0.0.1"),
metricsServerAddress: ValidIpAddress.init("127.0.0.1"),
dnsAddrsNameServers: @[ValidIpAddress.init("1.1.1.1"), ValidIpAddress.init("1.0.0.1")],
nat: "any",
maxConnections: 50,
topics: @["/waku/2/default-waku/proto"],
relay: true
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why has this been moved from test_app.nim? I wouldn't move any test code into "production" code.

../../apps/wakunode2/internal_config,
../wakunode2/test_app,
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, made a comment about this elsewhere before seeing this. wakunode.nim is a testlib - in other words, it's designed to be a utility module for functions useful in tests. newTestWakuNode defaultTestWakuNodeConf etc. shouldn't be defined in any "production" modules (test code should remain completely separate. The way to prevent test_app from being run multiple times for each import is to move defaultTestWakuNodeConf to a test helper module. I'd suggest just adding it to testlib/wakunode.nim and importing in both test_app and test_waku_netconfig

@gabrielmer
Copy link
Contributor Author

LGTM. defaultTestWakuNodeConf should not be defined in a "production" module llike external_config.nim, but once this has been moved I'll be happy for the suite to be merged. No need to re-request review from my side. Great job!

Ooh now everything makes much more sense! I didn't notice that wakunode.nim was a testlib 😶
Will move defaultTestWakuNodeConf to wakunode.nim then :)

Thanks so much!

Copy link
Collaborator

@Ivansete-status Ivansete-status left a comment

Choose a reason for hiding this comment

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

Thanks for that! You created many more test cases than I could imagine 🥇
Nevertheless, there are a few things that need to be revisited :)
It is especially important the comment about apps/wakunode2/external_config.nim. I'd prevent changing it.
Cheers!

tests/test_waku_netconfig.nim Outdated Show resolved Hide resolved
tests/test_waku_netconfig.nim Show resolved Hide resolved
waku/node/config.nim Outdated Show resolved Hide resolved
Copy link
Contributor

@SionoiS SionoiS left a comment

Choose a reason for hiding this comment

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

No further comments than what was already said.

I just feel like we could use the type system in cases like this to enforce some "rules".

My 0.02$

@gabrielmer
Copy link
Contributor Author

No further comments than what was already said.

I just feel like we could use the type system in cases like this to enforce some "rules".

My 0.02$

I'm not sure I fully understand the idea. Is it about setting explicitly the type when declaring variables instead of having the types being automatically inferred so we enforce the return types of procs?

Or what kind of rules are you thinking of?

Copy link
Collaborator

@Ivansete-status Ivansete-status left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for it! 💯

@SionoiS
Copy link
Contributor

SionoiS commented Sep 29, 2023

No further comments than what was already said.
I just feel like we could use the type system in cases like this to enforce some "rules".
My 0.02$

I'm not sure I fully understand the idea. Is it about setting explicitly the type when declaring variables instead of having the types being automatically inferred so we enforce the return types of procs?

Or what kind of rules are you thinking of?

Probably not practical to do this here but the type system can help enforcing requirement like
AnnouncedAddresses contains only bind address when no external addresses are provided

For example you could use some type to represent the state.

  • only bind address when no external addresses are provided
  • only external address if extIp/Port are provided

Maybe the Nim type system is not made to do this though IDK. I only done this in Rust.

@gabrielmer gabrielmer merged commit 23b49ca into master Sep 29, 2023
8 of 10 checks passed
@gabrielmer gabrielmer deleted the chore-improve-netconfig-test-coverage branch September 29, 2023 13:30
ABresting pushed a commit that referenced this pull request Sep 30, 2023
ABresting added a commit that referenced this pull request Sep 30, 2023
* chore: add retention policy with GB or MB limitation #1885

* chore: add retention policy with GB or MB limitation

* chore: updated code post review- retention policy

* ci: extract discordNotify to separate file

Signed-off-by: Jakub Sokołowski <[email protected]>

* ci: push images to new wakuorg/nwaku repo

Signed-off-by: Jakub Sokołowski <[email protected]>

* ci: enforce default Docker image tags strictly

Signed-off-by: Jakub Sokołowski <[email protected]>

* ci: push GIT_REF if it looks like a version

Signed-off-by: Jakub Sokołowski <[email protected]>

* fix: update wakuv2 fleet DNS discovery enrtree

https://github.com/status-im/infra-misc/issues/171

* chore: resolving DNS IP and publishing it when no extIp is provided (#2030)

* feat(coverage): Add simple coverage (#2067)

* Add test aggregator to all directories.
* Implement coverage script.

* fix(ci): fix name of discord notify method

Also use absolute path to load Groovy script.

Signed-off-by: Jakub Sokołowski <[email protected]>

* chore(networkmonitor): refactor setConnectedPeersMetrics, make it partially concurrent, add version (#2080)

* chore(networkmonitor): refactor setConnectedPeersMetrics, make it partially concurrent, add version

* add more metrics, refactor how most metrics are calculated

* rework metrics table fillup

* reset connErr to make sure we honour successful reconnection

* chore(cbindings): Adding cpp example that integrates the 'libwaku' (#2079)

* Adding cpp example that integrates the `libwaku`

---------

Co-authored-by: NagyZoltanPeter <[email protected]>

* fix(ci): update the dependency list in pre-release WF (#2088)

* chore: adding NetConfig test suite (#2091)

---------

Signed-off-by: Jakub Sokołowski <[email protected]>
Co-authored-by: Jakub Sokołowski <[email protected]>
Co-authored-by: Anton Iakimov <[email protected]>
Co-authored-by: gabrielmer <[email protected]>
Co-authored-by: Álex Cabeza Romero <[email protected]>
Co-authored-by: Vaclav Pavlin <[email protected]>
Co-authored-by: Ivan Folgueira Bande <[email protected]>
Co-authored-by: NagyZoltanPeter <[email protected]>
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.

chore: improve test coverage on NetConfig generation
4 participants