Skip to content

Commit 46c36ff

Browse files
committed
Improve RoutingTable#toString()
To include current timestamp. Expiration timestamp (based on TTL) can then be compared with the current timestamp in logs.
1 parent f2fc68c commit 46c36ff

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/v1/internal/routing-table.js

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export default class RoutingTable {
7474
toString() {
7575
return `RoutingTable[` +
7676
`expirationTime=${this.expirationTime}, ` +
77+
`currentTime=${Date.now()}, ` +
7778
`routers=[${this.routers}], ` +
7879
`readers=[${this.readers}], ` +
7980
`writers=[${this.writers}]]`;

test/internal/routing-table.test.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,14 @@ describe('routing-table', () => {
169169
});
170170

171171
it('should have correct toString', () => {
172-
const table = createTable([1, 2], [3, 4], [5, 6], 42);
173-
expect(table.toString()).toEqual('RoutingTable[expirationTime=42, routers=[1,2], readers=[3,4], writers=[5,6]]');
172+
const originalDateNow = Date.now;
173+
try {
174+
Date.now = () => 4242;
175+
const table = createTable([1, 2], [3, 4], [5, 6], 42);
176+
expect(table.toString()).toEqual('RoutingTable[expirationTime=42, currentTime=4242, routers=[1,2], readers=[3,4], writers=[5,6]]');
177+
} finally {
178+
Date.now = originalDateNow;
179+
}
174180
});
175181

176182
function expired() {

0 commit comments

Comments
 (0)