Skip to content

Commit

Permalink
ci: improve false-positive failures (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
wellwelwel committed Jun 27, 2024
1 parent dba8e21 commit 2c609da
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 149 deletions.
64 changes: 60 additions & 4 deletions test/e2e/background-process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { startScript, startService } from '../../src/modules/create-service.js';
import { legacyFetch } from '../helpers/legacy-fetch.test.js';
import { ext, isProduction } from '../helpers/capture-cli.test.js';
import { getRuntime } from '../../src/helpers/get-runtime.js';
import { waitForPort } from '../../src/modules/wait-for.js';

test(async () => {
const runtime = getRuntime();
Expand All @@ -20,6 +21,7 @@ test(async () => {
: 'ci/fixtures/server',
});

await waitForPort(4000, { timeout: 5000, delay: 100 });
const res = await legacyFetch('localhost', 4000);

assert.strictEqual(res?.statusCode, 200, 'Service is on');
Expand All @@ -44,6 +46,7 @@ test(async () => {
runner: runtime === 'node' ? 'npm' : runtime,
});

await waitForPort(4001, { timeout: 5000, delay: 100 });
const res = await legacyFetch('localhost', 4001);

assert.strictEqual(res?.statusCode, 200, 'Script is on');
Expand All @@ -67,6 +70,7 @@ test(async () => {
: 'ci/fixtures/server',
});

await waitForPort(4000, { timeout: 5000, delay: 100 });
const res = await legacyFetch('localhost', 4000);

assert.strictEqual(res?.statusCode, 200, 'Service is on');
Expand All @@ -83,14 +87,15 @@ test(async () => {
await describe('Start Service (Timer)', async () => {
await it(async () => {
const server = await startService(`server-a.${ext}`, {
startAfter: 5000,
timeout: 6000,
startAfter: 2500,
timeout: 5000,
cwd:
ext === 'ts' || isProduction
? 'fixtures/server'
: 'ci/fixtures/server',
});

await waitForPort(4000, { timeout: 5000, delay: 100 });
const res = await legacyFetch('localhost', 4000);

assert.strictEqual(res?.statusCode, 200, 'Service is on');
Expand All @@ -115,6 +120,7 @@ test(async () => {
runner: runtime === 'node' ? 'npm' : runtime,
});

await waitForPort(4001, { timeout: 5000, delay: 100 });
const res = await legacyFetch('localhost', 4001);

assert.strictEqual(res?.statusCode, 200, 'Script is on');
Expand All @@ -131,15 +137,63 @@ test(async () => {
await describe('Start Script (Timer)', async () => {
await it(async () => {
const server = await startScript(`start:${ext}`, {
startAfter: 5000,
timeout: 6000,
startAfter: 2500,
timeout: 5000,
cwd:
ext === 'ts' || isProduction
? 'fixtures/server'
: 'ci/fixtures/server',
runner: runtime === 'node' ? 'npm' : runtime,
});

await waitForPort(4001, { timeout: 5000, delay: 100 });
const res = await legacyFetch('localhost', 4001);

assert.strictEqual(res?.statusCode, 200, 'Script is on');
assert.deepStrictEqual(
JSON.parse(res?.body),
{ name: 'Poku' },
'Poku script is online'
);

await server.end([4001]);
});
});

await describe('Start Service (No "startAfter")', async () => {
await it(async () => {
const server = await startService(`server-a.${ext}`, {
cwd:
ext === 'ts' || isProduction
? 'fixtures/server'
: 'ci/fixtures/server',
});

await waitForPort(4000, { timeout: 10000, delay: 100 });
const res = await legacyFetch('localhost', 4000);

assert.strictEqual(res?.statusCode, 200, 'Service is on');
assert.deepStrictEqual(
JSON.parse(res?.body),
{ name: 'Poku' },
'Poku service is online'
);

await server.end([4000]);
});
});

await describe('Start Script (No "startAfter")', async () => {
await it(async () => {
const server = await startScript(`start:${ext}`, {
cwd:
ext === 'ts' || isProduction
? 'fixtures/server'
: 'ci/fixtures/server',
runner: runtime === 'node' ? 'npm' : runtime,
});

await waitForPort(4001, { timeout: 10000, delay: 100 });
const res = await legacyFetch('localhost', 4001);

assert.strictEqual(res?.statusCode, 200, 'Script is on');
Expand All @@ -164,6 +218,7 @@ test(async () => {
: 'ci/fixtures/server',
});

await waitForPort(4000, { timeout: 5000, delay: 100 });
const res = await legacyFetch('localhost', 4000);

assert.strictEqual(res?.statusCode, 200, 'Service is on');
Expand All @@ -188,6 +243,7 @@ test(async () => {
runner: runtime === 'node' ? 'npm' : runtime,
});

await waitForPort(4001, { timeout: 5000, delay: 100 });
const res = await legacyFetch('localhost', 4001);

assert.strictEqual(res?.statusCode, 200, 'Script is on');
Expand Down
6 changes: 2 additions & 4 deletions test/integration/containers/test-docker-compose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ describe('Docker Compose Service', async () => {
});

await compose.up();

await waitForPort(6001, { delay: 100 });
await waitForPort(6001, { delay: 100, timeout: 120000 });

const res = await legacyFetch('localhost', 6001);

Expand All @@ -62,8 +61,7 @@ describe('Docker Compose Service', async () => {
});

await compose.up();

await waitForPort(6001, { delay: 100 });
await waitForPort(6001, { delay: 100, timeout: 120000 });

const res = await legacyFetch('localhost', 6001);

Expand Down
2 changes: 1 addition & 1 deletion test/integration/containers/test-dockerfile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('Docker Service', async () => {
await dockerfile.build();
await dockerfile.start();

await waitForPort(6000, { delay: 100 });
await waitForPort(6000, { delay: 100, timeout: 120000 });

const res = await legacyFetch('localhost', 6000);

Expand Down
Loading

0 comments on commit 2c609da

Please sign in to comment.