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: Use random ports in rest tests instead of fixed ones #2804

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tests/wakunode_rest/test_rest_admin.nim
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ suite "Waku v2 Rest API - Admin":
await allFutures(node1.start(), node2.start(), node3.start())
await allFutures(node1.mountRelay(), node2.mountRelay(), node3.mountRelay())

let restPort = Port(58011)
var restPort = Port(0)
let restAddress = parseIpAddress("127.0.0.1")
restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
restPort = restServer.httpServer.address.port # update with bound port for client use

installAdminApiHandlers(restServer.router, node1)

Expand Down
17 changes: 10 additions & 7 deletions tests/wakunode_rest/test_rest_cors.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ proc testWakuNode(): WakuNode =
privkey = crypto.PrivateKey.random(Secp256k1, rng[]).tryGet()
bindIp = parseIpAddress("0.0.0.0")
extIp = parseIpAddress("127.0.0.1")
port = Port(58000)
port = Port(0)

newTestWakuNode(privkey, bindIp, port, some(extIp), some(port))

Expand Down Expand Up @@ -86,8 +86,7 @@ proc checkResponse(
expectedOrigin.isSome() and
response.headers.contains("Access-Control-Allow-Origin") and
response.headers.getLastString("Access-Control-Allow-Origin") ==
expectedOrigin.get() and
response.headers.contains("Access-Control-Allow-Headers") and
expectedOrigin.get() and response.headers.contains("Access-Control-Allow-Headers") and
response.headers.getLastString("Access-Control-Allow-Headers") == "Content-Type"
)
):
Expand All @@ -106,7 +105,7 @@ suite "Waku v2 REST API CORS Handling":
await node.start()
await node.mountRelay()

let restPort = Port(58001)
var restPort = Port(0)
let restAddress = parseIpAddress("0.0.0.0")
let restServer = WakuRestServerRef
.init(
Expand All @@ -116,6 +115,7 @@ suite "Waku v2 REST API CORS Handling":
some("test.net:1234,https://localhost:*,http://127.0.0.1:?8,?waku*.net:*80*"),
)
.tryGet()
restPort = restServer.httpServer.address.port # update with bound port for client use

installDebugApiHandlers(restServer.router, node)
restServer.start()
Expand Down Expand Up @@ -158,7 +158,7 @@ suite "Waku v2 REST API CORS Handling":
await node.start()
await node.mountRelay()

let restPort = Port(58001)
var restPort = Port(0)
let restAddress = parseIpAddress("0.0.0.0")
let restServer = WakuRestServerRef
.init(
Expand All @@ -168,6 +168,7 @@ suite "Waku v2 REST API CORS Handling":
some("test.net:1234,https://localhost:*,http://127.0.0.1:?8,?waku*.net:*80*"),
)
.tryGet()
restPort = restServer.httpServer.address.port # update with bound port for client use

installDebugApiHandlers(restServer.router, node)
restServer.start()
Expand Down Expand Up @@ -213,10 +214,11 @@ suite "Waku v2 REST API CORS Handling":
await node.start()
await node.mountRelay()

let restPort = Port(58001)
var restPort = Port(0)
let restAddress = parseIpAddress("0.0.0.0")
let restServer =
WakuRestServerRef.init(restAddress, restPort, allowedOrigin = some("*")).tryGet()
restPort = restServer.httpServer.address.port # update with bound port for client use

installDebugApiHandlers(restServer.router, node)
restServer.start()
Expand Down Expand Up @@ -259,7 +261,7 @@ suite "Waku v2 REST API CORS Handling":
await node.start()
await node.mountRelay()

let restPort = Port(58001)
var restPort = Port(0)
let restAddress = parseIpAddress("0.0.0.0")
let restServer = WakuRestServerRef
.init(
Expand All @@ -269,6 +271,7 @@ suite "Waku v2 REST API CORS Handling":
some("test.net:1234,https://localhost:*,http://127.0.0.1:?8,?waku*.net:*80*"),
)
.tryGet()
restPort = restServer.httpServer.address.port # update with bound port for client use

installDebugApiHandlers(restServer.router, node)
restServer.start()
Expand Down
8 changes: 5 additions & 3 deletions tests/wakunode_rest/test_rest_debug.nim
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ proc testWakuNode(): WakuNode =
privkey = crypto.PrivateKey.random(Secp256k1, rng[]).tryGet()
bindIp = parseIpAddress("0.0.0.0")
extIp = parseIpAddress("127.0.0.1")
port = Port(58000)
port = Port(0)

newTestWakuNode(privkey, bindIp, port, some(extIp), some(port))

Expand All @@ -37,9 +37,10 @@ suite "Waku v2 REST API - Debug":
await node.start()
await node.mountRelay()

let restPort = Port(58001)
var restPort = Port(0)
let restAddress = parseIpAddress("0.0.0.0")
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
restPort = restServer.httpServer.address.port # update with bound port for client use

installDebugApiHandlers(restServer.router, node)
restServer.start()
Expand All @@ -65,9 +66,10 @@ suite "Waku v2 REST API - Debug":
await node.start()
await node.mountRelay()

let restPort = Port(58002)
var restPort = Port(0)
let restAddress = parseIpAddress("0.0.0.0")
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
restPort = restServer.httpServer.address.port # update with bound port for client use

installDebugApiHandlers(restServer.router, node)
restServer.start()
Expand Down
8 changes: 6 additions & 2 deletions tests/wakunode_rest/test_rest_filter.nim
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,17 @@ proc init(T: type RestFilterTest): Future[T] {.async.} =
testSetup.serviceNode.peerInfo.toRemotePeerInfo(), WakuFilterSubscribeCodec
)

let restPort = Port(58011)
var restPort = Port(0)
let restAddress = parseIpAddress("127.0.0.1")
testSetup.restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
restPort = testSetup.restServer.httpServer.address.port
# update with bound port for client use

let restPort2 = Port(58012)
var restPort2 = Port(0)
testSetup.restServerForService =
WakuRestServerRef.init(restAddress, restPort2).tryGet()
restPort2 = testSetup.restServerForService.httpServer.address.port
# update with bound port for client use

# through this one we will see if messages are pushed according to our content topic sub
testSetup.messageCache = MessageCache.init()
Expand Down
3 changes: 2 additions & 1 deletion tests/wakunode_rest/test_rest_health.nim
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ suite "Waku v2 REST API - health":

healthMonitor.setOverallHealth(HealthStatus.INITIALIZING)

let restPort = Port(58001)
var restPort = Port(0)
let restAddress = parseIpAddress("0.0.0.0")
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
restPort = restServer.httpServer.address.port # update with bound port for client use

installHealthApiHandler(restServer.router, healthMonitor)
restServer.start()
Expand Down
4 changes: 3 additions & 1 deletion tests/wakunode_rest/test_rest_lightpush.nim
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ proc init(
testSetup.serviceNode.peerInfo.toRemotePeerInfo(), WakuLightPushCodec
)

let restPort = Port(58011)
var restPort = Port(0)
let restAddress = parseIpAddress("127.0.0.1")
testSetup.restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
restPort = testSetup.restServer.httpServer.address.port
# update with bound port for client use

installLightPushRequestHandler(testSetup.restServer.router, testSetup.pushNode)

Expand Down
28 changes: 18 additions & 10 deletions tests/wakunode_rest/test_rest_store.nim
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ procSuite "Waku Rest API - Store v3":
await node.start()
await node.mountRelay()

let restPort = Port(58011)
var restPort = Port(0)
let restAddress = parseIpAddress("0.0.0.0")
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
restPort = restServer.httpServer.address.port # update with bound port for client use

installStoreApiHandlers(restServer.router, node)
restServer.start()
Expand Down Expand Up @@ -170,9 +171,10 @@ procSuite "Waku Rest API - Store v3":
await node.start()
await node.mountRelay()

let restPort = Port(58011)
var restPort = Port(0)
let restAddress = parseIpAddress("0.0.0.0")
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
restPort = restServer.httpServer.address.port # update with bound port for client use

installStoreApiHandlers(restServer.router, node)
restServer.start()
Expand Down Expand Up @@ -239,9 +241,10 @@ procSuite "Waku Rest API - Store v3":
let node = testWakuNode()
await node.start()

let restPort = Port(58012)
var restPort = Port(0)
let restAddress = parseIpAddress("0.0.0.0")
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
restPort = restServer.httpServer.address.port # update with bound port for client use

installStoreApiHandlers(restServer.router, node)
restServer.start()
Expand Down Expand Up @@ -334,9 +337,10 @@ procSuite "Waku Rest API - Store v3":
await node.start()
await node.mountRelay()

let restPort = Port(58013)
var restPort = Port(0)
let restAddress = parseIpAddress("0.0.0.0")
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
restPort = restServer.httpServer.address.port # update with bound port for client use

installStoreApiHandlers(restServer.router, node)
restServer.start()
Expand Down Expand Up @@ -406,9 +410,10 @@ procSuite "Waku Rest API - Store v3":
await node.start()
await node.mountRelay()

let restPort = Port(58014)
var restPort = Port(0)
let restAddress = parseIpAddress("0.0.0.0")
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
restPort = restServer.httpServer.address.port # update with bound port for client use

installStoreApiHandlers(restServer.router, node)
restServer.start()
Expand Down Expand Up @@ -494,9 +499,10 @@ procSuite "Waku Rest API - Store v3":
await node.start()
await node.mountRelay()

let restPort = Port(58015)
var restPort = Port(0)
let restAddress = parseIpAddress("0.0.0.0")
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
restPort = restServer.httpServer.address.port # update with bound port for client use

installStoreApiHandlers(restServer.router, node)
restServer.start()
Expand Down Expand Up @@ -549,9 +555,10 @@ procSuite "Waku Rest API - Store v3":
await node.start()
await node.mountRelay()

let restPort = Port(58016)
var restPort = Port(0)
let restAddress = parseIpAddress("0.0.0.0")
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
restPort = restServer.httpServer.address.port # update with bound port for client use

installStoreApiHandlers(restServer.router, node)
restServer.start()
Expand Down Expand Up @@ -617,9 +624,10 @@ procSuite "Waku Rest API - Store v3":
let node = testWakuNode()
await node.start()

let restPort = Port(58017)
var restPort = Port(0)
let restAddress = parseIpAddress("0.0.0.0")
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
restPort = restServer.httpServer.address.port # update with bound port for client use

installStoreApiHandlers(restServer.router, node)
restServer.start()
Expand Down Expand Up @@ -680,7 +688,6 @@ procSuite "Waku Rest API - Store v3":
var restPort = Port(0)
let restAddress = parseIpAddress("0.0.0.0")
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()

restPort = restServer.httpServer.address.port # update with bound port for client use

installStoreApiHandlers(restServer.router, node)
Expand Down Expand Up @@ -726,9 +733,10 @@ procSuite "Waku Rest API - Store v3":
let node = testWakuNode()
await node.start()

let restPort = Port(58018)
var restPort = Port(0)
let restAddress = parseIpAddress("0.0.0.0")
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
restPort = restServer.httpServer.address.port # update with bound port for client use

installStoreApiHandlers(restServer.router, node)
restServer.start()
Expand Down
Loading