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

+1 -1
View File
@@ -22,7 +22,7 @@ describe("controller/InstanceInfo", function() {
check(InstanceInfo.fromJSON({ config, status: "stopped" }, "controller"));
check(InstanceInfo.fromJSON({ config, status: "running" }, "controller"));
check(InstanceInfo.fromJSON({ config, status: "running", gamePort: 34197 }, "controller"));
check(InstanceInfo.fromJSON({ config, status: "running", updatedAt: Date.now() }, "controller"));
check(InstanceInfo.fromJSON({ config, status: "running", updatedAtMs: Date.now() }, "controller"));
// All at once
check(InstanceInfo.fromJSON({
+6 -6
View File
@@ -64,7 +64,7 @@ describe("class Instance", function() {
"player",
new PlayerStats({
join_count: 1,
last_join_at: stats.lastJoinAt.getTime(),
last_join_at_ms: stats.lastJoinAt.getTime(),
})
)
),
@@ -111,8 +111,8 @@ describe("class Instance", function() {
new PlayerStats({
join_count: 1,
online_time_ms: stats.onlineTimeMs,
last_join_at: stats.lastJoinAt.getTime(),
last_leave_at: stats.lastLeaveAt.getTime(),
last_join_at_ms: stats.lastJoinAt.getTime(),
last_leave_at_ms: stats.lastLeaveAt.getTime(),
last_leave_reason: "quit",
}),
"quit",
@@ -162,7 +162,7 @@ describe("class Instance", function() {
"foo",
new PlayerStats({
join_count: 1,
last_join_at: stats.lastJoinAt.getTime(),
last_join_at_ms: stats.lastJoinAt.getTime(),
})
)
)
@@ -185,8 +185,8 @@ describe("class Instance", function() {
new PlayerStats({
join_count: 1,
online_time_ms: stats.onlineTimeMs,
last_join_at: stats.lastJoinAt.getTime(),
last_leave_at: stats.lastLeaveAt.getTime(),
last_join_at_ms: stats.lastJoinAt.getTime(),
last_leave_at_ms: stats.lastLeaveAt.getTime(),
last_leave_reason: "quit",
}),
"quit",
+1 -1
View File
@@ -214,7 +214,7 @@ describe("host/server", function() {
if (process.platform === "win32") {
this.skip();
}
server.hangTimeout = 20;
server.hangTimeoutMs = 20;
server._server = new events.EventEmitter();
server._server.kill = () => true;
server._state = "running";
+3 -3
View File
@@ -113,7 +113,7 @@ describe("Integration of Clusterio", function() {
let controlB = new TestControl(connectorB);
connectorB._sessionToken = connectorA._sessionToken;
connectorB._sessionTimeout = connectorA._sessionTimeout;
connectorB._startedResuming = Date.now();
connectorB._startedResumingMs = Date.now();
connectorB._state = "resuming";
connectorB._doConnect();
await events.once(connectorB, "resume");
@@ -898,7 +898,7 @@ describe("Integration of Clusterio", function() {
reference.settings["runtime-global"].set("MyInt", { value: 1235 });
reference.settings["runtime-global"].set("MyDouble", { value: 12.25 });
reference.settings["runtime-per-user"].set("MyString", { value: "a-string" });
reference.updatedAt = modPack.updatedAt;
reference.updatedAtMs = modPack.updatedAtMs;
assert.deepEqual(modPack, reference);
});
});
@@ -1003,7 +1003,7 @@ describe("Integration of Clusterio", function() {
"dependencies:\n" +
`size: ${stat.size}\n` +
`sha1: ${hash}\n` +
`updatedAt: ${stat.mtimeMs}\n` +
`updatedAtMs: ${stat.mtimeMs}\n` +
"isDeleted: false\n",
);
});
+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));