Add time unit suffixes to variables (#561)

Add suffixes like Ms and Ns to variables whos time unit is not in
seconds.  This is aligning with a new code style of putting units
on variables that are not in SI base units.
This commit is contained in:
Hornwitser authored and GitHub committed 2024-01-20 13:26:55 +01:00
1 parent 9842705eb9
commit c53781d16c
38 files changed
+221 -201

No files matched your search

+3 -3
View File
@@ -36,7 +36,7 @@ describe("lib/ExponentialBackoff", function() {
for (let max of [0.1, 0.5, 1, 2, 50, 100, 1000, 100000]) {
let backoff = new ExponentialBackoff({ base: 1, max });
for (let j = 0; j < 100; j++) {
let value = backoff.delay() / 1000; // Divide by 100 for ms to s conversion
let value = backoff.delay() / 1000; // Divide by 1000 for ms to s conversion
assert(value <= max, `delay returned a value greater than max: ${value} > ${max}`);
}
}
@@ -46,10 +46,10 @@ describe("lib/ExponentialBackoff", function() {
let backoff = new ExponentialBackoff({ reset: 100 });
backoff.delay();
assert.equal(backoff._exp, 1);
backoff._lastInvocationTime = Date.now() - 99 * 1000;
backoff._lastInvocationTimeMs = Date.now() - 99 * 1000;
backoff.delay();
assert.equal(backoff._exp, 2);
backoff._lastInvocationTime = Date.now() - 101 * 1000;
backoff._lastInvocationTimeMs = Date.now() - 101 * 1000;
backoff.delay();
assert.equal(backoff._exp, 1);
});
+1 -1
View File
@@ -92,7 +92,7 @@ describe("lib/data/ModInfo", function() {
dependencies: [],
filename: "empty_mod_1.0.0.zip",
size: stat.size,
updated_at: stat.mtimeMs,
updated_at_ms: stat.mtimeMs,
sha1: hash,
})
);
+7 -7
View File
@@ -28,15 +28,15 @@ describe("lib/data/User", function() {
[1, {
join_count: 1,
online_time_ms: 60e3,
last_join_at: new Date("2020-05T12:00Z").getTime(),
last_leave_at: new Date("2020-05T12:01Z").getTime(),
last_join_at_ms: new Date("2020-05T12:00Z").getTime(),
last_leave_at_ms: new Date("2020-05T12:01Z").getTime(),
last_leave_reason: "quit",
}],
[2, {
join_count: 1,
online_time_ms: 0,
first_join_at: new Date("2020-05T12:00Z").getTime(),
last_join_at: new Date("2020-05T12:02Z").getTime(),
first_join_at_ms: new Date("2020-05T12:00Z").getTime(),
last_join_at_ms: new Date("2020-05T12:02Z").getTime(),
}],
]});
@@ -52,9 +52,9 @@ describe("lib/data/User", function() {
lib.PlayerStats.fromJSON({
join_count: 2,
online_time_ms: 120e3,
first_join_at: new Date("2020-05T11:00Z").getTime(),
last_join_at: new Date("2020-05T13:00Z").getTime(),
last_leave_at: new Date("2020-05T13:02Z").getTime(),
first_join_at_ms: new Date("2020-05T11:00Z").getTime(),
last_join_at_ms: new Date("2020-05T13:00Z").getTime(),
last_leave_at_ms: new Date("2020-05T13:02Z").getTime(),
last_leave_reason: "afk",
}),
);
+2 -2
View File
@@ -21,10 +21,10 @@ describe("lib/helpers", function() {
it("should wait the approximate amount of time given", async function() {
let startNs = hrtime();
await lib.wait(100);
let duration = Number(hrtime() - startNs) / 1e6;
let durationMs = Number(hrtime() - startNs) / 1e6;
// On windows the time waited is normally up to 15 ms late with outliers in the 20ms range.
assert(duration > 90 && duration < 130, `duration (${duration}ms) not within (90-130)`);
assert(durationMs > 90 && durationMs < 130, `duration (${durationMs}ms) not within (90-130)`);
});
});
+7 -4
View File
@@ -347,7 +347,7 @@ describe("lib/subscriptions", function() {
it("should allow subscriptions to an event", async function() {
let calledWith = null;
let calledWithTwo = null;
const item = { id: 1, updatedAt: 1, isDeleted: false };
const item = { id: 1, updatedAtMs: 1, isDeleted: false };
const event = new RegisteredEvent([item]);
registeredEvent.subscribe(function(updates, synced) { calledWith = [updates, synced]; });
registeredEvent.subscribe(function(updates, synced) { calledWithTwo = [updates, synced]; });
@@ -382,9 +382,12 @@ describe("lib/subscriptions", function() {
describe("getSnapshot()", function() {
it("should give an immutable copy of the tracked values", async function() {
const update1 = [{ id: 1, updatedAt: 1, isDeleted: false }];
const update2 = [{ id: 1, updatedAt: 2, isDeleted: false }, { id: 2, updatedAt: 3, isDeleted: false }];
const update3 = [{ id: 1, updatedAt: 4, isDeleted: true }];
const update1 = [{ id: 1, updatedAtMs: 1, isDeleted: false }];
const update2 = [
{ id: 1, updatedAtMs: 2, isDeleted: false },
{ id: 2, updatedAtMs: 3, isDeleted: false },
];
const update3 = [{ id: 1, updatedAtMs: 4, isDeleted: true }];
const snap0 = registeredEvent.getSnapshot();
assert.deepEqual(snap0, [new Map(), false]);
await registeredEvent._handle(new RegisteredEvent(update1));