test(archive): pin the insert counter to what really got written

Each test writes once through a driver that refuses everything and once
through a working one: the first half keeps the counter tied to successful
writes -- it is what fails if the increment ever moves above the error check
and turns into an attempt counter -- and the second half is what fails if the
increment is dropped. The counters are process-global, so both compare against
a baseline read inside the test rather than an absolute value.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Ivan FB
2026-08-21 19:15:59 +02:00
co-authored by Claude Opus 5
parent 2b5946e924
commit c3a1b6b052
2 changed files with 59 additions and 1 deletions
+14
View File
@@ -24,6 +24,20 @@ proc newSqliteArchiveDriver*(): ArchiveDriver =
proc newWakuArchive*(driver: ArchiveDriver): WakuArchive =
WakuArchive.new(driver).get()
type FailingArchiveDriver* = ref object of ArchiveDriver
## Refuses every write, which is what a node with a broken database does.
method put*(
driver: FailingArchiveDriver,
messageHash: WakuMessageHash,
pubsubTopic: PubsubTopic,
message: WakuMessage,
): Future[ArchiveDriverResult[void]] {.async.} =
return err("failing archive driver stub")
proc newFailingArchiveDriver*(): ArchiveDriver =
return FailingArchiveDriver()
proc put*(
driver: ArchiveDriver, pubsubTopic: PubSubTopic, msgList: seq[WakuMessage]
): ArchiveDriver =
+45 -1
View File
@@ -1,6 +1,7 @@
{.used.}
import results, std/sequtils, testutils/unittests, chronos, libp2p/crypto/crypto
import
results, std/sequtils, testutils/unittests, chronos, metrics, libp2p/crypto/crypto
import
logos_delivery/waku/[
@@ -9,10 +10,22 @@ import
waku_core,
waku_core/message/digest,
waku_archive,
waku_archive/archive_metrics,
],
../waku_archive/archive_utils,
../testlib/wakucore
proc insertCount(source: string): float64 =
## `value(labelValues = ...)` ignores the label selector in metrics 0.2.1 and
## answers with whichever child was created first, so the series has to be
## read by name. Counters are registered with the '_total' suffix.
try:
return logos_delivery_archive_inserts.valueByName(
"logos_delivery_archive_inserts_total", [source]
)
except ValueError:
return 0.0
suite "Waku Archive - message handling":
test "it should archive a valid and non-ephemeral message":
## Setup
@@ -539,3 +552,34 @@ procSuite "Waku Archive - find messages":
let response = res.tryGet()
check:
response.messages.len == 0
suite "Waku Archive - insert metrics":
## The collectors are process-global and shared with every other test in this
## binary, hence the baseline taken inside each test.
test "the insert counter only moves when the relay ingress wrote":
let baseline = insertCount(relayIngress)
let failing = newWakuArchive(newFailingArchiveDriver())
waitFor failing.handleMessage(DefaultPubSubTopic, fakeWakuMessage())
check insertCount(relayIngress) == baseline
let stored = newWakuArchive(newSqliteArchiveDriver())
waitFor stored.handleMessage(DefaultPubSubTopic, fakeWakuMessage())
check insertCount(relayIngress) == baseline + 1
test "the insert counter only moves when the sync ingress wrote":
let baseline = insertCount(syncIngress)
let message = fakeWakuMessage()
let messageHash = computeMessageHash(DefaultPubSubTopic, message)
let failing = newWakuArchive(newFailingArchiveDriver())
check (waitFor failing.syncMessageIngress(messageHash, DefaultPubSubTopic, message)).isErr()
check insertCount(syncIngress) == baseline
let stored = newWakuArchive(newSqliteArchiveDriver())
check (waitFor stored.syncMessageIngress(messageHash, DefaultPubSubTopic, message)).isOk()
check insertCount(syncIngress) == baseline + 1