Skip to content

Commit 21c441e

Browse files
authored
Improve test time is synced (#1286)
1 parent c395085 commit 21c441e

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

  • tests/periodic-test/time-is-synchronized

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ if (!templateID) {
7070
throw new Error("❌ Template ID not found in e2b.toml");
7171
}
7272

73-
// sleep for 5 seconds to create a time delta
74-
await new Promise((resolve) => setTimeout(resolve, 5000));
73+
// sleep for 15 seconds to create a time delta
74+
await new Promise((resolve) => setTimeout(resolve, 15000));
7575

7676
try {
7777
// remove the file to make script idempotent in local testing
@@ -88,15 +88,15 @@ try {
8888

8989
console.log("ℹ️ starting command");
9090
const localDate = new Date().getTime() / 1000;
91-
const date = await sandbox.commands.run("date +%s");
91+
const date = await sandbox.commands.run("date +%s%3N");
9292
console.log("localDate", localDate);
9393

9494
console.log("date", date.stdout);
95-
const dateUnix = parseInt(date.stdout);
95+
const dateUnix = parseFloat(date.stdout) / 1000;
9696
console.log("ℹ️ comparing dates", dateUnix, localDate);
9797

98-
// compare the dates, should be within 1 second
99-
if (Math.abs(dateUnix - localDate) > 1) {
98+
// compare the dates, should be within 2 second
99+
if (Math.abs(dateUnix - localDate) > 2) {
100100
throw new Error("❌ Date is not synchronized");
101101
}
102102

@@ -107,8 +107,7 @@ try {
107107
} catch (e) {
108108
console.error("Error while running sandbox or commands", e);
109109
throw e;
110-
} finally {
111-
// delete template
110+
} finally { // delete template
112111
const output = await streamCommandOutput("deno", [
113112
"run",
114113
"--allow-all",

0 commit comments

Comments
 (0)