Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,59 @@
// This script polls to check whether the application has started at localhost:5000, and exits when it has started up,
// or exits with a failure if it hasn't started in 5 minutes.

const programName = 'await-application-startup';
const pollUrl = 'http://localhost:5000/projects';
const pollInterval = 1000;
const timeout = 5 * 60_000;

const startTime = Date.now();
let lastError: string | null = null;

function output(message: string) {
console.log(`${programName}: ${message}`);
}

function outputWithoutNewline(message: string) {
Deno.stdout.writeSync(new TextEncoder().encode(`${programName}: ${message}`));
}

setTimeout(() => {
console.log('Failed to start in ', timeout, ' milliseconds. Exiting.')
console.log(); // New line after dots
if (lastError != null) {
output(`Error: ${lastError}`);
}
output(`Failed to start in ${timeout} milliseconds. Exiting.`);
Deno.exit(1);
}, timeout);

const startTime = Date.now();
function elapsedTime() {
const currentTIme = Date.now();
const elapsed = currentTIme - startTime;
const currentTime = Date.now();
const elapsed = currentTime - startTime;
const minutes = Math.floor(elapsed / 60_000);
const seconds = Math.floor((elapsed % 60_000) / 1000)
return `${minutes}:${seconds < 10 ? '0' + seconds : seconds}`
const seconds = Math.floor((elapsed % 60_000) / 1000);
return `${minutes}:${seconds.toString().padStart(2, '0')}`;
}

async function check() {
try {
const response = await fetch(pollUrl, {
headers: { 'Accept': 'text/html' }
headers: { Accept: 'text/html' }
});
if (response.ok) {
console.log(elapsedTime(), 'Startup check passed. Exiting.')
console.log(); // New line after dots
output(`${elapsedTime()} Startup check passed. Exiting.`);
Deno.exit(0);
} else {
console.log(elapsedTime(), 'Startup check failed: ', response.status, response.statusText)
} } catch (error) {
console.log(elapsedTime(), 'Startup check failed: '+ error.message)
lastError = `${response.status} ${response.statusText}`;
Deno.stdout.writeSync(new TextEncoder().encode('.'));
}
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
lastError = message;
Deno.stdout.writeSync(new TextEncoder().encode('.'));
}
}

outputWithoutNewline('Awaiting application startup before running tests ...');
setTimeout(check, 0);
setInterval(check, pollInterval);
setInterval(check, pollInterval);
1 change: 0 additions & 1 deletion src/SIL.XForge.Scripture/ClientApp/e2e/pre_merge_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ function startServer() {
local SERVER_PID="$!"
trap "shutDownServer ${SERVER_PID}" EXIT
output "Server started with PID ${SERVER_PID}"
output "Awaiting application startup before running tests"
cd "${SCRIPT_DIR}"
./await-application-startup.mts
}
Expand Down
Loading