mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-10-25 07:40:36 +00:00
Fix Nostr unit test failures
This commit is contained in:
parent
51d8bdb991
commit
761af12203
@ -79,9 +79,9 @@ class NostrEventDeduplicator(
|
||||
* @return true if the event is a duplicate (already seen), false if it's new
|
||||
*/
|
||||
fun isDuplicate(eventId: String): Boolean {
|
||||
totalChecks++
|
||||
|
||||
synchronized(lruLock) {
|
||||
totalChecks++
|
||||
|
||||
val existingNode = nodeMap[eventId]
|
||||
|
||||
if (existingNode != null) {
|
||||
|
||||
@ -36,29 +36,34 @@ class NostrBackgroundEventProcessorTest {
|
||||
fun `cold start processes more events than the removed handoff queue capacity`() = runBlocking {
|
||||
val application = ApplicationProvider.getApplicationContext<Application>()
|
||||
val processor = NostrBackgroundEventProcessor(application, scope)
|
||||
val identity = NostrIdentity.generate()
|
||||
val expectedIds = mutableSetOf<String>()
|
||||
|
||||
repeat(300) { index ->
|
||||
val event = NostrEvent(
|
||||
pubkey = identity.publicKeyHex,
|
||||
createdAt = index + 1,
|
||||
kind = NostrKind.EPHEMERAL_EVENT,
|
||||
tags = listOf(listOf("g", "u4pruy")),
|
||||
content = "message-$index"
|
||||
).sign(identity.privateKeyHex)
|
||||
expectedIds += event.id
|
||||
|
||||
processor.onGeohashMessage(
|
||||
event = NostrEvent(
|
||||
id = "cold-start-$index",
|
||||
pubkey = index.toString(16).padStart(64, '0'),
|
||||
createdAt = 1,
|
||||
kind = NostrKind.EPHEMERAL_EVENT,
|
||||
tags = listOf(listOf("g", "u4pruy")),
|
||||
content = "message-$index"
|
||||
),
|
||||
event = event,
|
||||
geohash = "u4pruy"
|
||||
)
|
||||
}
|
||||
|
||||
withTimeout(5_000) {
|
||||
// CI can take longer to verify all 300 Schnorr signatures on a cold JVM.
|
||||
withTimeout(30_000) {
|
||||
while (AppStateStore.channelMessages.value["geo:u4pruy"].orEmpty().size < 300) {
|
||||
kotlinx.coroutines.yield()
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(
|
||||
(0 until 300).map { "cold-start-$it" }.toSet(),
|
||||
expectedIds,
|
||||
AppStateStore.channelMessages.value["geo:u4pruy"].orEmpty().map { it.id }.toSet()
|
||||
)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user