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

fix(tests): testautorelay #1121

Merged
merged 3 commits into from
Jun 12, 2024
Merged

fix(tests): testautorelay #1121

merged 3 commits into from
Jun 12, 2024

Conversation

diegomrsantos
Copy link
Collaborator

@diegomrsantos diegomrsantos commented Jun 7, 2024

Fix testautorelay due to wildcard resolver and improve its readability.

Related to #1099

@diegomrsantos diegomrsantos changed the title fix(tests): fix testautorelay fix(tests): testautorelay Jun 7, 2024

check addresses != switchClient.peerInfo.addrs
await allFutures(switchClient.stop(), switchRelay.stop())

asyncTest "Three relays connections":
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@lchenut what is this test checking exactly?

Copy link
Collaborator

@lchenut lchenut Jun 11, 2024

Choose a reason for hiding this comment

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

I'll answer every question about this test here.
So. This badly named "Three relays connections" tests multiple things. The two big things tested is:

  • the maximum number of relay line 119: let autorelay = AutoRelayService.new(2, relayClient, checkMA, newRng()) (here it's a limit of 2)
  • what happens in case of a disconnection of a remote peer line 127 await rel2.stop()

What does this test do in details:

  • It creates 4 switches. switchClient is the "autorelay switch", the other three (rel1, rel2, rel3) are standard relay server switches.
  • State == 0: checkMA is called for the first time because switchClient connects (and reserves) to rel1
  • State == 1: switchClient connects (and reserves) to rel2 (line 124). You can notice that switchClient connects to rel3 aswell but it doesn't reserve, due to the maximum number of relay set to 2.
  • State == 2: rel2 disconnect, we return to the "first state" with only rel1 reserved by switchClient
  • State == 3: now that rel2 is disconnected, there's room for another relay, and rel3 takes this place.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks a lot.

@@ -95,21 +95,25 @@ suite "Autorelay":
relayClient = RelayClient.new()
proc checkMA(addresses: seq[MultiAddress]) =
if state == 0 or state == 2:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why do we need this state variable and what's the reasoning behind the conditions?

buildRelayMA(rel1, switchClient) in addresses
buildRelayMA(rel2, switchClient) in addresses
addresses.len() == 2
let relay1MAs = buildRelayMA(rel1, switchClient)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why do we use relays 1 and 2 here?

buildRelayMA(rel1, switchClient) in addresses
buildRelayMA(rel3, switchClient) in addresses
addresses.len() == 2
let relay1MAs = buildRelayMA(rel1, switchClient)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why do we use relays 1 and 3 here?

buildRelayMA(rel1, switchClient) in addresses
buildRelayMA(rel3, switchClient) in addresses
addresses.len() == 2
let relay1MAs = buildRelayMA(rel1, switchClient)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

why do we test this again here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's indeed a bit overkill. Not mandatory.

@@ -23,7 +23,7 @@ import stubs/autonatclientstub
proc createSwitch(autonatSvc: Service = nil, withAutonat = true, maxConnsPerPeer = 1, maxConns = 100, nameResolver: NameResolver = nil): Switch =
var builder = SwitchBuilder.new()
.withRng(newRng())
.withAddresses(@[ MultiAddress.init("/ip4/0.0.0.0/tcp/0").tryGet() ], false)
.withAddresses(@[ MultiAddress.init("/ip4/0.0.0.0/tcp/0").tryGet() ])
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This wasn't necessary, this test wasn't failing.

@diegomrsantos diegomrsantos self-assigned this Jun 11, 2024
@diegomrsantos diegomrsantos marked this pull request as ready for review June 11, 2024 12:50
await rel2.stop()
await fut.wait(1.seconds)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would leave this. Without this await, the test could finish before all the check are done.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, all awaits are necessary. It was "working" cause I removed await fut.wait(1.seconds) so no check was being done as you said. But I used futures instead, let me know what you think.

Copy link
Collaborator

@lchenut lchenut left a comment

Choose a reason for hiding this comment

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

LGTM

@diegomrsantos diegomrsantos enabled auto-merge (squash) June 12, 2024 14:05
@diegomrsantos diegomrsantos merged commit 3bf8a29 into master Jun 12, 2024
10 checks passed
@diegomrsantos diegomrsantos deleted the fix-tests branch June 12, 2024 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants