Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions tests/periodic-test/time-is-synchronized/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ if (!templateID) {
throw new Error("❌ Template ID not found in e2b.toml");
}

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

try {
// remove the file to make script idempotent in local testing
Expand All @@ -88,15 +88,15 @@ try {

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

console.log("date", date.stdout);
const dateUnix = parseInt(date.stdout);
const dateUnix = parseFloat(date.stdout) / 1000;
console.log("ℹ️ comparing dates", dateUnix, localDate);

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

Expand All @@ -107,8 +107,7 @@ try {
} catch (e) {
console.error("Error while running sandbox or commands", e);
throw e;
} finally {
// delete template
} finally { // delete template
const output = await streamCommandOutput("deno", [
"run",
"--allow-all",
Expand Down
Loading