connection closing tests
This commit is contained in:
parent
5a657c9264
commit
4ee1b4a66d
|
@ -286,14 +286,12 @@ proc start*(s: Switch): Future[seq[Future[void]]] {.async, gcsafe.} =
|
|||
|
||||
proc handle(conn: Connection): Future[void] {.async, closure, gcsafe.} =
|
||||
try:
|
||||
dumpNumberOfInstances()
|
||||
await s.upgradeIncoming(conn) # perform upgrade on incoming connection
|
||||
except CatchableError as exc:
|
||||
trace "Exception occurred in Switch.start", exc = exc.msg
|
||||
finally:
|
||||
await conn.close()
|
||||
await s.cleanupConn(conn)
|
||||
dumpNumberOfInstances()
|
||||
|
||||
var startFuts: seq[Future[void]]
|
||||
for t in s.transports: # for each transport
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
import unittest
|
||||
import chronos, nimcrypto/utils
|
||||
import ../libp2p/[connection,
|
||||
stream/lpstream,
|
||||
stream/bufferstream]
|
||||
|
||||
suite "Connection":
|
||||
test "close":
|
||||
proc test(): Future[bool] {.async.} =
|
||||
var conn = newConnection(newBufferStream())
|
||||
await conn.close()
|
||||
check:
|
||||
conn.closed == true
|
||||
|
||||
result = true
|
||||
|
||||
check:
|
||||
waitFor(test()) == true
|
||||
|
||||
test "parent close":
|
||||
proc test(): Future[bool] {.async.} =
|
||||
var buf = newBufferStream()
|
||||
var conn = newConnection(buf)
|
||||
|
||||
await conn.close()
|
||||
check:
|
||||
conn.closed == true
|
||||
buf.closed == true
|
||||
|
||||
await sleepAsync(1.seconds)
|
||||
result = true
|
||||
|
||||
check:
|
||||
waitFor(test()) == true
|
||||
|
||||
test "child close":
|
||||
proc test(): Future[bool] {.async.} =
|
||||
var buf = newBufferStream()
|
||||
var conn = newConnection(buf)
|
||||
|
||||
await buf.close()
|
||||
check:
|
||||
conn.closed == true
|
||||
buf.closed == true
|
||||
|
||||
await sleepAsync(1.seconds)
|
||||
result = true
|
||||
|
||||
check:
|
||||
waitFor(test()) == true
|
Loading…
Reference in New Issue