From ed8bd7281e45f4fbadbaed4bf86399e6a01bdebf Mon Sep 17 00:00:00 2001 From: tyler-cai-microsoft <90650728+tyler-cai-microsoft@users.noreply.github.com> Date: Fri, 27 Sep 2024 14:45:45 -0700 Subject: [PATCH] Make odsp test cache less likely to fail (#22585) [AB#15994](https://dev.azure.com/fluidframework/235294da-091d-4c29-84fc-cdfc3d90890b/_workitems/edit/15994) Looking at the errors, it only looks like this occurred once. Based on the error stack, I've made some improvements to the `TestSnapshotCache` so that the persisted cache can be used for other non-snapshot storage, and non-`ValueWithSnapshot` types can be stored. --- .../test/test-end-to-end-tests/src/testSnapshotCache.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/test/test-end-to-end-tests/src/testSnapshotCache.ts b/packages/test/test-end-to-end-tests/src/testSnapshotCache.ts index f6ce23c8974b..226ed385e4d7 100644 --- a/packages/test/test-end-to-end-tests/src/testSnapshotCache.ts +++ b/packages/test/test-end-to-end-tests/src/testSnapshotCache.ts @@ -16,16 +16,19 @@ export interface ValueWithSnapshot { } export class TestSnapshotCache implements IPersistedCache { - private readonly cache = new Map(); + private readonly cache = new Map(); private readonly versionCache = new Map(); private readonly versionToCacheKey = new Map(); - public async get(entry: ICacheEntry): Promise { + public async get(entry: ICacheEntry): Promise { const key = getKeyForCacheEntry(entry); return this.cache.get(key); } - public async put(entry: ICacheEntry, value: ValueWithSnapshot): Promise { + public async put(entry: ICacheEntry, value: any): Promise { const key = getKeyForCacheEntry(entry); this.cache.set(key, value); + if (value.value?.snapshotTree?.id === undefined) { + return; + } const versionKey = `${value.value.snapshotTree.id}`; this.versionCache.set(versionKey, value); this.versionToCacheKey.set(versionKey, key);