fix tor transport test
This commit is contained in:
parent
2fa2c4425f
commit
995d522f72
|
@ -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 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(
|
await allFuturesThrowing(
|
||||||
allFinished(
|
allFinished(
|
||||||
transport1.stop(),
|
transport1.stop(),
|
||||||
transport2.stop()))
|
transport2.stop()))
|
||||||
|
|
||||||
await handlerWait.wait(1.seconds) # when no issues will not wait that long!
|
|
||||||
|
|
||||||
asyncTest "e2e: handle write":
|
asyncTest "e2e: handle write":
|
||||||
let ma = @[MultiAddress.init(ma1).tryGet()]
|
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
|
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(
|
await allFuturesThrowing(
|
||||||
allFinished(
|
allFinished(
|
||||||
transport1.stop(),
|
transport1.stop(),
|
||||||
transport2.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":
|
asyncTest "e2e: handle read":
|
||||||
let ma = @[MultiAddress.init(ma1).tryGet()]
|
let ma = @[MultiAddress.init(ma1).tryGet()]
|
||||||
|
|
|
@ -23,20 +23,21 @@ import ../libp2p/[stream/connection,
|
||||||
import ./helpers, ./stubs/torstub, ./commontransport
|
import ./helpers, ./stubs/torstub, ./commontransport
|
||||||
|
|
||||||
const torServer = initTAddress("127.0.0.1", 9050.Port)
|
const torServer = initTAddress("127.0.0.1", 9050.Port)
|
||||||
var stub: TorServerStub
|
|
||||||
var startFut: Future[void]
|
|
||||||
suite "Tor transport":
|
suite "Tor transport":
|
||||||
setup:
|
var
|
||||||
|
stub {.threadvar.}: TorServerStub
|
||||||
|
startFut {.threadvar.}: Future[void]
|
||||||
|
asyncSetup:
|
||||||
stub = TorServerStub.new()
|
stub = TorServerStub.new()
|
||||||
stub.registerAddr("127.0.0.1:8080", "/ip4/127.0.0.1/tcp/8080")
|
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("libp2p.nim:8080", "/ip4/127.0.0.1/tcp/8080")
|
||||||
stub.registerAddr("::1:8080", "/ip6/::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("a2mncbqsbullu7thgm4e6zxda2xccmcgzmaq44oayhdtm6rav5vovcad.onion:80", "/ip4/127.0.0.1/tcp/8080")
|
||||||
stub.registerAddr("a2mncbqsbullu7thgm4e6zxda2xccmcgzmaq44oayhdtm6rav5vovcae.onion:81", "/ip4/127.0.0.1/tcp/8081")
|
stub.registerAddr("a2mncbqsbullu7thgm4e6zxda2xccmcgzmaq44oayhdtm6rav5vovcae.onion:81", "/ip4/127.0.0.1/tcp/8081")
|
||||||
startFut = stub.start(torServer)
|
startFut = stub.start(torServer)
|
||||||
teardown:
|
asyncTeardown:
|
||||||
waitFor startFut.cancelAndWait()
|
await startFut.cancelAndWait()
|
||||||
waitFor stub.stop()
|
await stub.stop()
|
||||||
checkTrackers()
|
checkTrackers()
|
||||||
|
|
||||||
proc test(lintesAddr: string, dialAddr: string) {.async.} =
|
proc test(lintesAddr: string, dialAddr: string) {.async.} =
|
||||||
|
@ -127,15 +128,8 @@ suite "Tor transport":
|
||||||
await clientSwitch.stop()
|
await clientSwitch.stop()
|
||||||
|
|
||||||
await startClient()
|
await startClient()
|
||||||
|
|
||||||
await serverSwitch.stop()
|
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 =
|
proc transProvider(): Transport =
|
||||||
TorTransport.new(torServer, {ReuseAddr}, Upgrade())
|
TorTransport.new(torServer, {ReuseAddr}, Upgrade())
|
||||||
|
|
||||||
|
@ -143,3 +137,9 @@ suite "Tor transport":
|
||||||
transProvider,
|
transProvider,
|
||||||
"/ip4/127.0.0.1/tcp/8080/onion3/a2mncbqsbullu7thgm4e6zxda2xccmcgzmaq44oayhdtm6rav5vovcad:80",
|
"/ip4/127.0.0.1/tcp/8080/onion3/a2mncbqsbullu7thgm4e6zxda2xccmcgzmaq44oayhdtm6rav5vovcad:80",
|
||||||
"/ip4/127.0.0.1/tcp/8081/onion3/a2mncbqsbullu7thgm4e6zxda2xccmcgzmaq44oayhdtm6rav5vovcae:81")
|
"/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()))
|
||||||
|
|
Loading…
Reference in New Issue