Skip to content

Commit

Permalink
ci: run a server smoke test in the pipeline
Browse files Browse the repository at this point in the history
This verifies the server can launch with all the default settings.
  • Loading branch information
jagregory committed Dec 9, 2021
1 parent 635c527 commit b1900ff
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ jobs:
lint:
runs-on: ubuntu-latest
name: Lint
timeout-minutes: 5

steps:
- uses: actions/checkout@v2
Expand All @@ -27,6 +28,7 @@ jobs:
unit_test:
runs-on: ubuntu-latest
name: Unit Test
timeout-minutes: 5

steps:
- uses: actions/checkout@v2
Expand All @@ -41,9 +43,28 @@ jobs:
- run: yarn install
- run: yarn test

smoke_test:
runs-on: ubuntu-latest
name: Smoke Test
timeout-minutes: 5

steps:
- uses: actions/checkout@v2
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v1
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: ${{ runner.os }}-yarn-
- run: yarn install
- run: scripts/smoke-test

integration_test:
runs-on: ubuntu-latest
name: Integration Test
timeout-minutes: 5

steps:
- uses: actions/checkout@v2
Expand Down
30 changes: 30 additions & 0 deletions scripts/smoke-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

# This script launches the Cognito Local server, then polls the server until the /health endpoint
# responds with a 200. If the server doesn't respond in time, or exits with a non-zero code, the
# script will fail.
#
# We run this in CI to prove the actual server can start. This catches some edge-cases where
# everything else passes, but something in the compile produced invalid JavaScript.

export PORT=59232
yarn start &
PID=$!

trap "kill $PID" SIGINT

PORT=$PORT timeout --foreground -s TERM 30 bash -c \
'while [[ ${STATUS_RECEIVED} != 200 ]];\
do STATUS_RECEIVED=$(curl -s -o /dev/null -L -w ''%{http_code}'' http://localhost:$PORT/health) && \
echo "received status: $STATUS_RECEIVED" && \
sleep 1;\
done;
echo success with status: $STATUS_RECEIVED'
CURL_EXIT_CODE=$?

kill $PID

if [[ $CURL_EXIT_CODE -ne 0 ]]; then
echo Failed to start in time >&2
exit 1
fi
4 changes: 4 additions & 0 deletions src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export const createServer = (
});
});

app.get("/health", (req, res) => {
res.status(200).json({ ok: true });
});

app.post("/", (req, res) => {
const xAmzTarget = req.headers["x-amz-target"];

Expand Down

0 comments on commit b1900ff

Please sign in to comment.