From f8cac08cde4ac54315686eeae7f8cdecea232678 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Tue, 27 Jun 2023 16:16:31 +0200 Subject: [PATCH] Test that subscription stops after call to unsubscribe() --- .../jsonrpc/testJsonRpcSubscriptions.nim | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/testmodule/providers/jsonrpc/testJsonRpcSubscriptions.nim b/testmodule/providers/jsonrpc/testJsonRpcSubscriptions.nim index 3d01fc0..7714328 100644 --- a/testmodule/providers/jsonrpc/testJsonRpcSubscriptions.nim +++ b/testmodule/providers/jsonrpc/testJsonRpcSubscriptions.nim @@ -24,11 +24,24 @@ template subscriptionTests(subscriptions, client) = latestBlock = blck let subscription = await subscriptions.subscribeBlocks(callback) discard await client.call("evm_mine", newJArray()) - check eventually(latestBlock.number.isSome) + check eventually latestBlock.number.isSome check latestBlock.hash.isSome check latestBlock.timestamp > 0.u256 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": var subscriptions: JsonRpcSubscriptions