fix tor transport test

This commit is contained in:
Diego 2024-05-27 20:07:09 +02:00
parent 2fa2c4425f
commit 995d522f72
No known key found for this signature in database
GPG Key ID: C9DAC9BF68D1F806
2 changed files with 18 additions and 18 deletions

View File

@ -45,13 +45,12 @@ template commonTransportTest*(prov: TransportProvider, ma1: string, ma2: string
await conn.close() #for some protocols, closing requires actively reading, so we must close here
await handlerWait.wait(1.seconds) # when no issues will not wait that long!
await allFuturesThrowing(
allFinished(
transport1.stop(),
transport2.stop()))
await handlerWait.wait(1.seconds) # when no issues will not wait that long!
asyncTest "e2e: handle write":
let ma = @[MultiAddress.init(ma1).tryGet()]
@ -72,13 +71,14 @@ template commonTransportTest*(prov: TransportProvider, ma1: string, ma2: string
await conn.close() #for some protocols, closing requires actively reading, so we must close here
check string.fromBytes(msg) == "Hello!"
await handlerWait.wait(1.seconds) # when no issues will not wait that long!
await allFuturesThrowing(
allFinished(
transport1.stop(),
transport2.stop()))
check string.fromBytes(msg) == "Hello!"
await handlerWait.wait(1.seconds) # when no issues will not wait that long!
asyncTest "e2e: handle read":
let ma = @[MultiAddress.init(ma1).tryGet()]

View File

@ -23,20 +23,21 @@ import ../libp2p/[stream/connection,
import ./helpers, ./stubs/torstub, ./commontransport
const torServer = initTAddress("127.0.0.1", 9050.Port)
var stub: TorServerStub
var startFut: Future[void]
suite "Tor transport":
setup:
var
stub {.threadvar.}: TorServerStub
startFut {.threadvar.}: Future[void]
asyncSetup:
stub = TorServerStub.new()
stub.registerAddr("127.0.0.1:8080", "/ip4/127.0.0.1/tcp/8080")
stub.registerAddr("libp2p.nim:8080", "/ip4/127.0.0.1/tcp/8080")
stub.registerAddr("::1:8080", "/ip6/::1/tcp/8080")
stub.registerAddr("a2mncbqsbullu7thgm4e6zxda2xccmcgzmaq44oayhdtm6rav5vovcad.onion:80", "/ip4/127.0.0.1/tcp/8080")
stub.registerAddr("a2mncbqsbullu7thgm4e6zxda2xccmcgzmaq44oayhdtm6rav5vovcae.onion:81", "/ip4/127.0.0.1/tcp/8081")
startFut = stub.start(torServer)
teardown:
waitFor startFut.cancelAndWait()
waitFor stub.stop()
startFut = stub.start(torServer)
asyncTeardown:
await startFut.cancelAndWait()
await stub.stop()
checkTrackers()
proc test(lintesAddr: string, dialAddr: string) {.async.} =
@ -127,15 +128,8 @@ suite "Tor transport":
await clientSwitch.stop()
await startClient()
await serverSwitch.stop()
test "It's not possible to add another transport in TorSwitch":
let torSwitch = TorSwitch.new(torServer = torServer, rng= rng, flags = {ReuseAddr})
expect(AssertionDefect):
torSwitch.addTransport(TcpTransport.new(upgrade = Upgrade()))
waitFor torSwitch.stop()
proc transProvider(): Transport =
TorTransport.new(torServer, {ReuseAddr}, Upgrade())
@ -143,3 +137,9 @@ suite "Tor transport":
transProvider,
"/ip4/127.0.0.1/tcp/8080/onion3/a2mncbqsbullu7thgm4e6zxda2xccmcgzmaq44oayhdtm6rav5vovcad:80",
"/ip4/127.0.0.1/tcp/8081/onion3/a2mncbqsbullu7thgm4e6zxda2xccmcgzmaq44oayhdtm6rav5vovcae:81")
suite "Tor transport API":
asyncTest "It's not possible to add another transport in TorSwitch":
let torSwitch = TorSwitch.new(torServer = torServer, rng= rng, flags = {ReuseAddr})
expect(AssertionDefect):
torSwitch.addTransport(TcpTransport.new(upgrade = Upgrade()))