Fix trackers tests (#588)
* Fix checkTracker typo * fix testswich tests * use tracker consts
This commit is contained in:
parent
c7d9770637
commit
bd2e9a0462
|
@ -139,7 +139,7 @@ method close*(s: LPChannel) {.async, gcsafe.} =
|
||||||
|
|
||||||
method initStream*(s: LPChannel) =
|
method initStream*(s: LPChannel) =
|
||||||
if s.objName.len == 0:
|
if s.objName.len == 0:
|
||||||
s.objName = "LPChannel"
|
s.objName = LPChannelTrackerName
|
||||||
|
|
||||||
s.timeoutHandler = proc(): Future[void] {.gcsafe.} =
|
s.timeoutHandler = proc(): Future[void] {.gcsafe.} =
|
||||||
trace "Idle timeout expired, resetting LPChannel", s
|
trace "Idle timeout expired, resetting LPChannel", s
|
||||||
|
|
|
@ -59,7 +59,7 @@ proc init*(T: type SecureConn,
|
||||||
|
|
||||||
method initStream*(s: SecureConn) =
|
method initStream*(s: SecureConn) =
|
||||||
if s.objName.len == 0:
|
if s.objName.len == 0:
|
||||||
s.objName = "SecureConn"
|
s.objName = SecureConnTrackerName
|
||||||
|
|
||||||
procCall Connection(s).initStream()
|
procCall Connection(s).initStream()
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ proc len*(s: BufferStream): int =
|
||||||
|
|
||||||
method initStream*(s: BufferStream) =
|
method initStream*(s: BufferStream) =
|
||||||
if s.objName.len == 0:
|
if s.objName.len == 0:
|
||||||
s.objName = "BufferStream"
|
s.objName = BufferStreamTrackerName
|
||||||
|
|
||||||
procCall Connection(s).initStream()
|
procCall Connection(s).initStream()
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,7 @@ chronicles.formatIt(Connection): shortLog(it)
|
||||||
|
|
||||||
method initStream*(s: Connection) =
|
method initStream*(s: Connection) =
|
||||||
if s.objName.len == 0:
|
if s.objName.len == 0:
|
||||||
s.objName = "Connection"
|
s.objName = ConnectionTrackerName
|
||||||
|
|
||||||
procCall LPStream(s).initStream()
|
procCall LPStream(s).initStream()
|
||||||
|
|
||||||
|
|
|
@ -123,7 +123,7 @@ chronicles.formatIt(LPStream): shortLog(it)
|
||||||
|
|
||||||
method initStream*(s: LPStream) {.base.} =
|
method initStream*(s: LPStream) {.base.} =
|
||||||
if s.objName.len == 0:
|
if s.objName.len == 0:
|
||||||
s.objName = "LPStream"
|
s.objName = LPStreamTrackerName
|
||||||
|
|
||||||
s.closeEvent = newAsyncEvent()
|
s.closeEvent = newAsyncEvent()
|
||||||
s.oid = genOid()
|
s.oid = genOid()
|
||||||
|
@ -264,9 +264,9 @@ proc write*(s: LPStream, msg: string): Future[void] =
|
||||||
method closeImpl*(s: LPStream): Future[void] {.async, base.} =
|
method closeImpl*(s: LPStream): Future[void] {.async, base.} =
|
||||||
## Implementation of close - called only once
|
## Implementation of close - called only once
|
||||||
trace "Closing stream", s, objName = s.objName, dir = $s.dir
|
trace "Closing stream", s, objName = s.objName, dir = $s.dir
|
||||||
s.closeEvent.fire()
|
|
||||||
libp2p_open_streams.dec(labelValues = [s.objName, $s.dir])
|
libp2p_open_streams.dec(labelValues = [s.objName, $s.dir])
|
||||||
inc getStreamTracker(s.objName).closed
|
inc getStreamTracker(s.objName).closed
|
||||||
|
s.closeEvent.fire()
|
||||||
trace "Closed stream", s, objName = s.objName, dir = $s.dir
|
trace "Closed stream", s, objName = s.objName, dir = $s.dir
|
||||||
|
|
||||||
method close*(s: LPStream): Future[void] {.base, async.} = # {.raises [Defect].}
|
method close*(s: LPStream): Future[void] {.base, async.} = # {.raises [Defect].}
|
||||||
|
|
|
@ -36,7 +36,7 @@ iterator testTrackers*(extras: openArray[string] = []): TrackerBase =
|
||||||
if not isNil(t): yield t
|
if not isNil(t): yield t
|
||||||
|
|
||||||
template checkTracker*(name: string) =
|
template checkTracker*(name: string) =
|
||||||
var tracker = getTracker(LPChannelTrackerName)
|
var tracker = getTracker(name)
|
||||||
if tracker.isLeaked():
|
if tracker.isLeaked():
|
||||||
checkpoint tracker.dump()
|
checkpoint tracker.dump()
|
||||||
fail()
|
fail()
|
||||||
|
|
|
@ -596,13 +596,13 @@ suite "Switch":
|
||||||
rng = rng))
|
rng = rng))
|
||||||
|
|
||||||
switches[0].addConnEventHandler(hook, ConnEventKind.Connected)
|
switches[0].addConnEventHandler(hook, ConnEventKind.Connected)
|
||||||
switches[0].addConnEventHandler(hook, ConnEventKind.Disconnected)
|
|
||||||
awaiters.add(await switches[0].start())
|
awaiters.add(await switches[0].start())
|
||||||
|
|
||||||
for i in 1..5:
|
for i in 1..5:
|
||||||
switches.add(newStandardSwitch(
|
switches.add(newStandardSwitch(
|
||||||
privKey = some(peerInfo.privateKey),
|
privKey = some(peerInfo.privateKey),
|
||||||
rng = rng))
|
rng = rng))
|
||||||
|
switches[i].addConnEventHandler(hook, ConnEventKind.Disconnected)
|
||||||
onConnect = switches[i].connect(switches[0].peerInfo.peerId, switches[0].peerInfo.addrs)
|
onConnect = switches[i].connect(switches[0].peerInfo.peerId, switches[0].peerInfo.addrs)
|
||||||
await onConnect
|
await onConnect
|
||||||
|
|
||||||
|
@ -627,6 +627,7 @@ suite "Switch":
|
||||||
try:
|
try:
|
||||||
let conn = await transport.accept()
|
let conn = await transport.accept()
|
||||||
discard await conn.readLp(100)
|
discard await conn.readLp(100)
|
||||||
|
await conn.close()
|
||||||
except CatchableError:
|
except CatchableError:
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
@ -712,13 +713,12 @@ suite "Switch":
|
||||||
readers.add(closeReader())
|
readers.add(closeReader())
|
||||||
|
|
||||||
await allFuturesThrowing(readers)
|
await allFuturesThrowing(readers)
|
||||||
|
await switch2.stop() #Otherwise this leeks
|
||||||
checkTracker(LPChannelTrackerName)
|
checkTracker(LPChannelTrackerName)
|
||||||
checkTracker(SecureConnTrackerName)
|
checkTracker(SecureConnTrackerName)
|
||||||
checkTracker(ChronosStreamTrackerName)
|
checkTracker(ChronosStreamTrackerName)
|
||||||
|
|
||||||
await allFuturesThrowing(
|
await switch1.stop()
|
||||||
switch1.stop(),
|
|
||||||
switch2.stop())
|
|
||||||
|
|
||||||
# this needs to go at end
|
# this needs to go at end
|
||||||
await allFuturesThrowing(awaiters)
|
await allFuturesThrowing(awaiters)
|
||||||
|
|
Loading…
Reference in New Issue