test(quartz): make repeat-sub test tolerant of relay limit overshoot
nos.lol (strfry) sometimes returns one extra event past the requested limit, pushing the second EOSE past the hard-coded slot 111 and failing the run. Replace the fixed 112-message assertion with EOSE-driven termination plus structural checks that allow the relay to return up to limit + 1 events for each sub.
This commit is contained in:
+25
-12
@@ -116,7 +116,8 @@ class NostrClientRepeatSubTest : BaseNostrClientTest() {
|
||||
coroutineScope {
|
||||
launch {
|
||||
withTimeoutOrNull(30000) {
|
||||
while (events.size < 112) {
|
||||
var eoseCount = 0
|
||||
while (eoseCount < 2) {
|
||||
Log.d("Test") { "Processing message ${events.size}" }
|
||||
// simulates an update in the middle of the sub
|
||||
if (events.size == 1) {
|
||||
@@ -125,7 +126,9 @@ class NostrClientRepeatSubTest : BaseNostrClientTest() {
|
||||
if (events.size == 5) {
|
||||
client.subscribe(mySubId, filtersShouldSendAfterEOSE)
|
||||
}
|
||||
events.add(resultChannel.receive())
|
||||
val msg = resultChannel.receive()
|
||||
events.add(msg)
|
||||
if (msg == "EOSE") eoseCount++
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -141,15 +144,25 @@ class NostrClientRepeatSubTest : BaseNostrClientTest() {
|
||||
|
||||
appScope.cancel()
|
||||
|
||||
// gets all 113 messages (100 events + 1 EOSE + 10 events + 1 EOSE)
|
||||
assertEquals(112, events.size)
|
||||
// checks if first 100 have Ids
|
||||
assertEquals(true, events.take(100).all { it.length == 64 })
|
||||
// checks if EOSE is after the first 100
|
||||
assertEquals("EOSE", events[100])
|
||||
// checks if next 10 have Ids
|
||||
assertEquals(true, events.drop(101).take(10).all { it.length == 64 })
|
||||
// checks if EOSE is after the next 10
|
||||
assertEquals("EOSE", events[111])
|
||||
// The relay may return up to limit events before EOSE; some relays return
|
||||
// one extra past the requested limit, so don't assert on the exact count.
|
||||
// First sub: <= 100 metadata events, then EOSE.
|
||||
// Second sub: <= 10 advertised relay list events, then EOSE.
|
||||
val firstEose = events.indexOf("EOSE")
|
||||
val lastEose = events.lastIndexOf("EOSE")
|
||||
|
||||
// both EOSEs must be present and distinct
|
||||
assertEquals(true, firstEose >= 0)
|
||||
assertEquals(true, lastEose > firstEose)
|
||||
// last entry is the second EOSE (loop stops on it)
|
||||
assertEquals(events.size - 1, lastEose)
|
||||
// first sub stays within its limit (allow +1 for relay quirks)
|
||||
assertEquals(true, firstEose in 1..101)
|
||||
// second sub stays within its limit (allow +1 for relay quirks)
|
||||
assertEquals(true, (lastEose - firstEose - 1) in 1..11)
|
||||
// everything before the first EOSE is an event id
|
||||
assertEquals(true, events.take(firstEose).all { it.length == 64 })
|
||||
// everything between the two EOSEs is an event id
|
||||
assertEquals(true, events.subList(firstEose + 1, lastEose).all { it.length == 64 })
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user