Skip to content
Snippets Groups Projects
Unverified Commit 15c7e8de authored by John Daly's avatar John Daly Committed by GitHub
Browse files

fix: Prevent uninitialized cacheProxy from being accessed in cleanup (#20975)

parent c31eb5f1
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,9 @@ describe('util/cache/package/index', () => { ...@@ -7,6 +7,9 @@ describe('util/cache/package/index', () => {
it('returns undefined if not initialized', async () => { it('returns undefined if not initialized', async () => {
expect(await get('test', 'missing-key')).toBeUndefined(); expect(await get('test', 'missing-key')).toBeUndefined();
expect(await set('test', 'some-key', 'some-value', 5)).toBeUndefined(); expect(await set('test', 'some-key', 'some-value', 5)).toBeUndefined();
expect(async () => {
await cleanup({});
}).not.toThrow();
}); });
it('sets and gets file', async () => { it('sets and gets file', async () => {
......
...@@ -4,7 +4,7 @@ import * as fileCache from './file'; ...@@ -4,7 +4,7 @@ import * as fileCache from './file';
import * as redisCache from './redis'; import * as redisCache from './redis';
import type { PackageCache } from './types'; import type { PackageCache } from './types';
let cacheProxy: PackageCache; let cacheProxy: PackageCache | undefined;
function getGlobalKey(namespace: string, key: string): string { function getGlobalKey(namespace: string, key: string): string {
return `global%%${namespace}%%${key}`; return `global%%${namespace}%%${key}`;
...@@ -74,7 +74,7 @@ export async function cleanup(config: AllConfig): Promise<void> { ...@@ -74,7 +74,7 @@ export async function cleanup(config: AllConfig): Promise<void> {
if (config?.redisUrl) { if (config?.redisUrl) {
await redisCache.end(); await redisCache.end();
} }
if (cacheProxy.cleanup) { if (cacheProxy?.cleanup) {
await cacheProxy.cleanup(); await cacheProxy.cleanup();
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment