Skip to content

Commit 73791e7

Browse files
committed
Test TTLMap.delete
1 parent a47f045 commit 73791e7

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

backend/src/common/ttlMap.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,19 @@ suite("TTLMap", () => {
105105
assert.ok(!map.has("a"), "!map.has('a')");
106106
}));
107107

108+
test("delete", () => mockTime(() => {
109+
const map: TTLMap<string, null> = new TTLMap(SECOND);
110+
111+
map.set("a", null);
112+
assert.ok(map.delete("a"), "map.delete('a')");
113+
assert.ok(!map.delete("a"), "!map.delete('a')");
114+
115+
map.set("a", null);
116+
time += SECOND;
117+
118+
assert.ok(!map.delete("a"), "!map.delete('a') (after expiry)");
119+
}));
120+
108121
test("precision", () => mockTime(() => {
109122
const map: TTLMap<string, number> = new TTLMap(SECOND);
110123

backend/src/common/ttlMap.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ export class TTLMap<K, V> {
4242
}
4343

4444
delete(key: K): boolean {
45-
return this._map.delete(key);
45+
const had = this.has(key);
46+
this._map.delete(key);
47+
return had;
4648
}
4749

4850
forEach(callbackfn: (value: V, key: K, map: TTLMap<K, V>) => void, thisArg?: any): void {

0 commit comments

Comments
 (0)