final adjustments and now even the flaky tests that depend on others's relay should pass most of the time.
This commit is contained in:
parent
804403f574
commit
8840c4d8e2
|
@ -11,8 +11,9 @@ jobs:
|
|||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: oven-sh/setup-bun@v1
|
||||
- uses: extractions/setup-just@v1
|
||||
- run: bun i
|
||||
- run: bun test --timeout 20000
|
||||
- run: just test
|
||||
format:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
|
2
justfile
2
justfile
|
@ -5,7 +5,7 @@ build:
|
|||
bun run build.js
|
||||
|
||||
test:
|
||||
bun test
|
||||
bun test --timeout 20000
|
||||
|
||||
test-only file:
|
||||
bun test {{file}}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { test, expect } from 'bun:test'
|
||||
import { test, expect, afterAll } from 'bun:test'
|
||||
|
||||
import { finishEvent, type Event } from './event.ts'
|
||||
import { generatePrivateKey, getPublicKey } from './keys.ts'
|
||||
|
@ -8,6 +8,10 @@ let pool = new SimplePool()
|
|||
|
||||
let relays = ['wss://relay.damus.io/', 'wss://relay.nostr.bg/', 'wss://nos.lol', 'wss://public.relaying.io']
|
||||
|
||||
afterAll(() => {
|
||||
pool.close([...relays, 'wss://offchain.pub', 'wss://eden.nostr.land'])
|
||||
})
|
||||
|
||||
test('removing duplicates when querying', async () => {
|
||||
let priv = generatePrivateKey()
|
||||
let pub = getPublicKey(priv)
|
||||
|
@ -33,7 +37,6 @@ test('removing duplicates when querying', async () => {
|
|||
)
|
||||
|
||||
await Promise.any(pool.publish(relays, event))
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 1500))
|
||||
|
||||
expect(received).toHaveLength(1)
|
||||
|
|
6
pool.ts
6
pool.ts
|
@ -34,6 +34,12 @@ export class SimplePool {
|
|||
return relay
|
||||
}
|
||||
|
||||
close(relays: string[]) {
|
||||
relays.map(normalizeURL).forEach(url => {
|
||||
this.relays.get(url)?.close()
|
||||
})
|
||||
}
|
||||
|
||||
subscribeMany(relays: string[], filters: Filter[], params: SubscribeManyParams): SubCloser {
|
||||
if (this.trackRelays) {
|
||||
params.receivedEvent = (relay: Relay, id: string) => {
|
||||
|
|
13
relay.ts
13
relay.ts
|
@ -21,7 +21,7 @@ export class Relay {
|
|||
public onnotice: (msg: string) => void = msg => console.debug(`NOTICE from ${this.url}: ${msg}`)
|
||||
|
||||
public baseEoseTimeout: number = 4400
|
||||
public connectionTimeout: number = 8800
|
||||
public connectionTimeout: number = 4400
|
||||
private connectionTimeoutHandle: ReturnType<typeof setTimeout> | undefined
|
||||
|
||||
private connectionPromise: Promise<void> | undefined
|
||||
|
@ -215,18 +215,21 @@ export class Relay {
|
|||
}
|
||||
|
||||
public async send(message: string) {
|
||||
this.ws?.send(message)
|
||||
if (!this.connectionPromise) throw new Error('sending on closed connection')
|
||||
|
||||
this.connectionPromise.then(() => {
|
||||
this.ws?.send(message)
|
||||
})
|
||||
}
|
||||
|
||||
public async auth(signAuthEvent: (authEvent: EventTemplate) => Promise<void>) {
|
||||
if (!this.challenge) throw new Error("can't perform auth, no challenge was received")
|
||||
const evt = nip42.makeAuthEvent(this.url, this.challenge)
|
||||
await Promise.all([signAuthEvent(evt), this.connect()])
|
||||
await signAuthEvent(evt)
|
||||
this.send('["AUTH",' + JSON.stringify(evt) + ']')
|
||||
}
|
||||
|
||||
public async publish(event: Event): Promise<string> {
|
||||
await this.connect()
|
||||
const ret = new Promise<string>((resolve, reject) => {
|
||||
this.openEventPublishes.set(event.id, { resolve, reject })
|
||||
})
|
||||
|
@ -235,7 +238,6 @@ export class Relay {
|
|||
}
|
||||
|
||||
public async count(filters: Filter[], params: { id?: string | null }): Promise<number> {
|
||||
await this.connect()
|
||||
this.serial++
|
||||
const id = params?.id || 'count:' + this.serial
|
||||
const ret = new Promise<number>((resolve, reject) => {
|
||||
|
@ -246,7 +248,6 @@ export class Relay {
|
|||
}
|
||||
|
||||
public async subscribe(filters: Filter[], params: Partial<SubscriptionParams>): Promise<Subscription> {
|
||||
await this.connect()
|
||||
const subscription = this.prepareSubscription(filters, params)
|
||||
subscription.fire()
|
||||
return subscription
|
||||
|
|
Loading…
Reference in New Issue