2022-11-22 18:40:24 +00:00
|
|
|
{.used.}
|
|
|
|
|
|
|
|
import
|
2024-03-15 23:08:47 +00:00
|
|
|
std/[options, sequtils, random, algorithm], testutils/unittests, chronos, chronicles
|
2022-11-22 18:40:24 +00:00
|
|
|
import
|
2024-07-05 22:03:38 +00:00
|
|
|
waku/
|
|
|
|
[
|
|
|
|
waku_archive,
|
|
|
|
waku_archive/driver/queue_driver,
|
|
|
|
waku_core,
|
|
|
|
waku_core/message/digest,
|
|
|
|
],
|
2023-02-13 10:43:49 +00:00
|
|
|
../testlib/common,
|
2023-04-05 14:01:51 +00:00
|
|
|
../testlib/wakucore
|
2022-11-23 23:58:17 +00:00
|
|
|
|
|
|
|
logScope:
|
|
|
|
topics = "test archive queue_driver"
|
|
|
|
|
|
|
|
# Initialize the random number generator
|
|
|
|
common.randomize()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
proc newTestSqliteDriver(): ArchiveDriver =
|
2024-03-15 23:08:47 +00:00
|
|
|
QueueDriver.new(capacity = 50)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
suite "Queue driver - query by content topic":
|
|
|
|
test "no content topic":
|
|
|
|
## Given
|
|
|
|
const contentTopic = "test-content-topic"
|
|
|
|
|
|
|
|
let driver = newTestSqliteDriver()
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
let expected =
|
|
|
|
@[
|
|
|
|
fakeWakuMessage(@[byte 0], contentTopic = DefaultContentTopic, ts = ts(00)),
|
|
|
|
fakeWakuMessage(@[byte 1], contentTopic = DefaultContentTopic, ts = ts(10)),
|
|
|
|
fakeWakuMessage(@[byte 2], contentTopic = contentTopic, ts = ts(20)),
|
|
|
|
fakeWakuMessage(@[byte 3], contentTopic = contentTopic, ts = ts(30)),
|
|
|
|
fakeWakuMessage(@[byte 4], contentTopic = contentTopic, ts = ts(40)),
|
|
|
|
fakeWakuMessage(@[byte 5], contentTopic = contentTopic, ts = ts(50)),
|
|
|
|
fakeWakuMessage(@[byte 6], contentTopic = contentTopic, ts = ts(60)),
|
|
|
|
fakeWakuMessage(@[byte 7], contentTopic = contentTopic, ts = ts(70)),
|
|
|
|
]
|
2022-11-23 23:58:17 +00:00
|
|
|
var messages = expected
|
|
|
|
|
|
|
|
shuffle(messages)
|
2024-03-15 23:08:47 +00:00
|
|
|
debug "randomized message insertion sequence", sequence = messages.mapIt(it.payload)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
for msg in messages:
|
2024-03-15 23:08:47 +00:00
|
|
|
let retFut = waitFor driver.put(
|
2024-07-12 16:19:12 +00:00
|
|
|
computeMessageHash(DefaultPubsubTopic, msg), DefaultPubsubTopic, msg
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-05-25 15:34:34 +00:00
|
|
|
require retFut.isOk()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## When
|
2024-03-15 23:08:47 +00:00
|
|
|
let res = waitFor driver.getMessages(maxPageSize = 5, ascendingOrder = true)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
res.isOk()
|
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let filteredMessages = res.tryGet().mapIt(it[2])
|
2022-11-22 18:40:24 +00:00
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
filteredMessages == expected[0 .. 4]
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
(waitFor driver.close()).expect("driver to close")
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
test "single content topic":
|
|
|
|
## Given
|
|
|
|
const contentTopic = "test-content-topic"
|
|
|
|
|
|
|
|
let driver = newTestSqliteDriver()
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
let expected =
|
|
|
|
@[
|
|
|
|
fakeWakuMessage(@[byte 0], ts = ts(00)),
|
|
|
|
fakeWakuMessage(@[byte 1], ts = ts(10)),
|
|
|
|
fakeWakuMessage(@[byte 2], contentTopic = contentTopic, ts = ts(20)),
|
|
|
|
fakeWakuMessage(@[byte 3], contentTopic = contentTopic, ts = ts(30)),
|
|
|
|
fakeWakuMessage(@[byte 4], contentTopic = contentTopic, ts = ts(40)),
|
|
|
|
fakeWakuMessage(@[byte 5], contentTopic = contentTopic, ts = ts(50)),
|
|
|
|
fakeWakuMessage(@[byte 6], contentTopic = contentTopic, ts = ts(60)),
|
|
|
|
fakeWakuMessage(@[byte 7], contentTopic = contentTopic, ts = ts(70)),
|
|
|
|
]
|
2022-11-23 23:58:17 +00:00
|
|
|
var messages = expected
|
|
|
|
|
|
|
|
shuffle(messages)
|
2024-03-15 23:08:47 +00:00
|
|
|
debug "randomized message insertion sequence", sequence = messages.mapIt(it.payload)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
for msg in messages:
|
2024-03-15 23:08:47 +00:00
|
|
|
let retFut = waitFor driver.put(
|
2024-07-12 16:19:12 +00:00
|
|
|
computeMessageHash(DefaultPubsubTopic, msg), DefaultPubsubTopic, msg
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-05-25 15:34:34 +00:00
|
|
|
require retFut.isOk()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## When
|
2023-05-25 15:34:34 +00:00
|
|
|
let res = waitFor driver.getMessages(
|
2024-07-12 16:19:12 +00:00
|
|
|
contentTopics = @[contentTopic], maxPageSize = 2, ascendingOrder = true
|
2022-11-22 18:40:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
res.isOk()
|
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let filteredMessages = res.tryGet().mapIt(it[2])
|
2022-11-22 18:40:24 +00:00
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
filteredMessages == expected[2 .. 3]
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
(waitFor driver.close()).expect("driver to close")
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
test "single content topic - descending order":
|
|
|
|
## Given
|
|
|
|
const contentTopic = "test-content-topic"
|
|
|
|
|
|
|
|
let driver = newTestSqliteDriver()
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
let expected =
|
|
|
|
@[
|
|
|
|
fakeWakuMessage(@[byte 0], ts = ts(00)),
|
|
|
|
fakeWakuMessage(@[byte 1], ts = ts(10)),
|
|
|
|
fakeWakuMessage(@[byte 2], contentTopic = contentTopic, ts = ts(20)),
|
|
|
|
fakeWakuMessage(@[byte 3], contentTopic = contentTopic, ts = ts(30)),
|
|
|
|
fakeWakuMessage(@[byte 4], contentTopic = contentTopic, ts = ts(40)),
|
|
|
|
fakeWakuMessage(@[byte 5], contentTopic = contentTopic, ts = ts(50)),
|
|
|
|
fakeWakuMessage(@[byte 6], contentTopic = contentTopic, ts = ts(60)),
|
|
|
|
fakeWakuMessage(@[byte 7], contentTopic = contentTopic, ts = ts(70)),
|
|
|
|
]
|
2022-11-23 23:58:17 +00:00
|
|
|
var messages = expected
|
|
|
|
|
|
|
|
shuffle(messages)
|
2024-03-15 23:08:47 +00:00
|
|
|
debug "randomized message insertion sequence", sequence = messages.mapIt(it.payload)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
for msg in messages:
|
2024-03-15 23:08:47 +00:00
|
|
|
let retFut = waitFor driver.put(
|
2024-07-12 16:19:12 +00:00
|
|
|
computeMessageHash(DefaultPubsubTopic, msg), DefaultPubsubTopic, msg
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-05-25 15:34:34 +00:00
|
|
|
require retFut.isOk()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## When
|
2023-05-25 15:34:34 +00:00
|
|
|
let res = waitFor driver.getMessages(
|
2024-07-12 16:19:12 +00:00
|
|
|
contentTopics = @[contentTopic], maxPageSize = 2, ascendingOrder = false
|
2022-11-22 18:40:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
res.isOk()
|
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let filteredMessages = res.tryGet().mapIt(it[2])
|
2022-11-22 18:40:24 +00:00
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
filteredMessages == expected[6 .. 7].reversed()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
(waitFor driver.close()).expect("driver to close")
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
test "multiple content topic":
|
|
|
|
## Given
|
|
|
|
const contentTopic1 = "test-content-topic-1"
|
|
|
|
const contentTopic2 = "test-content-topic-2"
|
|
|
|
const contentTopic3 = "test-content-topic-3"
|
|
|
|
|
|
|
|
let driver = newTestSqliteDriver()
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
let expected =
|
|
|
|
@[
|
|
|
|
fakeWakuMessage(@[byte 0], ts = ts(00)),
|
|
|
|
fakeWakuMessage(@[byte 1], ts = ts(10)),
|
|
|
|
fakeWakuMessage(@[byte 2], contentTopic = contentTopic1, ts = ts(20)),
|
|
|
|
fakeWakuMessage(@[byte 3], contentTopic = contentTopic2, ts = ts(30)),
|
|
|
|
fakeWakuMessage(@[byte 4], contentTopic = contentTopic3, ts = ts(40)),
|
|
|
|
fakeWakuMessage(@[byte 5], contentTopic = contentTopic1, ts = ts(50)),
|
|
|
|
fakeWakuMessage(@[byte 6], contentTopic = contentTopic2, ts = ts(60)),
|
|
|
|
fakeWakuMessage(@[byte 7], contentTopic = contentTopic3, ts = ts(70)),
|
|
|
|
]
|
2022-11-23 23:58:17 +00:00
|
|
|
var messages = expected
|
|
|
|
|
|
|
|
shuffle(messages)
|
2024-03-15 23:08:47 +00:00
|
|
|
debug "randomized message insertion sequence", sequence = messages.mapIt(it.payload)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
for msg in messages:
|
2024-03-15 23:08:47 +00:00
|
|
|
let retFut = waitFor driver.put(
|
2024-07-12 16:19:12 +00:00
|
|
|
computeMessageHash(DefaultPubsubTopic, msg), DefaultPubsubTopic, msg
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-05-25 15:34:34 +00:00
|
|
|
require retFut.isOk()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## When
|
2023-05-25 15:34:34 +00:00
|
|
|
let res = waitFor driver.getMessages(
|
2024-07-12 16:19:12 +00:00
|
|
|
contentTopics = @[contentTopic1, contentTopic2],
|
2024-03-15 23:08:47 +00:00
|
|
|
maxPageSize = 2,
|
|
|
|
ascendingOrder = true,
|
2022-11-22 18:40:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
res.isOk()
|
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let filteredMessages = res.tryGet().mapIt(it[2])
|
2022-11-22 18:40:24 +00:00
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
filteredMessages == expected[2 .. 3]
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
(waitFor driver.close()).expect("driver to close")
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
test "single content topic - no results":
|
|
|
|
## Given
|
|
|
|
const contentTopic = "test-content-topic"
|
|
|
|
|
|
|
|
let driver = newTestSqliteDriver()
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
let expected =
|
|
|
|
@[
|
|
|
|
fakeWakuMessage(@[byte 0], contentTopic = DefaultContentTopic, ts = ts(00)),
|
|
|
|
fakeWakuMessage(@[byte 1], contentTopic = DefaultContentTopic, ts = ts(10)),
|
|
|
|
fakeWakuMessage(@[byte 2], contentTopic = DefaultContentTopic, ts = ts(20)),
|
|
|
|
fakeWakuMessage(@[byte 3], contentTopic = DefaultContentTopic, ts = ts(30)),
|
|
|
|
fakeWakuMessage(@[byte 4], contentTopic = DefaultContentTopic, ts = ts(40)),
|
|
|
|
]
|
2022-11-23 23:58:17 +00:00
|
|
|
var messages = expected
|
|
|
|
|
|
|
|
shuffle(messages)
|
2024-03-15 23:08:47 +00:00
|
|
|
debug "randomized message insertion sequence", sequence = messages.mapIt(it.payload)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
for msg in messages:
|
2024-03-15 23:08:47 +00:00
|
|
|
let retFut = waitFor driver.put(
|
2024-07-12 16:19:12 +00:00
|
|
|
computeMessageHash(DefaultPubsubTopic, msg), DefaultPubsubTopic, msg
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-05-25 15:34:34 +00:00
|
|
|
require retFut.isOk()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## When
|
2023-05-25 15:34:34 +00:00
|
|
|
let res = waitFor driver.getMessages(
|
2024-07-12 16:19:12 +00:00
|
|
|
contentTopics = @[contentTopic], maxPageSize = 2, ascendingOrder = true
|
2022-11-22 18:40:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
res.isOk()
|
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let filteredMessages = res.tryGet().mapIt(it[2])
|
2022-11-22 18:40:24 +00:00
|
|
|
check:
|
|
|
|
filteredMessages.len == 0
|
|
|
|
|
|
|
|
## Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
(waitFor driver.close()).expect("driver to close")
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
test "content topic and max page size - not enough messages stored":
|
|
|
|
## Given
|
|
|
|
const pageSize: uint = 50
|
|
|
|
|
|
|
|
let driver = newTestSqliteDriver()
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
for t in 0 ..< 40:
|
|
|
|
let msg = fakeWakuMessage(@[byte t], DefaultContentTopic, ts = ts(t))
|
|
|
|
let retFut = waitFor driver.put(
|
2024-07-12 16:19:12 +00:00
|
|
|
computeMessageHash(DefaultPubsubTopic, msg), DefaultPubsubTopic, msg
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-05-25 15:34:34 +00:00
|
|
|
require retFut.isOk()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## When
|
2023-05-25 15:34:34 +00:00
|
|
|
let res = waitFor driver.getMessages(
|
2024-07-12 16:19:12 +00:00
|
|
|
contentTopics = @[DefaultContentTopic],
|
2024-03-15 23:08:47 +00:00
|
|
|
maxPageSize = pageSize,
|
|
|
|
ascendingOrder = true,
|
2022-11-22 18:40:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
res.isOk()
|
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let filteredMessages = res.tryGet().mapIt(it[2])
|
2022-11-22 18:40:24 +00:00
|
|
|
check:
|
|
|
|
filteredMessages.len == 40
|
|
|
|
|
|
|
|
## Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
(waitFor driver.close()).expect("driver to close")
|
2022-11-22 18:40:24 +00:00
|
|
|
|
2022-11-23 23:58:17 +00:00
|
|
|
suite "SQLite driver - query by pubsub topic":
|
2022-11-22 18:40:24 +00:00
|
|
|
test "pubsub topic":
|
|
|
|
## Given
|
|
|
|
const contentTopic = "test-content-topic"
|
|
|
|
const pubsubTopic = "test-pubsub-topic"
|
|
|
|
|
|
|
|
let driver = newTestSqliteDriver()
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
let expected =
|
|
|
|
@[
|
|
|
|
(DefaultPubsubTopic, fakeWakuMessage(@[byte 0], ts = ts(00))),
|
|
|
|
(DefaultPubsubTopic, fakeWakuMessage(@[byte 1], ts = ts(10))),
|
|
|
|
(
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
fakeWakuMessage(@[byte 2], contentTopic = contentTopic, ts = ts(20)),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
fakeWakuMessage(@[byte 3], contentTopic = contentTopic, ts = ts(30)),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(@[byte 4], contentTopic = contentTopic, ts = ts(40)),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(@[byte 5], contentTopic = contentTopic, ts = ts(50)),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(@[byte 6], contentTopic = contentTopic, ts = ts(60)),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(@[byte 7], contentTopic = contentTopic, ts = ts(70)),
|
|
|
|
),
|
|
|
|
]
|
2022-11-23 23:58:17 +00:00
|
|
|
var messages = expected
|
|
|
|
|
|
|
|
shuffle(messages)
|
2024-03-15 23:08:47 +00:00
|
|
|
debug "randomized message insertion sequence",
|
|
|
|
sequence = messages.mapIt(it[1].payload)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
for row in messages:
|
|
|
|
let (topic, msg) = row
|
2024-07-12 16:19:12 +00:00
|
|
|
let retFut = waitFor driver.put(computeMessageHash(topic, msg), topic, msg)
|
2023-05-25 15:34:34 +00:00
|
|
|
require retFut.isOk()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## When
|
2023-05-25 15:34:34 +00:00
|
|
|
let res = waitFor driver.getMessages(
|
2024-03-15 23:08:47 +00:00
|
|
|
pubsubTopic = some(pubsubTopic), maxPageSize = 2, ascendingOrder = true
|
2022-11-22 18:40:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
res.isOk()
|
|
|
|
|
2022-11-23 23:58:17 +00:00
|
|
|
let expectedMessages = expected.mapIt(it[1])
|
2024-07-12 16:19:12 +00:00
|
|
|
let filteredMessages = res.tryGet().mapIt(it[2])
|
2022-11-22 18:40:24 +00:00
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
filteredMessages == expectedMessages[4 .. 5]
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
(waitFor driver.close()).expect("driver to close")
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
test "no pubsub topic":
|
|
|
|
## Given
|
|
|
|
const contentTopic = "test-content-topic"
|
|
|
|
const pubsubTopic = "test-pubsub-topic"
|
|
|
|
|
|
|
|
let driver = newTestSqliteDriver()
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
let expected =
|
|
|
|
@[
|
|
|
|
(DefaultPubsubTopic, fakeWakuMessage(@[byte 0], ts = ts(00))),
|
|
|
|
(DefaultPubsubTopic, fakeWakuMessage(@[byte 1], ts = ts(10))),
|
|
|
|
(
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
fakeWakuMessage(@[byte 2], contentTopic = contentTopic, ts = ts(20)),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
fakeWakuMessage(@[byte 3], contentTopic = contentTopic, ts = ts(30)),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(@[byte 4], contentTopic = contentTopic, ts = ts(40)),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(@[byte 5], contentTopic = contentTopic, ts = ts(50)),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(@[byte 6], contentTopic = contentTopic, ts = ts(60)),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(@[byte 7], contentTopic = contentTopic, ts = ts(70)),
|
|
|
|
),
|
|
|
|
]
|
2022-11-23 23:58:17 +00:00
|
|
|
var messages = expected
|
|
|
|
|
|
|
|
shuffle(messages)
|
2024-03-15 23:08:47 +00:00
|
|
|
debug "randomized message insertion sequence",
|
|
|
|
sequence = messages.mapIt(it[1].payload)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
for row in messages:
|
|
|
|
let (topic, msg) = row
|
2024-07-12 16:19:12 +00:00
|
|
|
let retFut = waitFor driver.put(computeMessageHash(topic, msg), topic, msg)
|
2023-05-25 15:34:34 +00:00
|
|
|
require retFut.isOk()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## When
|
2024-03-15 23:08:47 +00:00
|
|
|
let res = waitFor driver.getMessages(maxPageSize = 2, ascendingOrder = true)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
res.isOk()
|
|
|
|
|
2022-11-23 23:58:17 +00:00
|
|
|
let expectedMessages = expected.mapIt(it[1])
|
2024-07-12 16:19:12 +00:00
|
|
|
let filteredMessages = res.tryGet().mapIt(it[2])
|
2022-11-22 18:40:24 +00:00
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
filteredMessages == expectedMessages[0 .. 1]
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
(waitFor driver.close()).expect("driver to close")
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
test "content topic and pubsub topic":
|
|
|
|
## Given
|
|
|
|
const contentTopic = "test-content-topic"
|
|
|
|
const pubsubTopic = "test-pubsub-topic"
|
|
|
|
|
|
|
|
let driver = newTestSqliteDriver()
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
let expected =
|
|
|
|
@[
|
|
|
|
(DefaultPubsubTopic, fakeWakuMessage(@[byte 0], ts = ts(00))),
|
|
|
|
(DefaultPubsubTopic, fakeWakuMessage(@[byte 1], ts = ts(10))),
|
|
|
|
(
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
fakeWakuMessage(@[byte 2], contentTopic = contentTopic, ts = ts(20)),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
fakeWakuMessage(@[byte 3], contentTopic = contentTopic, ts = ts(30)),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(@[byte 4], contentTopic = contentTopic, ts = ts(40)),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(@[byte 5], contentTopic = contentTopic, ts = ts(50)),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(@[byte 6], contentTopic = contentTopic, ts = ts(60)),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(@[byte 7], contentTopic = contentTopic, ts = ts(70)),
|
|
|
|
),
|
|
|
|
]
|
2022-11-23 23:58:17 +00:00
|
|
|
var messages = expected
|
|
|
|
|
|
|
|
shuffle(messages)
|
2024-03-15 23:08:47 +00:00
|
|
|
debug "randomized message insertion sequence",
|
|
|
|
sequence = messages.mapIt(it[1].payload)
|
2022-11-23 23:58:17 +00:00
|
|
|
|
2022-11-22 18:40:24 +00:00
|
|
|
for row in messages:
|
|
|
|
let (topic, msg) = row
|
2024-07-12 16:19:12 +00:00
|
|
|
let retFut = waitFor driver.put(computeMessageHash(topic, msg), topic, msg)
|
2023-05-25 15:34:34 +00:00
|
|
|
require retFut.isOk()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## When
|
2023-05-25 15:34:34 +00:00
|
|
|
let res = waitFor driver.getMessages(
|
2024-07-12 16:19:12 +00:00
|
|
|
contentTopics = @[contentTopic],
|
2024-03-15 23:08:47 +00:00
|
|
|
pubsubTopic = some(pubsubTopic),
|
|
|
|
maxPageSize = 2,
|
|
|
|
ascendingOrder = true,
|
2022-11-22 18:40:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
res.isOk()
|
|
|
|
|
2022-11-23 23:58:17 +00:00
|
|
|
let expectedMessages = expected.mapIt(it[1])
|
2024-07-12 16:19:12 +00:00
|
|
|
let filteredMessages = res.tryGet().mapIt(it[2])
|
2022-11-22 18:40:24 +00:00
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
filteredMessages == expectedMessages[4 .. 5]
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
(waitFor driver.close()).expect("driver to close")
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
suite "Queue driver - query by cursor":
|
|
|
|
test "only cursor":
|
|
|
|
## Given
|
|
|
|
const contentTopic = "test-content-topic"
|
|
|
|
|
|
|
|
let driver = newTestSqliteDriver()
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
let expected =
|
|
|
|
@[
|
|
|
|
fakeWakuMessage(@[byte 0], ts = ts(00)),
|
|
|
|
fakeWakuMessage(@[byte 1], ts = ts(10)),
|
|
|
|
fakeWakuMessage(@[byte 2], contentTopic = contentTopic, ts = ts(20)),
|
|
|
|
fakeWakuMessage(@[byte 3], contentTopic = contentTopic, ts = ts(30)),
|
|
|
|
fakeWakuMessage(@[byte 4], contentTopic = contentTopic, ts = ts(40)),
|
|
|
|
# << cursor
|
|
|
|
fakeWakuMessage(@[byte 5], contentTopic = contentTopic, ts = ts(50)),
|
|
|
|
fakeWakuMessage(@[byte 6], contentTopic = contentTopic, ts = ts(60)),
|
|
|
|
fakeWakuMessage(@[byte 7], contentTopic = contentTopic, ts = ts(70)),
|
|
|
|
]
|
2022-11-23 23:58:17 +00:00
|
|
|
var messages = expected
|
|
|
|
|
|
|
|
shuffle(messages)
|
2024-03-15 23:08:47 +00:00
|
|
|
debug "randomized message insertion sequence", sequence = messages.mapIt(it.payload)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
for msg in messages:
|
2024-03-15 23:08:47 +00:00
|
|
|
let retFut = waitFor driver.put(
|
2024-07-12 16:19:12 +00:00
|
|
|
computeMessageHash(DefaultPubsubTopic, msg), DefaultPubsubTopic, msg
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-05-25 15:34:34 +00:00
|
|
|
require retFut.isOk()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let cursor = computeMessageHash(DefaultPubsubTopic, expected[4])
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## When
|
2023-05-25 15:34:34 +00:00
|
|
|
let res = waitFor driver.getMessages(
|
2024-03-15 23:08:47 +00:00
|
|
|
cursor = some(cursor), maxPageSize = 2, ascendingOrder = true
|
2022-11-22 18:40:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
res.isOk()
|
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let filteredMessages = res.tryGet().mapIt(it[2])
|
2022-11-22 18:40:24 +00:00
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
filteredMessages == expected[5 .. 6]
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
(waitFor driver.close()).expect("driver to close")
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
test "only cursor - descending order":
|
|
|
|
## Given
|
|
|
|
const contentTopic = "test-content-topic"
|
|
|
|
|
|
|
|
let driver = newTestSqliteDriver()
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
let expected =
|
|
|
|
@[
|
|
|
|
fakeWakuMessage(@[byte 0], ts = ts(00)),
|
|
|
|
fakeWakuMessage(@[byte 1], ts = ts(10)),
|
|
|
|
fakeWakuMessage(@[byte 2], contentTopic = contentTopic, ts = ts(20)),
|
|
|
|
fakeWakuMessage(@[byte 3], contentTopic = contentTopic, ts = ts(30)),
|
|
|
|
fakeWakuMessage(@[byte 4], contentTopic = contentTopic, ts = ts(40)),
|
|
|
|
# << cursor
|
|
|
|
fakeWakuMessage(@[byte 5], contentTopic = contentTopic, ts = ts(50)),
|
|
|
|
fakeWakuMessage(@[byte 6], contentTopic = contentTopic, ts = ts(60)),
|
|
|
|
fakeWakuMessage(@[byte 7], contentTopic = contentTopic, ts = ts(70)),
|
|
|
|
]
|
2022-11-23 23:58:17 +00:00
|
|
|
var messages = expected
|
|
|
|
|
|
|
|
shuffle(messages)
|
2024-03-15 23:08:47 +00:00
|
|
|
debug "randomized message insertion sequence", sequence = messages.mapIt(it.payload)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
for msg in messages:
|
2024-03-15 23:08:47 +00:00
|
|
|
let retFut = waitFor driver.put(
|
2024-07-12 16:19:12 +00:00
|
|
|
computeMessageHash(DefaultPubsubTopic, msg), DefaultPubsubTopic, msg
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-05-25 15:34:34 +00:00
|
|
|
require retFut.isOk()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let cursor = computeMessageHash(DefaultPubsubTopic, expected[4])
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## When
|
2023-05-25 15:34:34 +00:00
|
|
|
let res = waitFor driver.getMessages(
|
2024-03-15 23:08:47 +00:00
|
|
|
cursor = some(cursor), maxPageSize = 2, ascendingOrder = false
|
2022-11-22 18:40:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
res.isOk()
|
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let filteredMessages = res.tryGet().mapIt(it[2])
|
2022-11-22 18:40:24 +00:00
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
filteredMessages == expected[2 .. 3].reversed()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
(waitFor driver.close()).expect("driver to close")
|
2022-11-22 18:40:24 +00:00
|
|
|
|
2024-05-23 12:01:52 +00:00
|
|
|
test "only cursor - invalid":
|
|
|
|
## Given
|
|
|
|
const contentTopic = "test-content-topic"
|
|
|
|
|
|
|
|
let driver = newTestSqliteDriver()
|
|
|
|
|
|
|
|
var messages =
|
|
|
|
@[
|
|
|
|
fakeWakuMessage(@[byte 0], ts = ts(00)),
|
|
|
|
fakeWakuMessage(@[byte 1], ts = ts(10)),
|
|
|
|
fakeWakuMessage(@[byte 2], contentTopic = contentTopic, ts = ts(20)),
|
|
|
|
fakeWakuMessage(@[byte 3], contentTopic = contentTopic, ts = ts(30)),
|
|
|
|
fakeWakuMessage(@[byte 4], contentTopic = contentTopic, ts = ts(40)),
|
|
|
|
fakeWakuMessage(@[byte 5], contentTopic = contentTopic, ts = ts(50)),
|
|
|
|
fakeWakuMessage(@[byte 6], contentTopic = contentTopic, ts = ts(60)),
|
|
|
|
fakeWakuMessage(@[byte 7], contentTopic = contentTopic, ts = ts(70)),
|
|
|
|
]
|
|
|
|
|
|
|
|
shuffle(messages)
|
|
|
|
debug "randomized message insertion sequence", sequence = messages.mapIt(it.payload)
|
|
|
|
|
|
|
|
for msg in messages:
|
|
|
|
let retFut = waitFor driver.put(
|
2024-07-12 16:19:12 +00:00
|
|
|
computeMessageHash(DefaultPubsubTopic, msg), DefaultPubsubTopic, msg
|
2024-05-23 12:01:52 +00:00
|
|
|
)
|
|
|
|
require retFut.isOk()
|
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let cursor = computeMessageHash(DefaultPubsubTopic, fakeWakuMessage())
|
2024-05-23 12:01:52 +00:00
|
|
|
|
|
|
|
## When
|
|
|
|
let res = waitFor driver.getMessages(
|
2024-05-27 14:54:10 +00:00
|
|
|
includeData = true,
|
2024-07-12 16:19:12 +00:00
|
|
|
contentTopics = @[DefaultContentTopic],
|
2024-05-27 14:54:10 +00:00
|
|
|
pubsubTopic = none(PubsubTopic),
|
|
|
|
cursor = some(cursor),
|
|
|
|
startTime = none(Timestamp),
|
|
|
|
endTime = none(Timestamp),
|
|
|
|
hashes = @[],
|
|
|
|
maxPageSize = 5,
|
|
|
|
ascendingOrder = true,
|
2024-05-23 12:01:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
res.isErr()
|
|
|
|
res.error == "invalid_cursor"
|
|
|
|
|
|
|
|
## Cleanup
|
|
|
|
(waitFor driver.close()).expect("driver to close")
|
|
|
|
|
2022-11-22 18:40:24 +00:00
|
|
|
test "content topic and cursor":
|
|
|
|
## Given
|
|
|
|
const contentTopic = "test-content-topic"
|
|
|
|
|
|
|
|
let driver = newTestSqliteDriver()
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
let expected =
|
|
|
|
@[
|
|
|
|
fakeWakuMessage(@[byte 0], ts = ts(00)),
|
|
|
|
fakeWakuMessage(@[byte 1], ts = ts(10)),
|
|
|
|
fakeWakuMessage(@[byte 2], contentTopic = contentTopic, ts = ts(20)),
|
|
|
|
fakeWakuMessage(@[byte 3], contentTopic = contentTopic, ts = ts(30)),
|
|
|
|
fakeWakuMessage(@[byte 4], contentTopic = contentTopic, ts = ts(40)),
|
|
|
|
# << cursor
|
|
|
|
fakeWakuMessage(@[byte 5], contentTopic = contentTopic, ts = ts(50)),
|
|
|
|
fakeWakuMessage(@[byte 6], contentTopic = contentTopic, ts = ts(60)),
|
|
|
|
fakeWakuMessage(@[byte 7], ts = ts(70)),
|
|
|
|
]
|
2022-11-23 23:58:17 +00:00
|
|
|
var messages = expected
|
|
|
|
|
|
|
|
shuffle(messages)
|
2024-03-15 23:08:47 +00:00
|
|
|
debug "randomized message insertion sequence", sequence = messages.mapIt(it.payload)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
for msg in messages:
|
2024-03-15 23:08:47 +00:00
|
|
|
let retFut = waitFor driver.put(
|
2024-07-12 16:19:12 +00:00
|
|
|
computeMessageHash(DefaultPubsubTopic, msg), DefaultPubsubTopic, msg
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-05-25 15:34:34 +00:00
|
|
|
require retFut.isOk()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let cursor = computeMessageHash(DefaultPubsubTopic, expected[4])
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## When
|
2023-05-25 15:34:34 +00:00
|
|
|
let res = waitFor driver.getMessages(
|
2024-07-12 16:19:12 +00:00
|
|
|
contentTopics = @[contentTopic],
|
2024-03-15 23:08:47 +00:00
|
|
|
cursor = some(cursor),
|
|
|
|
maxPageSize = 10,
|
|
|
|
ascendingOrder = true,
|
2022-11-22 18:40:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
res.isOk()
|
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let filteredMessages = res.tryGet().mapIt(it[2])
|
2022-11-22 18:40:24 +00:00
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
filteredMessages == expected[5 .. 6]
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
(waitFor driver.close()).expect("driver to close")
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
test "content topic and cursor - descending order":
|
|
|
|
## Given
|
|
|
|
const contentTopic = "test-content-topic"
|
|
|
|
|
|
|
|
let driver = newTestSqliteDriver()
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
let expected =
|
|
|
|
@[
|
|
|
|
fakeWakuMessage(@[byte 0], ts = ts(00)),
|
|
|
|
fakeWakuMessage(@[byte 1], ts = ts(10)),
|
|
|
|
fakeWakuMessage(@[byte 2], contentTopic = contentTopic, ts = ts(20)),
|
|
|
|
fakeWakuMessage(@[byte 3], contentTopic = contentTopic, ts = ts(30)),
|
|
|
|
fakeWakuMessage(@[byte 4], contentTopic = contentTopic, ts = ts(40)),
|
|
|
|
fakeWakuMessage(@[byte 5], contentTopic = contentTopic, ts = ts(50)),
|
|
|
|
fakeWakuMessage(@[byte 6], contentTopic = contentTopic, ts = ts(60)),
|
|
|
|
# << cursor
|
|
|
|
fakeWakuMessage(@[byte 7], contentTopic = contentTopic, ts = ts(70)),
|
|
|
|
]
|
2022-11-23 23:58:17 +00:00
|
|
|
var messages = expected
|
|
|
|
|
|
|
|
shuffle(messages)
|
2024-03-15 23:08:47 +00:00
|
|
|
debug "randomized message insertion sequence", sequence = messages.mapIt(it.payload)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
for msg in messages:
|
2024-03-15 23:08:47 +00:00
|
|
|
let retFut = waitFor driver.put(
|
2024-07-12 16:19:12 +00:00
|
|
|
computeMessageHash(DefaultPubsubTopic, msg), DefaultPubsubTopic, msg
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-05-25 15:34:34 +00:00
|
|
|
require retFut.isOk()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let cursor = computeMessageHash(DefaultPubsubTopic, expected[6])
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## When
|
2023-05-25 15:34:34 +00:00
|
|
|
let res = waitFor driver.getMessages(
|
2024-07-12 16:19:12 +00:00
|
|
|
contentTopics = @[contentTopic],
|
2024-03-15 23:08:47 +00:00
|
|
|
cursor = some(cursor),
|
|
|
|
maxPageSize = 10,
|
|
|
|
ascendingOrder = false,
|
2022-11-22 18:40:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
res.isOk()
|
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let filteredMessages = res.tryGet().mapIt(it[2])
|
2022-11-22 18:40:24 +00:00
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
filteredMessages == expected[2 .. 5].reversed()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
(waitFor driver.close()).expect("driver to close")
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
test "pubsub topic and cursor":
|
|
|
|
## Given
|
|
|
|
const contentTopic = "test-content-topic"
|
|
|
|
const pubsubTopic = "test-pubsub-topic"
|
|
|
|
|
|
|
|
let driver = newTestSqliteDriver()
|
|
|
|
|
|
|
|
let timeOrigin = now()
|
2024-03-15 23:08:47 +00:00
|
|
|
let expected =
|
|
|
|
@[
|
|
|
|
(DefaultPubsubTopic, fakeWakuMessage(@[byte 0], ts = ts(00, timeOrigin))),
|
|
|
|
(DefaultPubsubTopic, fakeWakuMessage(@[byte 1], ts = ts(10, timeOrigin))),
|
|
|
|
(
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 2], contentTopic = contentTopic, ts = ts(20, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 3], contentTopic = contentTopic, ts = ts(30, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 4], contentTopic = contentTopic, ts = ts(40, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 5], contentTopic = contentTopic, ts = ts(50, timeOrigin)
|
|
|
|
),
|
|
|
|
), # << cursor
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 6], contentTopic = contentTopic, ts = ts(60, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 7], contentTopic = contentTopic, ts = ts(70, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 8], contentTopic = contentTopic, ts = ts(80, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 9], contentTopic = contentTopic, ts = ts(90, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
]
|
2022-11-23 23:58:17 +00:00
|
|
|
var messages = expected
|
|
|
|
|
|
|
|
shuffle(messages)
|
2024-03-15 23:08:47 +00:00
|
|
|
debug "randomized message insertion sequence",
|
|
|
|
sequence = messages.mapIt(it[1].payload)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
for row in messages:
|
|
|
|
let (topic, msg) = row
|
2024-07-12 16:19:12 +00:00
|
|
|
let retFut = waitFor driver.put(computeMessageHash(topic, msg), topic, msg)
|
2023-05-25 15:34:34 +00:00
|
|
|
require retFut.isOk()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let cursor = computeMessageHash(expected[5][0], expected[5][1])
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## When
|
2023-05-25 15:34:34 +00:00
|
|
|
let res = waitFor driver.getMessages(
|
2024-03-15 23:08:47 +00:00
|
|
|
pubsubTopic = some(pubsubTopic),
|
|
|
|
cursor = some(cursor),
|
|
|
|
maxPageSize = 10,
|
|
|
|
ascendingOrder = true,
|
2022-11-22 18:40:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
res.isOk()
|
|
|
|
|
2022-11-23 23:58:17 +00:00
|
|
|
let expectedMessages = expected.mapIt(it[1])
|
2024-07-12 16:19:12 +00:00
|
|
|
let filteredMessages = res.tryGet().mapIt(it[2])
|
2022-11-22 18:40:24 +00:00
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
filteredMessages == expectedMessages[6 .. 7]
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
(waitFor driver.close()).expect("driver to close")
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
test "pubsub topic and cursor - descending order":
|
|
|
|
## Given
|
|
|
|
const contentTopic = "test-content-topic"
|
|
|
|
const pubsubTopic = "test-pubsub-topic"
|
|
|
|
|
|
|
|
let driver = newTestSqliteDriver()
|
|
|
|
|
|
|
|
let timeOrigin = now()
|
2024-03-15 23:08:47 +00:00
|
|
|
let expected =
|
|
|
|
@[
|
|
|
|
(DefaultPubsubTopic, fakeWakuMessage(@[byte 0], ts = ts(00, timeOrigin))),
|
|
|
|
(DefaultPubsubTopic, fakeWakuMessage(@[byte 1], ts = ts(10, timeOrigin))),
|
|
|
|
(
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 2], contentTopic = contentTopic, ts = ts(20, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 3], contentTopic = contentTopic, ts = ts(30, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 4], contentTopic = contentTopic, ts = ts(40, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 5], contentTopic = contentTopic, ts = ts(50, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 6], contentTopic = contentTopic, ts = ts(60, timeOrigin)
|
|
|
|
),
|
|
|
|
), # << cursor
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 7], contentTopic = contentTopic, ts = ts(70, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 8], contentTopic = contentTopic, ts = ts(80, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 9], contentTopic = contentTopic, ts = ts(90, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
]
|
2022-11-23 23:58:17 +00:00
|
|
|
var messages = expected
|
|
|
|
|
|
|
|
shuffle(messages)
|
2024-03-15 23:08:47 +00:00
|
|
|
debug "randomized message insertion sequence",
|
|
|
|
sequence = messages.mapIt(it[1].payload)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
for row in messages:
|
|
|
|
let (topic, msg) = row
|
2024-07-12 16:19:12 +00:00
|
|
|
let retFut = waitFor driver.put(computeMessageHash(topic, msg), topic, msg)
|
2023-05-25 15:34:34 +00:00
|
|
|
require retFut.isOk()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let cursor = computeMessageHash(expected[6][0], expected[6][1])
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## When
|
2023-05-25 15:34:34 +00:00
|
|
|
let res = waitFor driver.getMessages(
|
2024-03-15 23:08:47 +00:00
|
|
|
pubsubTopic = some(pubsubTopic),
|
|
|
|
cursor = some(cursor),
|
|
|
|
maxPageSize = 10,
|
|
|
|
ascendingOrder = false,
|
2022-11-22 18:40:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
res.isOk()
|
|
|
|
|
2022-11-23 23:58:17 +00:00
|
|
|
let expectedMessages = expected.mapIt(it[1])
|
2024-07-12 16:19:12 +00:00
|
|
|
let filteredMessages = res.tryGet().mapIt(it[2])
|
2022-11-22 18:40:24 +00:00
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
filteredMessages == expectedMessages[4 .. 5].reversed()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
(waitFor driver.close()).expect("driver to close")
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
suite "Queue driver - query by time range":
|
|
|
|
test "start time only":
|
|
|
|
## Given
|
|
|
|
const contentTopic = "test-content-topic"
|
|
|
|
|
|
|
|
let driver = newTestSqliteDriver()
|
|
|
|
|
|
|
|
let timeOrigin = now()
|
2024-03-15 23:08:47 +00:00
|
|
|
let expected =
|
|
|
|
@[
|
|
|
|
fakeWakuMessage(@[byte 0], contentTopic = contentTopic, ts = ts(00, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 1], contentTopic = contentTopic, ts = ts(10, timeOrigin)),
|
|
|
|
# start_time
|
|
|
|
fakeWakuMessage(@[byte 2], contentTopic = contentTopic, ts = ts(20, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 3], contentTopic = contentTopic, ts = ts(30, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 4], contentTopic = contentTopic, ts = ts(40, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 5], contentTopic = contentTopic, ts = ts(50, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 6], contentTopic = contentTopic, ts = ts(60, timeOrigin)),
|
|
|
|
]
|
2022-11-23 23:58:17 +00:00
|
|
|
var messages = expected
|
|
|
|
|
|
|
|
shuffle(messages)
|
2024-03-15 23:08:47 +00:00
|
|
|
debug "randomized message insertion sequence", sequence = messages.mapIt(it.payload)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
for msg in messages:
|
2024-03-15 23:08:47 +00:00
|
|
|
let retFut = waitFor driver.put(
|
2024-07-12 16:19:12 +00:00
|
|
|
computeMessageHash(DefaultPubsubTopic, msg), DefaultPubsubTopic, msg
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-05-25 15:34:34 +00:00
|
|
|
require retFut.isOk()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## When
|
2023-05-25 15:34:34 +00:00
|
|
|
let res = waitFor driver.getMessages(
|
2024-03-15 23:08:47 +00:00
|
|
|
startTime = some(ts(15, timeOrigin)), maxPageSize = 10, ascendingOrder = true
|
2022-11-22 18:40:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
res.isOk()
|
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let filteredMessages = res.tryGet().mapIt(it[2])
|
2022-11-22 18:40:24 +00:00
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
filteredMessages == expected[2 .. 6]
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
(waitFor driver.close()).expect("driver to close")
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
test "end time only":
|
|
|
|
## Given
|
|
|
|
const contentTopic = "test-content-topic"
|
|
|
|
|
|
|
|
let driver = newTestSqliteDriver()
|
|
|
|
|
|
|
|
let timeOrigin = now()
|
2024-03-15 23:08:47 +00:00
|
|
|
let expected =
|
|
|
|
@[
|
|
|
|
fakeWakuMessage(@[byte 0], contentTopic = contentTopic, ts = ts(00, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 1], contentTopic = contentTopic, ts = ts(10, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 2], contentTopic = contentTopic, ts = ts(20, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 3], contentTopic = contentTopic, ts = ts(30, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 4], contentTopic = contentTopic, ts = ts(40, timeOrigin)),
|
|
|
|
# end_time
|
|
|
|
fakeWakuMessage(@[byte 5], contentTopic = contentTopic, ts = ts(50, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 6], contentTopic = contentTopic, ts = ts(60, timeOrigin)),
|
|
|
|
]
|
2022-11-23 23:58:17 +00:00
|
|
|
var messages = expected
|
|
|
|
|
|
|
|
shuffle(messages)
|
2024-03-15 23:08:47 +00:00
|
|
|
debug "randomized message insertion sequence", sequence = messages.mapIt(it.payload)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
for msg in messages:
|
2024-03-15 23:08:47 +00:00
|
|
|
let retFut = waitFor driver.put(
|
2024-07-12 16:19:12 +00:00
|
|
|
computeMessageHash(DefaultPubsubTopic, msg), DefaultPubsubTopic, msg
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-05-25 15:34:34 +00:00
|
|
|
require retFut.isOk()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## When
|
2023-05-25 15:34:34 +00:00
|
|
|
let res = waitFor driver.getMessages(
|
2024-03-15 23:08:47 +00:00
|
|
|
endTime = some(ts(45, timeOrigin)), maxPageSize = 10, ascendingOrder = true
|
2022-11-22 18:40:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
res.isOk()
|
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let filteredMessages = res.tryGet().mapIt(it[2])
|
2022-11-22 18:40:24 +00:00
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
filteredMessages == expected[0 .. 4]
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
(waitFor driver.close()).expect("driver to close")
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
test "start time and end time":
|
|
|
|
## Given
|
|
|
|
const contentTopic = "test-content-topic"
|
|
|
|
const pubsubTopic = "test-pubsub-topic"
|
|
|
|
|
|
|
|
let driver = newTestSqliteDriver()
|
|
|
|
|
|
|
|
let timeOrigin = now()
|
2024-03-15 23:08:47 +00:00
|
|
|
let expected =
|
|
|
|
@[
|
|
|
|
(DefaultPubsubTopic, fakeWakuMessage(@[byte 0], ts = ts(00, timeOrigin))),
|
|
|
|
(DefaultPubsubTopic, fakeWakuMessage(@[byte 1], ts = ts(10, timeOrigin))),
|
|
|
|
# start_time
|
|
|
|
(
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 2], contentTopic = contentTopic, ts = ts(20, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 3], contentTopic = contentTopic, ts = ts(30, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 4], contentTopic = contentTopic, ts = ts(40, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
# end_time
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 5], contentTopic = contentTopic, ts = ts(50, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 6], contentTopic = contentTopic, ts = ts(60, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 7], contentTopic = contentTopic, ts = ts(70, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 8], contentTopic = contentTopic, ts = ts(80, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 9], contentTopic = contentTopic, ts = ts(90, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
]
|
2022-11-23 23:58:17 +00:00
|
|
|
var messages = expected
|
|
|
|
|
|
|
|
shuffle(messages)
|
2024-03-15 23:08:47 +00:00
|
|
|
debug "randomized message insertion sequence",
|
|
|
|
sequence = messages.mapIt(it[1].payload)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
for row in messages:
|
|
|
|
let (topic, msg) = row
|
2024-07-12 16:19:12 +00:00
|
|
|
let retFut = waitFor driver.put(computeMessageHash(topic, msg), topic, msg)
|
2023-05-25 15:34:34 +00:00
|
|
|
require retFut.isOk()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## When
|
2023-05-25 15:34:34 +00:00
|
|
|
let res = waitFor driver.getMessages(
|
2024-03-15 23:08:47 +00:00
|
|
|
startTime = some(ts(15, timeOrigin)),
|
|
|
|
endTime = some(ts(45, timeOrigin)),
|
|
|
|
maxPageSize = 10,
|
|
|
|
ascendingOrder = true,
|
2022-11-22 18:40:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
res.isOk()
|
|
|
|
|
2022-11-23 23:58:17 +00:00
|
|
|
let expectedMessages = expected.mapIt(it[1])
|
2024-07-12 16:19:12 +00:00
|
|
|
let filteredMessages = res.tryGet().mapIt(it[2])
|
2022-11-22 18:40:24 +00:00
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
filteredMessages == expectedMessages[2 .. 4]
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
(waitFor driver.close()).expect("driver to close")
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
test "invalid time range - no results":
|
|
|
|
## Given
|
|
|
|
const contentTopic = "test-content-topic"
|
|
|
|
|
|
|
|
let driver = newTestSqliteDriver()
|
|
|
|
|
|
|
|
let timeOrigin = now()
|
2024-03-15 23:08:47 +00:00
|
|
|
let expected =
|
|
|
|
@[
|
|
|
|
fakeWakuMessage(@[byte 0], contentTopic = contentTopic, ts = ts(00, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 1], contentTopic = contentTopic, ts = ts(10, timeOrigin)),
|
|
|
|
# start_time
|
|
|
|
fakeWakuMessage(@[byte 2], contentTopic = contentTopic, ts = ts(20, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 3], contentTopic = contentTopic, ts = ts(30, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 4], contentTopic = contentTopic, ts = ts(40, timeOrigin)),
|
|
|
|
# end_time
|
|
|
|
fakeWakuMessage(@[byte 5], contentTopic = contentTopic, ts = ts(50, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 6], contentTopic = contentTopic, ts = ts(60, timeOrigin)),
|
|
|
|
]
|
2022-11-23 23:58:17 +00:00
|
|
|
var messages = expected
|
|
|
|
|
|
|
|
shuffle(messages)
|
2024-03-15 23:08:47 +00:00
|
|
|
debug "randomized message insertion sequence", sequence = messages.mapIt(it.payload)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
for msg in messages:
|
2024-03-15 23:08:47 +00:00
|
|
|
let retFut = waitFor driver.put(
|
2024-07-12 16:19:12 +00:00
|
|
|
computeMessageHash(DefaultPubsubTopic, msg), DefaultPubsubTopic, msg
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-05-25 15:34:34 +00:00
|
|
|
require retFut.isOk()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## When
|
2023-05-25 15:34:34 +00:00
|
|
|
let res = waitFor driver.getMessages(
|
2024-07-12 16:19:12 +00:00
|
|
|
contentTopics = @[contentTopic],
|
2024-03-15 23:08:47 +00:00
|
|
|
startTime = some(ts(45, timeOrigin)),
|
|
|
|
endTime = some(ts(15, timeOrigin)),
|
|
|
|
maxPageSize = 2,
|
|
|
|
ascendingOrder = true,
|
2022-11-22 18:40:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
check:
|
|
|
|
res.isOk()
|
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let filteredMessages = res.tryGet().mapIt(it[2])
|
2022-11-22 18:40:24 +00:00
|
|
|
check:
|
|
|
|
filteredMessages.len == 0
|
|
|
|
|
|
|
|
## Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
(waitFor driver.close()).expect("driver to close")
|
2022-11-22 18:40:24 +00:00
|
|
|
|
2023-05-25 15:34:34 +00:00
|
|
|
asynctest "time range start and content topic":
|
2022-11-22 18:40:24 +00:00
|
|
|
## Given
|
|
|
|
const contentTopic = "test-content-topic"
|
|
|
|
|
|
|
|
let driver = newTestSqliteDriver()
|
|
|
|
|
|
|
|
let timeOrigin = now()
|
2024-03-15 23:08:47 +00:00
|
|
|
let expected =
|
|
|
|
@[
|
|
|
|
fakeWakuMessage(@[byte 0], contentTopic = contentTopic, ts = ts(00, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 1], contentTopic = contentTopic, ts = ts(10, timeOrigin)),
|
|
|
|
# start_time
|
|
|
|
fakeWakuMessage(@[byte 2], contentTopic = contentTopic, ts = ts(20, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 3], contentTopic = contentTopic, ts = ts(30, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 4], contentTopic = contentTopic, ts = ts(40, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 5], contentTopic = contentTopic, ts = ts(50, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 6], contentTopic = contentTopic, ts = ts(60, timeOrigin)),
|
|
|
|
]
|
2022-11-23 23:58:17 +00:00
|
|
|
var messages = expected
|
|
|
|
|
|
|
|
shuffle(messages)
|
2024-03-15 23:08:47 +00:00
|
|
|
debug "randomized message insertion sequence", sequence = messages.mapIt(it.payload)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
for msg in messages:
|
2024-05-10 12:13:58 +00:00
|
|
|
let retFut = await driver.put(
|
2024-07-12 16:19:12 +00:00
|
|
|
computeMessageHash(DefaultPubsubTopic, msg), DefaultPubsubTopic, msg
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-05-25 15:34:34 +00:00
|
|
|
require retFut.isOk()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## When
|
2024-05-10 12:13:58 +00:00
|
|
|
let res = await driver.getMessages(
|
2024-07-12 16:19:12 +00:00
|
|
|
contentTopics = @[contentTopic],
|
2024-03-15 23:08:47 +00:00
|
|
|
startTime = some(ts(15, timeOrigin)),
|
|
|
|
maxPageSize = 10,
|
|
|
|
ascendingOrder = true,
|
2022-11-22 18:40:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
check:
|
|
|
|
res.isOk()
|
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let filteredMessages = res.tryGet().mapIt(it[2])
|
2022-11-22 18:40:24 +00:00
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
filteredMessages == expected[2 .. 6]
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## Cleanup
|
2024-05-10 12:13:58 +00:00
|
|
|
(await driver.close()).expect("driver to close")
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
test "time range start and content topic - descending order":
|
|
|
|
## Given
|
|
|
|
const contentTopic = "test-content-topic"
|
|
|
|
|
|
|
|
let driver = newTestSqliteDriver()
|
|
|
|
|
|
|
|
let timeOrigin = now()
|
2024-03-15 23:08:47 +00:00
|
|
|
let expected =
|
|
|
|
@[
|
|
|
|
fakeWakuMessage(@[byte 0], contentTopic = contentTopic, ts = ts(00, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 1], contentTopic = contentTopic, ts = ts(10, timeOrigin)),
|
|
|
|
# start_time
|
|
|
|
fakeWakuMessage(@[byte 2], contentTopic = contentTopic, ts = ts(20, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 3], contentTopic = contentTopic, ts = ts(30, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 4], contentTopic = contentTopic, ts = ts(40, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 5], contentTopic = contentTopic, ts = ts(50, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 6], contentTopic = contentTopic, ts = ts(60, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 7], ts = ts(70, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 8], ts = ts(80, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 9], ts = ts(90, timeOrigin)),
|
|
|
|
]
|
2022-11-23 23:58:17 +00:00
|
|
|
var messages = expected
|
|
|
|
|
|
|
|
shuffle(messages)
|
2024-03-15 23:08:47 +00:00
|
|
|
debug "randomized message insertion sequence", sequence = messages.mapIt(it.payload)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
for msg in messages:
|
2024-03-15 23:08:47 +00:00
|
|
|
let retFut = waitFor driver.put(
|
2024-07-12 16:19:12 +00:00
|
|
|
computeMessageHash(DefaultPubsubTopic, msg), DefaultPubsubTopic, msg
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-05-25 15:34:34 +00:00
|
|
|
require retFut.isOk()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## When
|
2023-05-25 15:34:34 +00:00
|
|
|
let res = waitFor driver.getMessages(
|
2024-07-12 16:19:12 +00:00
|
|
|
contentTopics = @[contentTopic],
|
2024-03-15 23:08:47 +00:00
|
|
|
startTime = some(ts(15, timeOrigin)),
|
|
|
|
maxPageSize = 10,
|
|
|
|
ascendingOrder = false,
|
2022-11-22 18:40:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
check:
|
|
|
|
res.isOk()
|
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let filteredMessages = res.tryGet().mapIt(it[2])
|
2022-11-22 18:40:24 +00:00
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
filteredMessages == expected[2 .. 6].reversed()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
(waitFor driver.close()).expect("driver to close")
|
2022-11-22 18:40:24 +00:00
|
|
|
|
2023-05-25 15:34:34 +00:00
|
|
|
asynctest "time range start, single content topic and cursor":
|
2022-11-22 18:40:24 +00:00
|
|
|
## Given
|
|
|
|
const contentTopic = "test-content-topic"
|
|
|
|
|
|
|
|
let driver = newTestSqliteDriver()
|
|
|
|
|
|
|
|
let timeOrigin = now()
|
2024-03-15 23:08:47 +00:00
|
|
|
let expected =
|
|
|
|
@[
|
|
|
|
fakeWakuMessage(@[byte 0], contentTopic = contentTopic, ts = ts(00, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 1], contentTopic = contentTopic, ts = ts(10, timeOrigin)),
|
|
|
|
# start_time
|
|
|
|
fakeWakuMessage(@[byte 2], contentTopic = contentTopic, ts = ts(20, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 3], contentTopic = contentTopic, ts = ts(30, timeOrigin)),
|
|
|
|
# << cursor
|
|
|
|
fakeWakuMessage(@[byte 4], contentTopic = contentTopic, ts = ts(40, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 5], contentTopic = contentTopic, ts = ts(50, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 6], contentTopic = contentTopic, ts = ts(60, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 7], contentTopic = contentTopic, ts = ts(70, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 8], contentTopic = contentTopic, ts = ts(80, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 9], contentTopic = contentTopic, ts = ts(90, timeOrigin)),
|
|
|
|
]
|
2022-11-23 23:58:17 +00:00
|
|
|
var messages = expected
|
|
|
|
|
|
|
|
shuffle(messages)
|
2024-03-15 23:08:47 +00:00
|
|
|
debug "randomized message insertion sequence", sequence = messages.mapIt(it.payload)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
for msg in messages:
|
2024-05-10 12:13:58 +00:00
|
|
|
let retFut = await driver.put(
|
2024-07-12 16:19:12 +00:00
|
|
|
computeMessageHash(DefaultPubsubTopic, msg), DefaultPubsubTopic, msg
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-05-25 15:34:34 +00:00
|
|
|
require retFut.isOk()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let cursor = computeMessageHash(DefaultPubsubTopic, expected[3])
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## When
|
2024-05-10 12:13:58 +00:00
|
|
|
let res = await driver.getMessages(
|
2024-07-12 16:19:12 +00:00
|
|
|
contentTopics = @[contentTopic],
|
2024-03-15 23:08:47 +00:00
|
|
|
cursor = some(cursor),
|
|
|
|
startTime = some(ts(15, timeOrigin)),
|
|
|
|
maxPageSize = 10,
|
|
|
|
ascendingOrder = true,
|
2022-11-22 18:40:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
check:
|
|
|
|
res.isOk()
|
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let filteredMessages = res.tryGet().mapIt(it[2])
|
2022-11-22 18:40:24 +00:00
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
filteredMessages == expected[4 .. 9]
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## Cleanup
|
2024-05-10 12:13:58 +00:00
|
|
|
(await driver.close()).expect("driver to close")
|
2022-11-22 18:40:24 +00:00
|
|
|
|
2023-05-25 15:34:34 +00:00
|
|
|
asynctest "time range start, single content topic and cursor - descending order":
|
2022-11-22 18:40:24 +00:00
|
|
|
## Given
|
|
|
|
const contentTopic = "test-content-topic"
|
|
|
|
|
|
|
|
let driver = newTestSqliteDriver()
|
|
|
|
|
|
|
|
let timeOrigin = now()
|
2024-03-15 23:08:47 +00:00
|
|
|
let expected =
|
|
|
|
@[
|
|
|
|
fakeWakuMessage(@[byte 0], contentTopic = contentTopic, ts = ts(00, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 1], contentTopic = contentTopic, ts = ts(10, timeOrigin)),
|
|
|
|
# start_time
|
|
|
|
fakeWakuMessage(@[byte 2], ts = ts(20, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 3], contentTopic = contentTopic, ts = ts(30, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 4], contentTopic = contentTopic, ts = ts(40, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 5], ts = ts(50, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 6], contentTopic = contentTopic, ts = ts(60, timeOrigin)),
|
|
|
|
# << cursor
|
|
|
|
fakeWakuMessage(@[byte 7], contentTopic = contentTopic, ts = ts(70, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 8], contentTopic = contentTopic, ts = ts(80, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 9], contentTopic = contentTopic, ts = ts(90, timeOrigin)),
|
|
|
|
]
|
2022-11-23 23:58:17 +00:00
|
|
|
var messages = expected
|
|
|
|
|
|
|
|
shuffle(messages)
|
2024-03-15 23:08:47 +00:00
|
|
|
debug "randomized message insertion sequence", sequence = messages.mapIt(it.payload)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
for msg in messages:
|
2024-05-10 12:13:58 +00:00
|
|
|
let retFut = await driver.put(
|
2024-07-12 16:19:12 +00:00
|
|
|
computeMessageHash(DefaultPubsubTopic, msg), DefaultPubsubTopic, msg
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-05-25 15:34:34 +00:00
|
|
|
require retFut.isOk()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let cursor = computeMessageHash(DefaultPubsubTopic, expected[6])
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## When
|
2024-05-10 12:13:58 +00:00
|
|
|
let res = await driver.getMessages(
|
2024-07-12 16:19:12 +00:00
|
|
|
contentTopics = @[contentTopic],
|
2024-03-15 23:08:47 +00:00
|
|
|
cursor = some(cursor),
|
|
|
|
startTime = some(ts(15, timeOrigin)),
|
|
|
|
maxPageSize = 10,
|
|
|
|
ascendingOrder = false,
|
2022-11-22 18:40:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
check:
|
|
|
|
res.isOk()
|
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let filteredMessages = res.tryGet().mapIt(it[2])
|
2022-11-22 18:40:24 +00:00
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
filteredMessages == expected[3 .. 4].reversed()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## Cleanup
|
2024-05-10 12:13:58 +00:00
|
|
|
(await driver.close()).expect("driver to close")
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
test "time range, content topic, pubsub topic and cursor":
|
|
|
|
## Given
|
|
|
|
const contentTopic = "test-content-topic"
|
|
|
|
const pubsubTopic = "test-pubsub-topic"
|
|
|
|
|
|
|
|
let driver = newTestSqliteDriver()
|
|
|
|
|
|
|
|
let timeOrigin = now()
|
2024-03-15 23:08:47 +00:00
|
|
|
let expected =
|
|
|
|
@[
|
|
|
|
# start_time
|
|
|
|
(DefaultPubsubTopic, fakeWakuMessage(@[byte 0], ts = ts(00, timeOrigin))),
|
|
|
|
(DefaultPubsubTopic, fakeWakuMessage(@[byte 1], ts = ts(10, timeOrigin))),
|
|
|
|
# << cursor
|
|
|
|
(
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 2], contentTopic = contentTopic, ts = ts(20, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 3], contentTopic = contentTopic, ts = ts(30, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 4], contentTopic = contentTopic, ts = ts(40, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
# end_time
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 5], contentTopic = contentTopic, ts = ts(50, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(pubsubTopic, fakeWakuMessage(@[byte 6], ts = ts(60, timeOrigin))),
|
|
|
|
(pubsubTopic, fakeWakuMessage(@[byte 7], ts = ts(70, timeOrigin))),
|
|
|
|
(
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 8], contentTopic = contentTopic, ts = ts(80, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 9], contentTopic = contentTopic, ts = ts(90, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
]
|
2022-11-23 23:58:17 +00:00
|
|
|
var messages = expected
|
|
|
|
|
|
|
|
shuffle(messages)
|
2024-03-15 23:08:47 +00:00
|
|
|
debug "randomized message insertion sequence",
|
|
|
|
sequence = messages.mapIt(it[1].payload)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
for row in messages:
|
|
|
|
let (topic, msg) = row
|
2024-07-12 16:19:12 +00:00
|
|
|
let retFut = waitFor driver.put(computeMessageHash(topic, msg), topic, msg)
|
2023-05-25 15:34:34 +00:00
|
|
|
require retFut.isOk()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let cursor = computeMessageHash(DefaultPubsubTopic, expected[1][1])
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## When
|
2023-05-25 15:34:34 +00:00
|
|
|
let res = waitFor driver.getMessages(
|
2024-07-12 16:19:12 +00:00
|
|
|
contentTopics = @[contentTopic],
|
2024-03-15 23:08:47 +00:00
|
|
|
pubsubTopic = some(pubsubTopic),
|
|
|
|
cursor = some(cursor),
|
|
|
|
startTime = some(ts(0, timeOrigin)),
|
|
|
|
endTime = some(ts(45, timeOrigin)),
|
|
|
|
maxPageSize = 10,
|
|
|
|
ascendingOrder = true,
|
2022-11-22 18:40:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
check:
|
|
|
|
res.isOk()
|
|
|
|
|
2022-11-23 23:58:17 +00:00
|
|
|
let expectedMessages = expected.mapIt(it[1])
|
2024-07-12 16:19:12 +00:00
|
|
|
let filteredMessages = res.tryGet().mapIt(it[2])
|
2022-11-22 18:40:24 +00:00
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
filteredMessages == expectedMessages[3 .. 4]
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
(waitFor driver.close()).expect("driver to close")
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
test "time range, content topic, pubsub topic and cursor - descending order":
|
|
|
|
## Given
|
|
|
|
const contentTopic = "test-content-topic"
|
|
|
|
const pubsubTopic = "test-pubsub-topic"
|
|
|
|
|
|
|
|
let driver = newTestSqliteDriver()
|
|
|
|
|
|
|
|
let timeOrigin = now()
|
2024-03-15 23:08:47 +00:00
|
|
|
let expected =
|
|
|
|
@[
|
|
|
|
(DefaultPubsubTopic, fakeWakuMessage(@[byte 0], ts = ts(00, timeOrigin))),
|
|
|
|
(DefaultPubsubTopic, fakeWakuMessage(@[byte 1], ts = ts(10, timeOrigin))),
|
|
|
|
(
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 2], contentTopic = contentTopic, ts = ts(20, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 3], contentTopic = contentTopic, ts = ts(30, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
# start_time
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 4], contentTopic = contentTopic, ts = ts(40, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 5], contentTopic = contentTopic, ts = ts(50, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(pubsubTopic, fakeWakuMessage(@[byte 6], ts = ts(60, timeOrigin))),
|
|
|
|
(pubsubTopic, fakeWakuMessage(@[byte 7], ts = ts(70, timeOrigin))), # << cursor
|
|
|
|
(
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 8], contentTopic = contentTopic, ts = ts(80, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
# end_time
|
|
|
|
(
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 9], contentTopic = contentTopic, ts = ts(90, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
]
|
2022-11-23 23:58:17 +00:00
|
|
|
var messages = expected
|
|
|
|
|
|
|
|
shuffle(messages)
|
2024-03-15 23:08:47 +00:00
|
|
|
debug "randomized message insertion sequence",
|
|
|
|
sequence = messages.mapIt(it[1].payload)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
for row in messages:
|
|
|
|
let (topic, msg) = row
|
2024-07-12 16:19:12 +00:00
|
|
|
let retFut = waitFor driver.put(computeMessageHash(topic, msg), topic, msg)
|
2023-05-25 15:34:34 +00:00
|
|
|
require retFut.isOk()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let cursor = computeMessageHash(expected[7][0], expected[7][1])
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## When
|
2023-05-25 15:34:34 +00:00
|
|
|
let res = waitFor driver.getMessages(
|
2024-07-12 16:19:12 +00:00
|
|
|
contentTopics = @[contentTopic],
|
2024-03-15 23:08:47 +00:00
|
|
|
pubsubTopic = some(pubsubTopic),
|
|
|
|
cursor = some(cursor),
|
|
|
|
startTime = some(ts(35, timeOrigin)),
|
|
|
|
endTime = some(ts(85, timeOrigin)),
|
|
|
|
maxPageSize = 10,
|
|
|
|
ascendingOrder = false,
|
2022-11-22 18:40:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
check:
|
|
|
|
res.isOk()
|
|
|
|
|
2022-11-23 23:58:17 +00:00
|
|
|
let expectedMessages = expected.mapIt(it[1])
|
2024-07-12 16:19:12 +00:00
|
|
|
let filteredMessages = res.tryGet().mapIt(it[2])
|
2022-11-22 18:40:24 +00:00
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
filteredMessages == expectedMessages[4 .. 5].reversed()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
(waitFor driver.close()).expect("driver to close")
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
test "time range, content topic, pubsub topic and cursor - cursor timestamp out of time range":
|
|
|
|
## Given
|
|
|
|
const contentTopic = "test-content-topic"
|
|
|
|
const pubsubTopic = "test-pubsub-topic"
|
|
|
|
|
|
|
|
let driver = newTestSqliteDriver()
|
|
|
|
|
|
|
|
let timeOrigin = now()
|
2024-03-15 23:08:47 +00:00
|
|
|
let expected =
|
|
|
|
@[
|
|
|
|
(DefaultPubsubTopic, fakeWakuMessage(@[byte 0], ts = ts(00, timeOrigin))),
|
|
|
|
(DefaultPubsubTopic, fakeWakuMessage(@[byte 1], ts = ts(10, timeOrigin))),
|
|
|
|
# << cursor
|
|
|
|
(
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 2], contentTopic = contentTopic, ts = ts(20, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 3], contentTopic = contentTopic, ts = ts(30, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
# start_time
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 4], contentTopic = contentTopic, ts = ts(40, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 5], contentTopic = contentTopic, ts = ts(50, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(pubsubTopic, fakeWakuMessage(@[byte 6], ts = ts(60, timeOrigin))),
|
|
|
|
(pubsubTopic, fakeWakuMessage(@[byte 7], ts = ts(70, timeOrigin))),
|
|
|
|
(
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 8], contentTopic = contentTopic, ts = ts(80, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
# end_time
|
|
|
|
(
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 9], contentTopic = contentTopic, ts = ts(90, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
]
|
2022-11-23 23:58:17 +00:00
|
|
|
var messages = expected
|
|
|
|
|
|
|
|
shuffle(messages)
|
2024-03-15 23:08:47 +00:00
|
|
|
debug "randomized message insertion sequence",
|
|
|
|
sequence = messages.mapIt(it[1].payload)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
for row in messages:
|
|
|
|
let (topic, msg) = row
|
2024-07-12 16:19:12 +00:00
|
|
|
let retFut = waitFor driver.put(computeMessageHash(topic, msg), topic, msg)
|
2023-05-25 15:34:34 +00:00
|
|
|
require retFut.isOk()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let cursor = computeMessageHash(expected[1][0], expected[1][1])
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## When
|
2023-05-25 15:34:34 +00:00
|
|
|
let res = waitFor driver.getMessages(
|
2024-07-12 16:19:12 +00:00
|
|
|
contentTopics = @[contentTopic],
|
2024-03-15 23:08:47 +00:00
|
|
|
pubsubTopic = some(pubsubTopic),
|
|
|
|
cursor = some(cursor),
|
|
|
|
startTime = some(ts(35, timeOrigin)),
|
|
|
|
endTime = some(ts(85, timeOrigin)),
|
|
|
|
maxPageSize = 10,
|
|
|
|
ascendingOrder = true,
|
2022-11-22 18:40:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
res.isOk()
|
|
|
|
|
2022-11-23 23:58:17 +00:00
|
|
|
let expectedMessages = expected.mapIt(it[1])
|
2024-07-12 16:19:12 +00:00
|
|
|
let filteredMessages = res.tryGet().mapIt(it[2])
|
2022-11-22 18:40:24 +00:00
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
filteredMessages == expectedMessages[4 .. 5]
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
(waitFor driver.close()).expect("driver to close")
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
test "time range, content topic, pubsub topic and cursor - cursor timestamp out of time range, descending order":
|
|
|
|
## Given
|
|
|
|
const contentTopic = "test-content-topic"
|
|
|
|
const pubsubTopic = "test-pubsub-topic"
|
|
|
|
|
|
|
|
let driver = newTestSqliteDriver()
|
|
|
|
|
|
|
|
let timeOrigin = now()
|
2024-03-15 23:08:47 +00:00
|
|
|
let expected =
|
|
|
|
@[
|
|
|
|
(DefaultPubsubTopic, fakeWakuMessage(@[byte 0], ts = ts(00, timeOrigin))),
|
|
|
|
(DefaultPubsubTopic, fakeWakuMessage(@[byte 1], ts = ts(10, timeOrigin))),
|
|
|
|
# << cursor
|
|
|
|
(
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 2], contentTopic = contentTopic, ts = ts(20, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 3], contentTopic = contentTopic, ts = ts(30, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
# start_time
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 4], contentTopic = contentTopic, ts = ts(40, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
pubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 5], contentTopic = contentTopic, ts = ts(50, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(pubsubTopic, fakeWakuMessage(@[byte 6], ts = ts(60, timeOrigin))),
|
|
|
|
(pubsubTopic, fakeWakuMessage(@[byte 7], ts = ts(70, timeOrigin))),
|
|
|
|
(
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 8], contentTopic = contentTopic, ts = ts(80, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
# end_time
|
|
|
|
(
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 9], contentTopic = contentTopic, ts = ts(90, timeOrigin)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
]
|
2022-11-23 23:58:17 +00:00
|
|
|
var messages = expected
|
|
|
|
|
|
|
|
shuffle(messages)
|
2024-03-15 23:08:47 +00:00
|
|
|
debug "randomized message insertion sequence",
|
|
|
|
sequence = messages.mapIt(it[1].payload)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
for row in messages:
|
|
|
|
let (topic, msg) = row
|
2024-07-12 16:19:12 +00:00
|
|
|
let retFut = waitFor driver.put(computeMessageHash(topic, msg), topic, msg)
|
2023-05-25 15:34:34 +00:00
|
|
|
require retFut.isOk()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let cursor = computeMessageHash(expected[1][0], expected[1][1])
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## When
|
2023-05-25 15:34:34 +00:00
|
|
|
let res = waitFor driver.getMessages(
|
2024-07-12 16:19:12 +00:00
|
|
|
contentTopics = @[contentTopic],
|
2024-03-15 23:08:47 +00:00
|
|
|
pubsubTopic = some(pubsubTopic),
|
|
|
|
cursor = some(cursor),
|
|
|
|
startTime = some(ts(35, timeOrigin)),
|
|
|
|
endTime = some(ts(85, timeOrigin)),
|
|
|
|
maxPageSize = 10,
|
|
|
|
ascendingOrder = false,
|
2022-11-22 18:40:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
res.isOk()
|
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let filteredMessages = res.tryGet().mapIt(it[2])
|
2022-11-22 18:40:24 +00:00
|
|
|
check:
|
|
|
|
filteredMessages.len == 0
|
|
|
|
|
|
|
|
## Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
(waitFor driver.close()).expect("driver to close")
|