Skip to content

Commit

Permalink
test: fix testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemain committed Jun 21, 2024
1 parent 4420f08 commit 59675fc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 0 additions & 1 deletion __tests__/commander/commander.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ describe('command center', () => {
});

cc.on('hello', async (ctx) => {
console.log(`🚀 ~ file: commander.test.ts:53 ~ cc.on ~ ctx:`, ctx);
await Promise.race([
(async () => {
await sleep(5 * 1000);
Expand Down
13 changes: 11 additions & 2 deletions __tests__/kv/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('KV', () => {
expect(json).toEqual({ key: 'value' });
});
it('can cache', async () => {
jest.useFakeTimers();
const manager = KVManager.for<any>('test', 500);

const spy = jest.spyOn(manager.kv, 'get');
Expand All @@ -36,12 +37,20 @@ describe('KV', () => {

// should only call once, the second time should get from cache
expect(spy).toBeCalledTimes(1);
await sleep(4000);

jest.advanceTimersByTime(300);

const c = await manager.getJSONCached('key');
expect(c).toEqual({ key: 'value' });
expect(spy).toBeCalledTimes(1);

jest.advanceTimersByTime(4000);

const d = await manager.getJSONCached('key');
expect(d).toEqual({ key: 'value' });

expect(spy).toBeCalledTimes(2);
}, 10000);
jest.useRealTimers();
});
});
});

0 comments on commit 59675fc

Please sign in to comment.