Test that subscription stops after call to unsubscribe()

This commit is contained in:
Mark Spanbroek 2023-06-27 16:16:31 +02:00 committed by markspanbroek
parent ceedf03c82
commit f8cac08cde
1 changed files with 14 additions and 1 deletions

View File

@ -24,11 +24,24 @@ template subscriptionTests(subscriptions, client) =
latestBlock = blck latestBlock = blck
let subscription = await subscriptions.subscribeBlocks(callback) let subscription = await subscriptions.subscribeBlocks(callback)
discard await client.call("evm_mine", newJArray()) discard await client.call("evm_mine", newJArray())
check eventually(latestBlock.number.isSome) check eventually latestBlock.number.isSome
check latestBlock.hash.isSome check latestBlock.hash.isSome
check latestBlock.timestamp > 0.u256 check latestBlock.timestamp > 0.u256
await subscription.unsubscribe() await subscription.unsubscribe()
test "stops listening to new blocks when unsubscribed":
var count = 0
proc callback(blck: Block) {.async.} =
inc count
let subscription = await subscriptions.subscribeBlocks(callback)
discard await client.call("evm_mine", newJArray())
check eventually count > 0
await subscription.unsubscribe()
let endcount = count
discard await client.call("evm_mine", newJArray())
await sleepAsync(100.millis)
check count == endcount
suite "Web socket subscriptions": suite "Web socket subscriptions":
var subscriptions: JsonRpcSubscriptions var subscriptions: JsonRpcSubscriptions