From 58dd4317791033e1ecad65cffcd21edc7bf3bace Mon Sep 17 00:00:00 2001 From: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> Date: Fri, 9 Apr 2021 22:47:24 +0200 Subject: [PATCH] Fix Windows CI (#467) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Force chronological message history * Fix start/end index computation * Sleep before RPC call * Lower default max cache sizes on APIs Co-authored-by: Oskar Thorén --- tests/v2/test_jsonrpc_waku.nim | 2 ++ tests/v2/test_waku_store.nim | 4 ++++ waku/v2/node/jsonrpc/filter_api.nim | 2 +- waku/v2/node/jsonrpc/relay_api.nim | 2 +- waku/v2/protocol/waku_store/waku_store.nim | 4 ++-- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/v2/test_jsonrpc_waku.nim b/tests/v2/test_jsonrpc_waku.nim index 7d3542b16..39f0aee38 100644 --- a/tests/v2/test_jsonrpc_waku.nim +++ b/tests/v2/test_jsonrpc_waku.nim @@ -372,6 +372,8 @@ procSuite "Waku v2 JSON-RPC API": for x in 1..(maxSize + 1): # Try to cache 1 more than maximum allowed filters.notify(WakuMessage(payload: @[byte x], contentTopic: defaultContentTopic), requestId) + + await sleepAsync(2000.millis) response = await client.get_waku_v2_filter_v1_messages(defaultContentTopic) check: diff --git a/tests/v2/test_waku_store.nim b/tests/v2/test_waku_store.nim index 98e2c5db5..5c6e66e06 100644 --- a/tests/v2/test_waku_store.nim +++ b/tests/v2/test_waku_store.nim @@ -88,6 +88,7 @@ procSuite "Waku Store": listenSwitch.mount(proto) await subscriptions.notify("foo", msg) + await sleepAsync(1.millis) # Sleep a millisecond to ensure messages are stored chronologically await subscriptions.notify("foo", msg2) var completionFut = newFuture[bool]() @@ -162,6 +163,7 @@ procSuite "Waku Store": for wakuMsg in msgList: await subscriptions.notify("foo", wakuMsg) + await sleepAsync(1.millis) # Sleep a millisecond to ensure messages are stored chronologically var completionFut = newFuture[bool]() @@ -212,6 +214,7 @@ procSuite "Waku Store": for wakuMsg in msgList: await subscriptions.notify("foo", wakuMsg) + await sleepAsync(1.millis) # Sleep a millisecond to ensure messages are stored chronologically var completionFut = newFuture[bool]() proc handler(response: HistoryResponse) {.gcsafe, closure.} = @@ -262,6 +265,7 @@ procSuite "Waku Store": for wakuMsg in msgList: await subscriptions.notify("foo", wakuMsg) + await sleepAsync(1.millis) # Sleep a millisecond to ensure messages are stored chronologically var completionFut = newFuture[bool]() proc handler(response: HistoryResponse) {.gcsafe, closure.} = diff --git a/waku/v2/node/jsonrpc/filter_api.nim b/waku/v2/node/jsonrpc/filter_api.nim index 666242c5f..53af00645 100644 --- a/waku/v2/node/jsonrpc/filter_api.nim +++ b/waku/v2/node/jsonrpc/filter_api.nim @@ -14,7 +14,7 @@ logScope: topics = "filter api" const futTimeout* = 5.seconds # Max time to wait for futures -const maxCache* = 100 # Max number of messages cached per topic @TODO make this configurable +const maxCache* = 30 # Max number of messages cached per topic @TODO make this configurable proc installFilterApiHandlers*(node: WakuNode, rpcsrv: RpcServer, messageCache: MessageCache) = diff --git a/waku/v2/node/jsonrpc/relay_api.nim b/waku/v2/node/jsonrpc/relay_api.nim index 3cc4f1c33..e6a404c12 100644 --- a/waku/v2/node/jsonrpc/relay_api.nim +++ b/waku/v2/node/jsonrpc/relay_api.nim @@ -15,7 +15,7 @@ logScope: topics = "relay api" const futTimeout* = 5.seconds # Max time to wait for futures -const maxCache* = 100 # Max number of messages cached per topic @TODO make this configurable +const maxCache* = 30 # Max number of messages cached per topic @TODO make this configurable proc installRelayApiHandlers*(node: WakuNode, rpcsrv: RpcServer, topicCache: TopicCache) = diff --git a/waku/v2/protocol/waku_store/waku_store.nim b/waku/v2/protocol/waku_store/waku_store.nim index ad0bead4f..30c0432c4 100644 --- a/waku/v2/protocol/waku_store/waku_store.nim +++ b/waku/v2/protocol/waku_store/waku_store.nim @@ -242,9 +242,9 @@ proc paginateWithIndex*(list: seq[IndexedWakuMessage], pinfo: PagingInfo): (seq[ initQuery = true # an empty cursor means it is an initial query case dir of PagingDirection.FORWARD: - cursor = list[0].index # perform paging from the begining of the list + cursor = msgList[0].index # perform paging from the begining of the list of PagingDirection.BACKWARD: - cursor = list[list.len - 1].index # perform paging from the end of the list + cursor = msgList[list.len - 1].index # perform paging from the end of the list var foundIndexOption = msgList.findIndex(cursor) # echo "foundIndexOption", foundIndexOption.get() if foundIndexOption.isNone: # the cursor is not valid