Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up local HAPI server for e2e tests #90

Merged
merged 26 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8ac5e0c
Fix all the e2e stuff
bamader Oct 28, 2024
697860c
add hapi-fhir-server to docker-compose-dev
m-goggins Oct 28, 2024
89154d0
add data loader to docker compose
m-goggins Oct 28, 2024
b770186
Cleanups
bamader Oct 28, 2024
754b4a4
Merge branch 'main' into optimize-e2e
bamader Oct 29, 2024
9875da8
add docker compose file for e2e tests
m-goggins Oct 29, 2024
cc0c5c5
use e2e docker compose
m-goggins Oct 29, 2024
286c7b8
update setup to check for available data in hapi server
m-goggins Oct 29, 2024
302d66b
Merge branch 'optimize-e2e' of https://github.com/CDCgov/dibbs-query-…
m-goggins Oct 29, 2024
3fea397
temp redirect Public HAPI for testing
m-goggins Oct 29, 2024
15d7b72
temp changes
m-goggins Oct 29, 2024
ce63a25
don't touch anything; this works
m-goggins Oct 29, 2024
4b4790c
add Poll for hapi server
m-goggins Oct 30, 2024
d43aebb
get response status
m-goggins Oct 30, 2024
859c2ce
check status using container name
m-goggins Oct 30, 2024
ed2cdc0
run e2e version of docker compose in CI
m-goggins Oct 30, 2024
cc4835c
add back networks
m-goggins Oct 30, 2024
07e1c5b
update polling to check based on container name, not localhost
m-goggins Oct 30, 2024
6744e11
update all instances of localhost in CI
m-goggins Oct 30, 2024
e11368f
change QC polling back to localhost
m-goggins Oct 30, 2024
85b4891
remove networks
m-goggins Oct 30, 2024
ccf4b12
bump timeout & more verbose error messages
m-goggins Oct 30, 2024
6c6a12c
change hapi-fhir-server to localhost in CI
m-goggins Oct 30, 2024
558918c
update tests to use local server
m-goggins Oct 30, 2024
fd27dbf
Merge branch 'main' into marcelle/2758-set-up-local-hapi-server-for-t…
m-goggins Oct 30, 2024
5a3701c
Merge branch 'main' of https://github.com/CDCgov/dibbs-query-connecto…
m-goggins Oct 30, 2024
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
20 changes: 18 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
run: npm test

end-to-end-tests:
timeout-minutes: 10
timeout-minutes: 15
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand All @@ -67,13 +67,29 @@ jobs:
run: docker compose build --no-cache
- name: Run Query Connector
working-directory: ./query-connector
run: docker compose up -d
run: docker compose -f ./docker-compose-e2e.yaml up -d
- name: Poll until Query Connector is ready
run: |
until curl -s http://localhost:3000/tefca-viewer; do
echo "Waiting for Query Connector to be ready before running Playwright..."
sleep 5
done
- name: Poll until HAPI server is ready
run: |
until response=$(curl -v -s -w "HTTP_STATUS:%{http_code}" http://localhost:8080/fhir/Patient); do
# Extract status code from the response
http_status=$(echo "$response" | grep "HTTP_STATUS" | awk -F: '{print $2}')
echo "Waiting for HAPI server to be ready..."
echo "Response code: $http_status"
echo "Full response: $response"
sleep 5
done
- name: Poll until FHIR server has data
run: |
until curl -s http://localhost:8080/fhir/Patient | jq '.entry | length > 0' | grep -q 'true'; do
echo "Waiting for FHIR server to have data..."
sleep 5
done
- name: Playwright Tests
working-directory: ./query-connector
run: npx playwright test e2e --reporter=list --config playwright.config.ts
Expand Down
16 changes: 16 additions & 0 deletions query-connector/docker-compose-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,19 @@ services:
depends_on:
db:
condition: service_started

# HAPI FHIR Server for running e2e tests
hapi-fhir-server:
image: "hapiproject/hapi:latest"
ports:
- "8080:8080"
data-loader:
build:
context: .
dockerfile: Dockerfile.dev
volumes:
- "./src/app/tests/assets/GoldenSickPatient.json:/etc/GoldenSickPatient.json"
- "./post_e2e_data_hapi.sh:/post_e2e_data_hapi.sh"
command: ["sh", "post_e2e_data_hapi.sh"]
depends_on:
- hapi-fhir-server
50 changes: 50 additions & 0 deletions query-connector/docker-compose-e2e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
services:
# PostgreSQL DB for custom query and value set storage
db:
image: "postgres:alpine"
ports:
- "5432:5432"
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=pw
- POSTGRES_DB=tefca_db
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 2s
timeout: 5s
retries: 20

# Next.js app with Flyway
tefca-viewer:
platform: linux/amd64
build:
context: .
dockerfile: Dockerfile
tty: true
ports:
- "3000:3000"
environment:
- NODE_ENV=production
- DATABASE_URL=postgres://postgres:pw@db:5432/tefca_db
- NEXT_PUBLIC_HAPI_FHIR_URL=http://hapi-fhir-server:8080
# Note: you must have a local .env file with the ERSD_API_KEY set to a key
# obtained from the ERSD API at https://ersd.aimsplatform.org/#/api-keys
depends_on:
db:
condition: service_healthy
# HAPI FHIR Server for running e2e tests
hapi-fhir-server:
image: "hapiproject/hapi:latest"
ports:
- "8080:8080"
# Loads synthetic data into hapi-fhir-server for e2e tests
data-loader:
build:
context: .
dockerfile: Dockerfile.dev
volumes:
- "./src/app/tests/assets/GoldenSickPatient.json:/etc/GoldenSickPatient.json"
- "./post_e2e_data_hapi.sh:/post_e2e_data_hapi.sh"
command: ["sh", "post_e2e_data_hapi.sh"]
depends_on:
- hapi-fhir-server
18 changes: 18 additions & 0 deletions query-connector/e2e/alternate_queries.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ test.describe("alternate queries with the Query Connector", () => {
await page.getByLabel("Last Name").clear();
await page.getByLabel("Medical Record Number").clear();

// Select FHIR server from drop down
await page.getByRole("button", { name: "Advanced" }).click();
await page
.getByLabel("FHIR Server (QHIN)")
.selectOption("Local e2e HAPI Server: Direct");

// Among verification, make sure phone number is right
await page.getByRole("button", { name: "Search for patient" }).click();
await expect(page.getByText("Loading")).toHaveCount(0, { timeout: 10000 });
Expand All @@ -46,6 +52,12 @@ test.describe("alternate queries with the Query Connector", () => {
test("cancer query with generalized function", async ({ page }) => {
await page.getByRole("button", { name: "Go to the demo" }).click();
await page.getByRole("button", { name: "Fill fields" }).click();
// Select FHIR server from drop down
await page.getByRole("button", { name: "Advanced" }).click();
await page
.getByLabel("FHIR Server (QHIN)")
.selectOption("Local e2e HAPI Server: Direct");

await page.getByRole("button", { name: "Search for patient" }).click();
await expect(page.getByText("Loading")).toHaveCount(0, { timeout: 10000 });

Expand All @@ -68,6 +80,12 @@ test.describe("alternate queries with the Query Connector", () => {
}) => {
await page.getByRole("button", { name: "Go to the demo" }).click();
await page.getByRole("button", { name: "Fill fields" }).click();
// Select FHIR server from drop down
await page.getByRole("button", { name: "Advanced" }).click();
await page
.getByLabel("FHIR Server (QHIN)")
.selectOption("Local e2e HAPI Server: Direct");

await page.getByRole("button", { name: "Search for patient" }).click();
await expect(page.getByText("Loading")).toHaveCount(0, { timeout: 10000 });
await page.getByRole("link", { name: "Select patient" }).click();
Expand Down
6 changes: 6 additions & 0 deletions query-connector/e2e/customize_query.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ test.describe("querying with the Query Connector", () => {
).toBeVisible();

await page.getByRole("button", { name: "Fill fields" }).click();
// Select FHIR server from drop down
await page.getByRole("button", { name: "Advanced" }).click();
await page
.getByLabel("FHIR Server (QHIN)")
.selectOption("Local e2e HAPI Server: Direct");

await page.getByRole("button", { name: "Search for patient" }).click();
await expect(page.getByText("Loading")).toHaveCount(0, { timeout: 10000 });

Expand Down
12 changes: 12 additions & 0 deletions query-connector/e2e/query_workflow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ test.describe("querying with the Query Connector", () => {
await page.getByRole("button", { name: "Fill fields" }).click();
await page.getByLabel("First Name").fill("Shouldnt");
await page.getByLabel("Last Name").fill("Findanyone");
// Select FHIR server from drop down
await page.getByRole("button", { name: "Advanced" }).click();
await page
.getByLabel("FHIR Server (QHIN)")
.selectOption("Local e2e HAPI Server: Direct");

await page.getByRole("button", { name: "Search for patient" }).click();

// Better luck next time, user!
Expand Down Expand Up @@ -48,6 +54,12 @@ test.describe("querying with the Query Connector", () => {
).toBeVisible();

await page.getByRole("button", { name: "Fill fields" }).click();
// Select FHIR server from drop down
await page.getByRole("button", { name: "Advanced" }).click();
await page
.getByLabel("FHIR Server (QHIN)")
.selectOption("Local e2e HAPI Server: Direct");

await page.getByRole("button", { name: "Search for patient" }).click();
await expect(page.getByText("Loading")).toHaveCount(0, { timeout: 10000 });

Expand Down
2 changes: 1 addition & 1 deletion query-connector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"test:unit": "jest --testPathPattern=tests/unit",
"test:unit:watch": "jest --watch",
"test:integration": "jest --testPathPattern=tests/integration",
"test:playwright": "docker compose build --no-cache && docker compose up -d && npx playwright test --reporter=list",
"test:playwright": "docker compose build --no-cache && docker compose -f ./docker-compose-e2e.yaml up -d && npx playwright test --reporter=list",
"test:playwright:local": "dotenv -e ./.env -- npx playwright test --ui",
"cypress:open": "cypress open",
"cypress:run": "cypress run"
Expand Down
25 changes: 6 additions & 19 deletions query-connector/playwright-setup.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,32 @@
/**
*
*/

export const TEST_URL =
process.env.TEST_ENV ?? "http://localhost:3000/tefca-viewer";

/**
*
*/
async function globalSetup() {
const maxRetries = 300; // Maximum number of retries
const delay = 1000; // Delay between retries in milliseconds
const delay = 5000; // Delay between retries in milliseconds

// Check TEST_URL
for (let attempts = 0; attempts < maxRetries; attempts++) {
try {
const response = await fetch(TEST_URL); // Fetch the TEST_URL
const response = await fetch(TEST_URL);
if (response.status === 200) {
console.log(`Connected to ${TEST_URL} successfully.`);
return; // Exit the function if the webpage loads successfully
break; // Proceed to the FHIR server check
} else {
console.log(
`Failed to connect to ${TEST_URL}, status: ${response.status}. Retrying...`,
`Failed to connect to ${TEST_URL}, status: ${response.status}. Error: ${response.text} Retrying...`,
);
// Wait before the next attempt
await new Promise((resolve) => setTimeout(resolve, delay));
}
} catch (error) {
console.log(
`Fetch failed for ${TEST_URL}: ${
(error as Error).message
}. Retrying...`,
`Fetch failed for ${TEST_URL}: ${(error as Error).message}. Retrying...`,
);
await new Promise((resolve) => setTimeout(resolve, delay));
}
// Wait before the next attempt
await new Promise((resolve) => setTimeout(resolve, delay));
}

throw new Error(
`Unable to connect to ${TEST_URL} after ${maxRetries} attempts.`,
);
}

export default globalSetup;
6 changes: 3 additions & 3 deletions query-connector/post_request.sh → query-connector/post_e2e_data_hapi.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

# URL to check
URL="http://tefca-fhir-server:8080/fhir/"
TEST_URL="http://tefca-fhir-server:8080/fhir/metadata"
URL="http://hapi-fhir-server:8080/fhir/"
TEST_URL="http://hapi-fhir-server:8080/fhir/metadata"

# Maximum number of attempts (120 seconds / 5 seconds = 24 attempts)
MAX_ATTEMPTS=24
Expand All @@ -20,7 +20,7 @@ while [ $attempt -lt $MAX_ATTEMPTS ]; do
echo "Server is healthy!"

# POST Bundle of synthetic data to spun up server
curl -X POST -H "Content-Type: application/json" -d @/etc/BundleHAPIServer.json $URL
curl -X POST -H "Content-Type: application/json" -d @/etc/GoldenSickPatient.json $URL

exit 0
fi
Expand Down
1 change: 1 addition & 0 deletions query-connector/src/app/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export const FhirServers = [
"JMC Meld: Direct",
"JMC Meld: eHealthExchange",
"Public HAPI: Direct",
"Local e2e HAPI Server: Direct",
m-goggins marked this conversation as resolved.
Show resolved Hide resolved
"OpenEpic: eHealthExchange",
"CernerHelios: eHealthExchange",
"OPHDST Meld: Direct",
Expand Down
12 changes: 11 additions & 1 deletion query-connector/src/app/fhir-servers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export const fhirServers: Record<FHIR_SERVERS, FHIR_SERVER_CONFIG> = {
hostname: "https://hapi.fhir.org/baseR4",
init: {} as RequestInit,
},
"Local e2e HAPI Server: Direct": {
hostname: "http://hapi-fhir-server:8080/fhir",
init: {} as RequestInit,
},
"OpenEpic: eHealthExchange": configureEHX("OpenEpic"),
"CernerHelios: eHealthExchange": configureEHX("CernerHelios"),
"OPHDST Meld: Direct": {
Expand Down Expand Up @@ -85,7 +89,13 @@ class FHIRClient {
}

async get(path: string): Promise<Response> {
return fetch(this.hostname + path, this.init);
try {
console.log("FHIR Server: ", this.hostname);
return fetch(this.hostname + path, this.init);
} catch (error) {
console.error(error);
throw error;
}
}

async getBatch(paths: Array<string>): Promise<Array<Response>> {
Expand Down
Loading