Skip to content

Commit

Permalink
AG-1474: run e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hallieswan committed Jun 5, 2024
1 parent 841db25 commit e957154
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 23 deletions.
65 changes: 62 additions & 3 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
name: Build Data Image and Run End-to-end Tests

on:
push:
branches:
- AG-1471_AG-1473_AG-1474
branches: [ develop, main ]
pull_request:
branches: [ develop, main ]

jobs:
e2e:
timeout-minutes: 60
runs-on: ubuntu-20.04
environment: e2e
env:
Expand Down Expand Up @@ -39,7 +43,7 @@ jobs:
echo "==> data image tag: ${{ env.DATA_IMAGE_TAG }}"
echo "IMAGE_EXISTS=false" >> "$GITHUB_ENV"
# TODO - move into job which conditionally runs based on IMAGE_EXISTS
# TODO - move into job which conditionally runs based on IMAGE_EXISTS
# https://github.com/actions/setup-python/issues/807
- name: create placeholder requirements.txt file
run: touch ./requirements.txt
Expand Down Expand Up @@ -86,3 +90,58 @@ jobs:
--build-arg LOCAL_CREATE_INDEXES_PATH="${{ env.LOCAL_CREATE_INDEXES_PATH }}" \
.
# TODO - push image to remote repository

# TODO - move into job that pulls image from remote repository
- uses: actions/setup-node@v4
with:
node-version: 16

- name: install dependencies
run: npm install

- name: install Playwright Browsers
run: npx playwright install --with-deps

- name: start database, server, and app
env:
DB_USER: ${{ secrets.DB_USER }}
DB_PASS: ${{ secrets.DB_PASS }}
DB_PORT: ${{ vars.DB_PORT }}
DB_NAME: ${{ vars.DB_NAME }}
run: |
echo "==> start database and data containers"
docker-compose -f "${{ env.DOCKER_COMPOSE_PATH }}" up -d
echo "==> wait for data container to finish seeding database container"
DATA_CONTAINER=$(docker compose -f "${{ env.DOCKER_COMPOSE_PATH }}" ps -a --format '{{.Name}}' mongo-seed)
docker wait "${DATA_CONTAINER}"
echo "==> start server and app in background and wait for server to grab port"
MONGODB_HOST="localhost" MONGODB_PORT="${{ env.DB_PORT }}" APP_ENV="e2e" npm run dev >/dev/null 2>&1 &
sleep 5
- name: run e2e tests
run: npx playwright test

- name: clean up database, server, and app
env:
DB_USER: ${{ secrets.DB_USER }}
DB_PASS: ${{ secrets.DB_PASS }}
DB_PORT: ${{ vars.DB_PORT }}
DB_NAME: ${{ vars.DB_NAME }}
run: |
echo "==> stop app"
pid=$(lsof -i :3000 -t) && kill ${pid}
echo "==> stop server"
pid=$(lsof -i :8080 -t) && kill ${pid}
echo "==> stop database"
docker-compose -f "${{ env.DOCKER_COMPOSE_PATH }}" down
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 5
26 changes: 26 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Agora Docker Image

Files in this directory:

- `Dockerfile`: creates the `agora/data` docker image, which contains data for a particular Agora data release (manifest synId + version) and team images and will seed a mongodb at start up using `import-data.sh`
- `docker-compose.yml`: spins up `mongo` and `agora/data` docker containers

## Workflow Setup

The following secrets and variables need to be set up in GitHub for the `e2e.yml` workflow to create the `agora/data` Docker image:

e2e Environment secrets:

| Variable | Description | Example |
| ------------------ | ------------------------------------------ | ----------------- |
| DB_USER | The database user | dbuser |
| DB_PASS | The database password | supersecret |
| SYNAPSE_AUTH_TOKEN | The Synapse service user view/download PAT | token-string-here |

e2e Environment variables:

| Variable | Description | Example |
| -------------- | ----------------------------------- | ------- |
| DB_NAME | The database name | agora |
| DB_PORT | The database port | 27017 |
| TEAM_IMAGES_ID | The synId of the team images folder | syn123 |
14 changes: 8 additions & 6 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineConfig, devices } from '@playwright/test';

export const baseURL = 'http://localhost:8080';
const port = 8080;
export const baseURL = `http://127.0.0.1:${port}`;

/**
* Read environment variables from file.
Expand All @@ -14,17 +15,17 @@ export const baseURL = 'http://localhost:8080';
export default defineConfig({
testDir: './tests',
// timeout for every test
timeout: 25 * 60 * 1000,
timeout: 3 * 60 * 1000,
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
workers: process.env.CI ? 2 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
reporter: process.env.CI ? [['list'], ['html']] : 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
Expand Down Expand Up @@ -75,7 +76,8 @@ export default defineConfig({
/* Run your local dev server before starting the tests */
webServer: {
command: 'npm run start',
url: baseURL,
reuseExistingServer: !process.env.CI,
port,
reuseExistingServer: true,
timeout: 120 * 1000,
},
});
35 changes: 21 additions & 14 deletions src/server/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,37 @@ const database = { url: '' };
doc && ('doc => ' + util.inspect(doc)), '\n');
}); */

console.log(process.env);
console.log(process.env.MONGODB_HOST);
console.log(process.env.MONGODB_PORT);

// Set the database url
if (
process.env.MONGODB_HOST &&
process.env.MONGODB_PORT &&
process.env.APP_ENV
) {
const results = awsParamStore.getParametersSync(
[
'/agora-' + process.env.APP_ENV + '/MongodbUsername',
'/agora-' + process.env.APP_ENV + '/MongodbPassword',
],
{ region: 'us-east-1' }
);
let dbUser: string | undefined;
let dbPass: string | undefined;
if (process.env.APP_ENV === 'e2e') {
dbUser = process.env.DB_USER;
dbPass = process.env.DB_PASS;
} else {
const results = awsParamStore.getParametersSync(
[
'/agora-' + process.env.APP_ENV + '/MongodbUsername',
'/agora-' + process.env.APP_ENV + '/MongodbPassword',
],
{ region: 'us-east-1' }
);
if (results && results.Parameters) {
dbUser = results.Parameters[1]['Value'];
dbPass = results.Parameters[0]['Value'];
}
}

if (results && results.Parameters) {
if (dbUser && dbPass) {
database.url =
'mongodb://' +
results.Parameters[1]['Value'] +
dbUser +
':' +
results.Parameters[0]['Value'] +
dbPass +
'@' +
process.env.MONGODB_HOST +
':' +
Expand Down

0 comments on commit e957154

Please sign in to comment.