MCPcopy Create free account
hub / github.com/Datakitpage/Datakit / waitForServer

Function waitForServer

backend/integration_tests/setup/global-setup.js:9–37  ·  view source on GitHub ↗
(port, timeout = 30000)

Source from the content-addressed store, hash-verified

7
8// Function to wait for server to be ready
9function waitForServer(port, timeout = 30000) {
10 return new Promise((resolve, reject) => {
11 const startTime = Date.now();
12
13 const checkServer = () => {
14 const req = http.get(`http://localhost:${port}/api/health`, (res) => {
15 if (res.statusCode === 200) {
16 resolve();
17 } else {
18 if (Date.now() - startTime > timeout) {
19 reject(new Error(`Server did not start within ${timeout}ms`));
20 } else {
21 setTimeout(checkServer, 1000);
22 }
23 }
24 });
25
26 req.on('error', () => {
27 if (Date.now() - startTime > timeout) {
28 reject(new Error(`Server did not start within ${timeout}ms`));
29 } else {
30 setTimeout(checkServer, 1000);
31 }
32 });
33 };
34
35 checkServer();
36 });
37}
38
39module.exports = async function globalSetup() {
40 console.log('🚀 Starting global setup for integration tests...');

Callers 1

global-setup.jsFile · 0.85

Calls 1

checkServerFunction · 0.85

Tested by

no test coverage detected