Fix unrelibable datastore tests (#662)

* Use incrementDateMs

* Change wait time to 15ms

* Fix loop condition
This commit is contained in:
Cooldude2606 authored and GitHub committed 2024-09-14 17:20:52 +01:00
1 parent a1c7173dd2
commit 77fea7e295
1 file changed
+9 -2
+9 -2
View File
@@ -5,6 +5,13 @@ const lib = require("@clusterio/lib");
const fs = require("fs-extra");
const path = require("path");
async function incrementDateMs() {
const prev = Date.now();
do {
await lib.wait(1);
} while (prev >= Date.now());
}
class MockDatastoreProvider extends lib.DatastoreProvider {
constructor() {
super();
@@ -548,7 +555,7 @@ describe("lib/datastore", function() {
assert.notEqual(value.updatedAtMs, undefined);
assert(value.updatedAtMs > 0, "updatedAtMs greater than zero");
const prev = value.updatedAtMs;
await lib.wait();
await incrementDateMs();
datastore.set(value);
assert(value.updatedAtMs > prev, "updatedAtMs must increase");
});
@@ -581,7 +588,7 @@ describe("lib/datastore", function() {
assert(updates[0].updatedAtMs > 0, "updatedAtMs greater than zero");
assert(updates[1].updatedAtMs > 0, "updatedAtMs greater than zero");
const prev = [updates[0].updatedAtMs, updates[1].updatedAtMs];
await lib.wait();
await incrementDateMs();
datastore.setMany(updates);
assert(updates[0].updatedAtMs > prev[0], "updatedAtMs must increase");
assert(updates[1].updatedAtMs > prev[1], "updatedAtMs must increase");