Skip to content

Commit 36f0243

Browse files
committed
test(appkit): add regression test for non-signal cache callers
Verify that direct getOrExecute callers (like telemetry-example-plugin) that pass a plain async function without accepting the shared signal continue to work after the in-flight deduplication refactor. Also update the MockCacheManager signature to match the new real implementation. Signed-off-by: Pawel Kosiec <pawel.kosiec@databricks.com>
1 parent dd95e69 commit 36f0243

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

packages/appkit/src/cache/tests/cache-manager.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,24 @@ describe("CacheManager", () => {
378378
expect(r2).toBe("result-2");
379379
expect(fn).toHaveBeenCalledTimes(2);
380380
});
381+
382+
test("should work when fn ignores signal parameter (non-signal caller regression)", async () => {
383+
const cache = await CacheManager.getInstance({
384+
storage: createMockStorage(),
385+
});
386+
// Simulates direct callers like telemetry-example-plugin that pass
387+
// a plain async function without accepting the shared signal.
388+
const fn = vi.fn().mockResolvedValue("no-signal-result");
389+
390+
const result = await cache.getOrExecute(["key"], fn, "user1", {
391+
ttl: 60,
392+
});
393+
394+
expect(result).toBe("no-signal-result");
395+
expect(fn).toHaveBeenCalledTimes(1);
396+
// The cache passes the shared AbortSignal even if the fn ignores it
397+
expect(fn).toHaveBeenCalledWith(expect.any(AbortSignal));
398+
});
381399
});
382400

383401
describe("disabled cache", () => {

packages/appkit/src/plugin/tests/cache.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ class MockCacheManager {
2020

2121
async getOrExecute<T>(
2222
key: (string | number | object)[],
23-
fn: () => Promise<T>,
23+
fn: (sharedSignal?: AbortSignal) => Promise<T>,
2424
userKey: string,
25-
options?: { ttl?: number },
25+
options?: { ttl?: number; callerSignal?: AbortSignal },
2626
): Promise<T> {
2727
const cacheKey = this.generateKey(key, userKey);
2828
const cached = await this.get<T>(cacheKey);

0 commit comments

Comments
 (0)