Skip to content

Commit

Permalink
test: coverage back to 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
Falx committed Apr 14, 2022
1 parent 4836cbc commit 2541ac6
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions test/unit/util/locking/RedisReadWriteLocker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,14 +408,23 @@ describe('A RedisLocker', (): void => {
expect(redis.quit).toHaveBeenCalledTimes(1);
});
});
it('should clear all keys when finalize() is called.', async(): Promise<void> => {
it('should clear all lock keys when finalize() is called.', async(): Promise<void> => {
redis.keys.mockResolvedValueOnce([ '__L__k1', '__L__k2' ]);
// // This works since the redis is simply a mock and quit should have cleared the internal store
await locker.withWriteLock(resource1, async(): Promise<any> => {
await locker.finalize();
expect(redis.quit).toHaveBeenCalledTimes(1);
});
});

it('should clear all rw keys when finalize() is called.', async(): Promise<void> => {
redis.keys.mockResolvedValueOnce([ '__RW__k1', '__RW__k2' ]);
// // This works since the redis is simply a mock and quit should have cleared the internal store
await locker.withWriteLock(resource1, async(): Promise<any> => {
await locker.finalize();
expect(redis.quit).toHaveBeenCalledTimes(1);
});
});
});
});

Expand Down Expand Up @@ -502,7 +511,15 @@ describe('A RedisLocker', (): void => {
});

describe('finalize()', (): void => {
it('should clear all locks and intervals when finalize() is called.', async(): Promise<void> => {
it('should clear all locks (even when empty) when finalize() is called.', async(): Promise<void> => {
await locker.finalize();
expect(redis.quit).toHaveBeenCalledTimes(1);
});

it('should clear all locks when finalize() is called.', async(): Promise<void> => {
redis.keys
.mockResolvedValueOnce([ '__L__k1', '__L__k2' ])
.mockResolvedValueOnce([ '__L__k1', '__L__k2' ]);
await locker.finalize();
expect(redis.quit).toHaveBeenCalledTimes(1);
});
Expand Down

0 comments on commit 2541ac6

Please sign in to comment.