Fix trackers tests (#588)

* Fix checkTracker typo

* fix testswich tests

* use tracker consts
This commit is contained in:
Tanguy Cizain 2021-06-14 10:26:11 +02:00 committed by GitHub
parent c7d9770637
commit bd2e9a0462
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 11 additions and 11 deletions

View File

@ -139,7 +139,7 @@ method close*(s: LPChannel) {.async, gcsafe.} =
method initStream*(s: LPChannel) =
if s.objName.len == 0:
s.objName = "LPChannel"
s.objName = LPChannelTrackerName
s.timeoutHandler = proc(): Future[void] {.gcsafe.} =
trace "Idle timeout expired, resetting LPChannel", s

View File

@ -59,7 +59,7 @@ proc init*(T: type SecureConn,
method initStream*(s: SecureConn) =
if s.objName.len == 0:
s.objName = "SecureConn"
s.objName = SecureConnTrackerName
procCall Connection(s).initStream()

View File

@ -50,7 +50,7 @@ proc len*(s: BufferStream): int =
method initStream*(s: BufferStream) =
if s.objName.len == 0:
s.objName = "BufferStream"
s.objName = BufferStreamTrackerName
procCall Connection(s).initStream()

View File

@ -68,7 +68,7 @@ chronicles.formatIt(Connection): shortLog(it)
method initStream*(s: Connection) =
if s.objName.len == 0:
s.objName = "Connection"
s.objName = ConnectionTrackerName
procCall LPStream(s).initStream()

View File

@ -123,7 +123,7 @@ chronicles.formatIt(LPStream): shortLog(it)
method initStream*(s: LPStream) {.base.} =
if s.objName.len == 0:
s.objName = "LPStream"
s.objName = LPStreamTrackerName
s.closeEvent = newAsyncEvent()
s.oid = genOid()
@ -264,9 +264,9 @@ proc write*(s: LPStream, msg: string): Future[void] =
method closeImpl*(s: LPStream): Future[void] {.async, base.} =
## Implementation of close - called only once
trace "Closing stream", s, objName = s.objName, dir = $s.dir
s.closeEvent.fire()
libp2p_open_streams.dec(labelValues = [s.objName, $s.dir])
inc getStreamTracker(s.objName).closed
s.closeEvent.fire()
trace "Closed stream", s, objName = s.objName, dir = $s.dir
method close*(s: LPStream): Future[void] {.base, async.} = # {.raises [Defect].}

View File

@ -36,7 +36,7 @@ iterator testTrackers*(extras: openArray[string] = []): TrackerBase =
if not isNil(t): yield t
template checkTracker*(name: string) =
var tracker = getTracker(LPChannelTrackerName)
var tracker = getTracker(name)
if tracker.isLeaked():
checkpoint tracker.dump()
fail()

View File

@ -596,13 +596,13 @@ suite "Switch":
rng = rng))
switches[0].addConnEventHandler(hook, ConnEventKind.Connected)
switches[0].addConnEventHandler(hook, ConnEventKind.Disconnected)
awaiters.add(await switches[0].start())
for i in 1..5:
switches.add(newStandardSwitch(
privKey = some(peerInfo.privateKey),
rng = rng))
switches[i].addConnEventHandler(hook, ConnEventKind.Disconnected)
onConnect = switches[i].connect(switches[0].peerInfo.peerId, switches[0].peerInfo.addrs)
await onConnect
@ -627,6 +627,7 @@ suite "Switch":
try:
let conn = await transport.accept()
discard await conn.readLp(100)
await conn.close()
except CatchableError:
discard
@ -712,13 +713,12 @@ suite "Switch":
readers.add(closeReader())
await allFuturesThrowing(readers)
await switch2.stop() #Otherwise this leeks
checkTracker(LPChannelTrackerName)
checkTracker(SecureConnTrackerName)
checkTracker(ChronosStreamTrackerName)
await allFuturesThrowing(
switch1.stop(),
switch2.stop())
await switch1.stop()
# this needs to go at end
await allFuturesThrowing(awaiters)