Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

test(api): remove kv recording test providers

Hampusb4005e617d3d
diff --git a/fluxer_api/pkgs/kv_client/src/testing/BatchRecordingKVProvider.ts b/fluxer_api/pkgs/kv_client/src/testing/BatchRecordingKVProvider.ts
deleted file mode 100644
index 7b1073f56..000000000
--- a/fluxer_api/pkgs/kv_client/src/testing/BatchRecordingKVProvider.ts
+++ /dev/null
@@ -1,62 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-or-later
-
-import type {IKVPipeline} from '@pkgs/kv_client/src/IKVProvider';
-import {computeHashSlot} from '@pkgs/kv_client/src/KVHashSlots';
-import {MockKVProvider} from '@pkgs/kv_client/src/testing/MockKVProvider';
-
-type BatchMode = 'multi' | 'pipeline';
-
-interface RecordedBatch {
- mode: BatchMode;
- keys: Array<string>;
-}
-
-export class BatchRecordingKVProvider extends MockKVProvider {
- readonly batches: Array<RecordedBatch> = [];
-
- override pipeline(): IKVPipeline {
- return this.recordBatch('pipeline', super.pipeline());
- }
-
- override multi(): IKVPipeline {
- return this.recordBatch('multi', super.multi());
- }
-
- crossSlotBatches(): Array<RecordedBatch> {
- return this.batches.filter((batch) => new Set(batch.keys.map(computeHashSlot)).size > 1);
- }
-
- private recordBatch(mode: BatchMode, inner: IKVPipeline): IKVPipeline {
- const batch: RecordedBatch = {mode, keys: []};
- this.batches.push(batch);
- const recorded: IKVPipeline = {
- setex: (key, ttlSeconds, value) => {
- batch.keys.push(key);
- inner.setex(key, ttlSeconds, value);
- return recorded;
- },
- del: (key) => {
- batch.keys.push(key);
- inner.del(key);
- return recorded;
- },
- expire: (key, ttlSeconds) => {
- batch.keys.push(key);
- inner.expire(key, ttlSeconds);
- return recorded;
- },
- sadd: (key, ...members) => {
- batch.keys.push(key);
- inner.sadd(key, ...members);
- return recorded;
- },
- hgetall: (key) => {
- batch.keys.push(key);
- inner.hgetall(key);
- return recorded;
- },
- exec: async () => await inner.exec(),
- };
- return recorded;
- }
-}
diff --git a/fluxer_api/pkgs/kv_client/src/testing/FanoutRecordingKVProvider.ts b/fluxer_api/pkgs/kv_client/src/testing/FanoutRecordingKVProvider.ts
deleted file mode 100644
index 0dd91a94d..000000000
--- a/fluxer_api/pkgs/kv_client/src/testing/FanoutRecordingKVProvider.ts
+++ /dev/null
@@ -1,53 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-or-later
-
-import type {IKVPipeline} from '@pkgs/kv_client/src/IKVProvider';
-import {BatchRecordingKVProvider} from '@pkgs/kv_client/src/testing/BatchRecordingKVProvider';
-
-export class FanoutRecordingKVProvider extends BatchRecordingKVProvider {
- inFlight = 0;
- peakInFlight = 0;
- failingKey: string | null = null;
-
- private insidePipeline = 0;
-
- override pipeline(): IKVPipeline {
- const inner = super.pipeline();
- return {
- ...inner,
- exec: async () =>
- await this.trackRoundTrip(async () => {
- this.insidePipeline += 1;
- try {
- return await inner.exec();
- } finally {
- this.insidePipeline -= 1;
- }
- }),
- };
- }
-
- override async setex(key: string, ttlSeconds: number, value: string): Promise<void> {
- if (key === this.failingKey) {
- throw new Error('write rejected');
- }
- if (this.insidePipeline > 0) {
- await super.setex(key, ttlSeconds, value);
- return;
- }
- this.batches.push({mode: 'pipeline', keys: [key]});
- await this.trackRoundTrip(async () => {
- await super.setex(key, ttlSeconds, value);
- });
- }
-
- private async trackRoundTrip<T>(run: () => Promise<T>): Promise<T> {
- this.inFlight += 1;
- this.peakInFlight = Math.max(this.peakInFlight, this.inFlight);
- try {
- await new Promise((resolve) => setTimeout(resolve, 0));
- return await run();
- } finally {
- this.inFlight -= 1;
- }
- }
-}