Skip to content

Commit a594db3

Browse files
authored
Update the time comparison in periodic tests (#1356)
1 parent 96d81c4 commit a594db3

File tree

1 file changed

+8
-7
lines changed
  • tests/periodic-test/time-is-synchronized

1 file changed

+8
-7
lines changed

tests/periodic-test/time-is-synchronized/index.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,17 @@ try {
8787
console.log("ℹ️ running command");
8888

8989
console.log("ℹ️ starting command");
90-
const localDate = new Date().getTime() / 1000;
90+
const localDateStart = new Date().getTime() / 1000;
9191
const date = await sandbox.commands.run("date +%s%3N");
92-
console.log("localDate", localDate);
93-
94-
console.log("date", date.stdout);
92+
const localDateEnd = new Date().getTime() / 1000;
9593
const dateUnix = parseFloat(date.stdout) / 1000;
96-
console.log("ℹ️ comparing dates", dateUnix, localDate);
9794

98-
// compare the dates, should be within 2 second
99-
if (Math.abs(dateUnix - localDate) > 2) {
95+
console.log("local date - start of request", localDateStart);
96+
console.log("local date - end of request", localDateEnd);
97+
console.log("sandbox date", dateUnix);
98+
99+
// check if the diff between sandbox time and local time is less than 1 second (taking into consideration the request latency)
100+
if (dateUnix < localDateStart - 1 || dateUnix > localDateEnd + 1) {
100101
throw new Error("❌ Date is not synchronized");
101102
}
102103

0 commit comments

Comments
 (0)