Skip to content

Commit

Permalink
test: speeding up tests and table key value check
Browse files Browse the repository at this point in the history
  • Loading branch information
AuHau committed Oct 22, 2024
1 parent 04fa948 commit 7b24ffe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ethers.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ requires "stew"
requires "eth#c482b4c5b658a77cc96b49d4a397aa6d98472ac7"

task test, "Run the test suite":
exec "nimble install -d -y"
# exec "nimble install -d -y"
withDir "testmodule":
exec "nimble test"
15 changes: 10 additions & 5 deletions testmodule/providers/jsonrpc/testJsonRpcSubscriptions.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import std/json
import std/sequtils
import pkg/asynctest
import pkg/serde
import pkg/json_rpc/rpcclient
Expand Down Expand Up @@ -109,7 +110,7 @@ suite "HTTP polling subscriptions - filter not found":
await client.connect("http://" & $mockServer.localAddress()[0])

subscriptions = JsonRpcSubscriptions.new(client,
pollingInterval = 100.millis)
pollingInterval = 15.millis)
subscriptions.start()

teardown:
Expand All @@ -126,9 +127,9 @@ suite "HTTP polling subscriptions - filter not found":
let id = string.fromJson(jsonId).tryGet
check mockServer.newFilterCounter == 1

await sleepAsync(300.millis)
await sleepAsync(50.millis)
mockServer.invalidateFilter(id)
await sleepAsync(300.millis)
await sleepAsync(50.millis)
check mockServer.newFilterCounter == 2

test "recreated filter can be still unsubscribed using the original id":
Expand All @@ -140,12 +141,16 @@ suite "HTTP polling subscriptions - filter not found":
let id = string.fromJson(jsonId).tryGet
check mockServer.newFilterCounter == 1

await sleepAsync(300.millis)
await sleepAsync(50.millis)
mockServer.invalidateFilter(id)
check eventually mockServer.newFilterCounter == 2
check mockServer.filters[id] == false
check mockServer.filters.len() == 2
await subscriptions.unsubscribe(jsonId)
check mockServer.filters.len() == 1


# invalidateFilter sets the filter's value to false which will return the "filter not found"
# unsubscribing will actually delete the key from filters table
# hence after unsubscribing the only key left in the table should be the original id
for key in mockServer.filters.keys():
check key == id

0 comments on commit 7b24ffe

Please sign in to comment.