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

Development: Add multi node e2e tests with playwright #8599

Merged
merged 15 commits into from
May 18, 2024
Merged
2 changes: 2 additions & 0 deletions .ci/E2E-tests/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ docker compose -f ./docker/cypress-E2E-tests-mysql.yml down -v
docker compose -f ./docker/cypress-E2E-tests-postgres.yml down -v
docker compose -f ./docker/playwright-E2E-tests-mysql.yml down -v
docker compose -f ./docker/cypress-E2E-tests-local.yml down -v
docker compose -f ./docker/playwright-E2E-tests-multi-node.yml down -v
docker compose -f ./docker/cypress-E2E-tests-multi-node.yml down -v

# show all running docker containers and volumes after the cleanup to detect issues
echo "SHOW RUNNING Docker containers and volumes:"
Expand Down
36 changes: 27 additions & 9 deletions .ci/E2E-tests/execute.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ if [ "$TEST_FRAMEWORK" = "playwright" ]; then
COMPOSE_FILE="playwright-E2E-tests-postgres.yml"
elif [ "$CONFIGURATION" = "mysql-localci" ]; then
COMPOSE_FILE="playwright-E2E-tests-mysql-localci.yml"
elif [ "$CONFIGURATION" = "multi-node" ]; then
COMPOSE_FILE="playwright-E2E-tests-multi-node.yml"
else
echo "Invalid configuration. Please choose among mysql, postgres or mysql-localci."
echo "Invalid configuration. Please choose among mysql, postgres, mysql-localci or multi-node."
exit 1
fi
else
Expand All @@ -26,6 +28,8 @@ else
COMPOSE_FILE="cypress-E2E-tests-postgres.yml"
elif [ "$CONFIGURATION" = "local" ]; then
COMPOSE_FILE="cypress-E2E-tests-local.yml"
elif [ "$CONFIGURATION" = "multi-node" ]; then
COMPOSE_FILE="cypress-E2E-tests-multi-node.yml"
else
echo "Invalid configuration. Please choose among mysql, postgres or local."
exit 1
Expand All @@ -45,15 +49,29 @@ export HOST_HOSTNAME=$(hostname)
cd docker
#just pull everything else than artemis-app as we build it later either way
if [ "$TEST_FRAMEWORK" = "playwright" ]; then
echo "Building for playwright"
docker compose -f $COMPOSE_FILE pull artemis-playwright $CONFIGURATION nginx
docker compose -f $COMPOSE_FILE build --build-arg WAR_FILE_STAGE=external_builder --no-cache --pull artemis-app
docker compose -f $COMPOSE_FILE up --exit-code-from artemis-playwright
if [ "$CONFIGURATION" = "multi-node" ]; then
echo "Building for playwright"
docker compose -f $COMPOSE_FILE pull artemis-playwright $CONFIGURATION nginx
docker compose -f $COMPOSE_FILE build --build-arg WAR_FILE_STAGE=external_builder --no-cache --pull artemis-app-node-1 artemis-app-node-2 artemis-app-node-3
docker compose -f $COMPOSE_FILE up --exit-code-from artemis-playwright
else
echo "Building for playwright"
docker compose -f $COMPOSE_FILE pull artemis-playwright $CONFIGURATION nginx
docker compose -f $COMPOSE_FILE build --build-arg WAR_FILE_STAGE=external_builder --no-cache --pull artemis-app
docker compose -f $COMPOSE_FILE up --exit-code-from artemis-playwright
fi
else
echo "Building for cypress"
docker compose -f $COMPOSE_FILE pull artemis-cypress $CONFIGURATION nginx
docker compose -f $COMPOSE_FILE build --build-arg WAR_FILE_STAGE=external_builder --no-cache --pull artemis-app
docker compose -f $COMPOSE_FILE up --exit-code-from artemis-cypress
if [ "$CONFIGURATION" = "multi-node" ]; then
echo "Building for cypress"
docker compose -f $COMPOSE_FILE pull artemis-cypress $CONFIGURATION nginx
docker compose -f $COMPOSE_FILE build --build-arg WAR_FILE_STAGE=external_builder --no-cache --pull artemis-app-node-1 artemis-app-node-2 artemis-app-node-3
docker compose -f $COMPOSE_FILE up --exit-code-from artemis-cypress
else
echo "Building for cypress"
docker compose -f $COMPOSE_FILE pull artemis-cypress $CONFIGURATION nginx
docker compose -f $COMPOSE_FILE build --build-arg WAR_FILE_STAGE=external_builder --no-cache --pull artemis-app
docker compose -f $COMPOSE_FILE up --exit-code-from artemis-cypress
fi
fi
exitCode=$?
cd ..
Expand Down
154 changes: 154 additions & 0 deletions docker/cypress-E2E-tests-multi-node.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# ----------------------------------------------------------------------------------------------------------------------
# Cypress setup for multi-node
# ----------------------------------------------------------------------------------------------------------------------

services:
artemis-app-node-1:
container_name: artemis-app-node-1
extends:
file: ./artemis.yml
service: artemis-app
image: ghcr.io/ls1intum/artemis:${ARTEMIS_DOCKER_TAG:-latest}
depends_on:
mysql:
condition: service_healthy
jhipster-registry:
condition: service_healthy
activemq-broker:
condition: service_healthy
pull_policy: always
restart: always
group_add:
- ${DOCKER_GROUP_ID:-0}
env_file:
- ./artemis/config/prod-multinode.env
- ./artemis/config/node1.env
- ./artemis/config/cypress.env
volumes:
- /var/run/docker.sock:/var/run/docker.sock

artemis-app-node-2:
container_name: artemis-app-node-2
extends:
file: ./artemis.yml
service: artemis-app
image: ghcr.io/ls1intum/artemis:${ARTEMIS_DOCKER_TAG:-latest}
depends_on:
mysql:
condition: service_healthy
jhipster-registry:
condition: service_healthy
activemq-broker:
condition: service_healthy
artemis-app-node-1:
condition: service_healthy
pull_policy: always
restart: always
group_add:
- ${DOCKER_GROUP_ID:-0}
env_file:
- ./artemis/config/prod-multinode.env
- ./artemis/config/node2.env
- ./artemis/config/cypress.env
volumes:
- /var/run/docker.sock:/var/run/docker.sock

artemis-app-node-3:
container_name: artemis-app-node-3
extends:
file: ./artemis.yml
service: artemis-app
image: ghcr.io/ls1intum/artemis:${ARTEMIS_DOCKER_TAG:-latest}
depends_on:
mysql:
condition: service_healthy
jhipster-registry:
condition: service_healthy
activemq-broker:
condition: service_healthy
artemis-app-node-1:
condition: service_healthy
pull_policy: always
restart: always
group_add:
- ${DOCKER_GROUP_ID:-0}
env_file:
- ./artemis/config/prod-multinode.env
- ./artemis/config/node3.env
- ./artemis/config/cypress.env
volumes:
- /var/run/docker.sock:/var/run/docker.sock

jhipster-registry:
extends:
file: ./broker-registry.yml
service: jhipster-registry
networks:
- artemis

activemq-broker:
extends:
file: ./broker-registry.yml
service: activemq-broker
networks:
- artemis

mysql:
extends:
file: ./mysql.yml
service: mysql
restart: always

nginx:
extends:
file: ./nginx.yml
service: nginx
depends_on:
artemis-app-node-1:
condition: service_started
artemis-app-node-2:
condition: service_started
artemis-app-node-3:
condition: service_started
restart: always
ports:
- '80:80'
- '443:443'
# see comments in artemis/config/cypress.env why this port is necessary
- '54321:54321'
volumes:
- ./nginx/artemis-upstream-multi-node.conf:/etc/nginx/includes/artemis-upstream.conf:ro
- ./nginx/artemis-nginx-cypress.conf:/etc/nginx/conf.d/artemis-nginx-cypress.conf:ro
- type: bind
source: ${NGINX_PROXY_SSL_CERTIFICATE_PATH:-../src/test/cypress/certs/artemis-nginx+4.pem}
target: "/certs/fullchain.pem"
- type: bind
source: ${NGINX_PROXY_SSL_CERTIFICATE_KEY_PATH:-../src/test/cypress/certs/artemis-nginx+4-key.pem}
target: "/certs/priv_key.pem"


artemis-cypress:
extends:
file: ./cypress.yml
service: artemis-cypress
depends_on:
artemis-app:
condition: service_healthy
environment:
CYPRESS_DB_TYPE: "Local"
SORRY_CYPRESS_PROJECT_ID: "artemis-local"
CYPRESS_createUsers: "true"
command: sh -c "cd /app/artemis/src/test/cypress && chmod 777 /root && npm ci && npm run cypress:setup && (npm run cypress:record:local & sleep 60 && npm run cypress:record:local & wait)"


networks:
artemis:
driver: "bridge"
name: artemis

volumes:
artemis-mysql-data:
name: artemis-mysql-data
artemis-data:
name: artemis-data

155 changes: 155 additions & 0 deletions docker/playwright-E2E-tests-multi-node.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# ----------------------------------------------------------------------------------------------------------------------
# Playwright setup for multi-node
# ----------------------------------------------------------------------------------------------------------------------

services:
artemis-app-node-1:
container_name: artemis-app-node-1
extends:
file: ./artemis.yml
service: artemis-app
image: ghcr.io/ls1intum/artemis:${ARTEMIS_DOCKER_TAG:-latest}
depends_on:
mysql:
condition: service_healthy
jhipster-registry:
condition: service_healthy
activemq-broker:
condition: service_healthy
pull_policy: always
restart: always
user: 0:0
env_file:
- ./artemis/config/prod-multinode.env
- ./artemis/config/node1.env
- ./artemis/config/cypress.env
volumes:
- /var/run/docker.sock:/var/run/docker.sock

artemis-app-node-2:
container_name: artemis-app-node-2
extends:
file: ./artemis.yml
service: artemis-app
image: ghcr.io/ls1intum/artemis:${ARTEMIS_DOCKER_TAG:-latest}
depends_on:
mysql:
condition: service_healthy
jhipster-registry:
condition: service_healthy
activemq-broker:
condition: service_healthy
artemis-app-node-1:
condition: service_healthy
pull_policy: always
restart: always
user: 0:0
env_file:
- ./artemis/config/prod-multinode.env
- ./artemis/config/node2.env
- ./artemis/config/cypress.env
volumes:
- /var/run/docker.sock:/var/run/docker.sock

artemis-app-node-3:
container_name: artemis-app-node-3
extends:
file: ./artemis.yml
service: artemis-app
image: ghcr.io/ls1intum/artemis:${ARTEMIS_DOCKER_TAG:-latest}
depends_on:
mysql:
condition: service_healthy
jhipster-registry:
condition: service_healthy
activemq-broker:
condition: service_healthy
artemis-app-node-1:
condition: service_healthy
pull_policy: always
restart: always
user: 0:0
env_file:
- ./artemis/config/prod-multinode.env
- ./artemis/config/node3.env
- ./artemis/config/cypress.env
volumes:
- /var/run/docker.sock:/var/run/docker.sock

jhipster-registry:
extends:
file: ./broker-registry.yml
service: jhipster-registry
networks:
- artemis

activemq-broker:
extends:
file: ./broker-registry.yml
service: activemq-broker
networks:
- artemis

mysql:
extends:
file: ./mysql.yml
service: mysql
restart: always

nginx:
extends:
file: ./nginx.yml
service: nginx
depends_on:
artemis-app-node-1:
condition: service_started
artemis-app-node-2:
condition: service_started
artemis-app-node-3:
condition: service_started
restart: always
ports:
- '80:80'
- '443:443'
# see comments in artemis/config/cypress.env why this port is necessary
- '54321:54321'
volumes:
- ./nginx/artemis-upstream-multi-node.conf:/etc/nginx/includes/artemis-upstream.conf:ro
- ./nginx/artemis-nginx-cypress.conf:/etc/nginx/conf.d/artemis-nginx-cypress.conf:ro
- type: bind
source: ${NGINX_PROXY_SSL_CERTIFICATE_PATH:-../src/test/cypress/certs/artemis-nginx+4.pem}
target: "/certs/fullchain.pem"
- type: bind
source: ${NGINX_PROXY_SSL_CERTIFICATE_KEY_PATH:-../src/test/cypress/certs/artemis-nginx+4-key.pem}
target: "/certs/priv_key.pem"


artemis-playwright:
extends:
file: ./playwright.yml
service: artemis-playwright
depends_on:
nginx:
condition: service_healthy
environment:
PLAYWRIGHT_DB_TYPE: 'MySQL'
command: >
sh -c '
cd /app/artemis/src/test/playwright &&
chmod 777 /root &&
npm ci &&
npm run playwright:setup &&
npm run playwright:test
'

networks:
artemis:
driver: "bridge"
name: artemis

volumes:
artemis-mysql-data:
name: artemis-mysql-data
artemis-data:
name: artemis-data

4 changes: 2 additions & 2 deletions src/test/playwright/support/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ export class PlaywrightUserManagement {
* @returns the username template.
*/
private getUsernameTemplate(): string {
return process.env.PLAYWRIGHT_USERNAME_TEMPLATE ?? 'user_' + USER_ID_SELECTOR;
return (process.env.PLAYWRIGHT_USERNAME_TEMPLATE ?? 'user_') + USER_ID_SELECTOR;
}

/**
* @returns the password template.
*/
private getPasswordTemplate(): string {
return process.env.PLAYWRIGHT_PASSWORD_TEMPLATE ?? 'password_' + USER_ID_SELECTOR;
return (process.env.PLAYWRIGHT_PASSWORD_TEMPLATE ?? 'password_') + USER_ID_SELECTOR;
}

/**
Expand Down
Loading