mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
Add InternalRelay test
This commit is contained in:
parent
b7a1efe33c
commit
640e533dca
3 changed files with 25 additions and 2 deletions
|
|
@ -149,7 +149,7 @@ function connectStream(socket: WebSocket, ip: string | undefined) {
|
|||
send(['EVENT', subId, msg[2]]);
|
||||
}
|
||||
}
|
||||
} catch (_e) {
|
||||
} catch {
|
||||
controllers.delete(subId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
23
src/storages/InternalRelay.test.ts
Normal file
23
src/storages/InternalRelay.test.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import { assertEquals } from '@std/assert';
|
||||
|
||||
import { eventFixture } from '@/test.ts';
|
||||
|
||||
import { InternalRelay } from './InternalRelay.ts';
|
||||
|
||||
Deno.test('InternalRelay', async () => {
|
||||
const relay = new InternalRelay();
|
||||
const event1 = await eventFixture('event-1');
|
||||
|
||||
const promise = new Promise((resolve) => setTimeout(() => resolve(relay.event(event1)), 0));
|
||||
|
||||
for await (const msg of relay.req([{}])) {
|
||||
if (msg[0] === 'EVENT') {
|
||||
assertEquals(relay.subs.size, 1);
|
||||
assertEquals(msg[2], event1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
await promise;
|
||||
assertEquals(relay.subs.size, 0); // cleanup
|
||||
});
|
||||
|
|
@ -24,7 +24,7 @@ interface InternalRelayOpts {
|
|||
* The pipeline should push events to it, then anything in the application can subscribe to it.
|
||||
*/
|
||||
export class InternalRelay implements NRelay {
|
||||
private subs = new Map<string, { filters: NostrFilter[]; machina: Machina<NostrEvent> }>();
|
||||
readonly subs = new Map<string, { filters: NostrFilter[]; machina: Machina<NostrEvent> }>();
|
||||
|
||||
constructor(private opts: InternalRelayOpts = {}) {}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue