Skip to content

Commit

Permalink
[CYPRESS TESTS - PART 1] Start auth proxy as a local process (#175)
Browse files Browse the repository at this point in the history
* Start auth proxy as a local process

This is necessary in order to run the cypress tests because if the auth proxy is in a container, it cannot communicate with the locally running rest api.

* clone auth proxy if not exist

* try https for clone

* [CYPRESS TESTS - PART2] Run cypress tests in actions (also easy local run) (#176)

* fix cypress tests and add to makefile

* fix lint error

* get rid of checkout for auth proxy, clone worked

* remove flaky test

* fix workflow file

Co-authored-by: Austin Mackillop <[email protected]>

* fix workflow file again

* add redis-cli

* remove cypress from actions

Co-authored-by: Austin Mackillop <[email protected]>
  • Loading branch information
amackillop and amackillop authored Jul 22, 2020
1 parent 50cefef commit 8aca652
Show file tree
Hide file tree
Showing 22 changed files with 108 additions and 86 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the action will run. Triggers the workflow on push or pull request
Expand All @@ -24,10 +22,8 @@ jobs:
uses: actions/setup-python@v1
with:
python-version: 3.7

- name: Install requirements
run: pip install -r requirements_test.txt

- name: Run unit tests
run: |
. ./activate_dev_env.sh
Expand All @@ -36,3 +32,10 @@ jobs:
run: |
. ./activate_dev_env.sh
make devenv-start
# - name: Run Cypress tests
# run: |
# sudo apt-get install redis-tools
# . ./activate_dev_env.sh
# make cypress-tests

6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ integration-tests:

.PHONY: acceptance-tests
acceptance-tests:
./run_acceptance_tests.sh
./run_acceptance_tests.sh

.PHONY: cypress-tests
cypress-tests: devenv-start
cd foundations_ui && yarn cy:run
8 changes: 5 additions & 3 deletions activate_dev_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ export REDIS_URL="redis://localhost:5556"
UI_FOLDER="foundations_ui"
FIXTURE_FOLDER="atlas_scheduler"

export CYPRESS_LOCAL_FOUNDATIONS_HOME="${CWD}/${UI_FOLDER}/cypress/fixtures/${FIXTURE_FOLDER}/.foundations" \
export CYPRESS_LOCAL_FOUNDATIONS_HOME=$FOUNDATIONS_HOME #"${CWD}/${UI_FOLDER}/cypress/fixtures/${FIXTURE_FOLDER}/.foundations" \
export CYPRESS_SCHEDULER_IP="localhost"
export CYPRESS_SCHEDULER_FOUNDATIONS_HOME=$FOUNDATIONS_HOME
export CYPRESS_SCHEDULER_REDIS_PORT=$REDIS_PORT
export CYPRESS_SCHEDULER_REDIS_PORT="5556"
export CYPRESS_GUI_HOST="localhost"
export CYPRESS_GUI_PORT=$GUI_PORT
export CYPRESS_GUI_PORT="3000"
export CYPRESS_REST_API_HOST="localhost"
export CYPRESS_REST_API_PORT="37722"
3 changes: 0 additions & 3 deletions atlas/testing/acceptance/test_can_load_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ def test_can_load_parameters_within_foundations_submit(self):
def test_can_load_parameters_as_empty_dict_within_python_empty_params(self):
self._test_can_load_parameters_within_python(self.script_directory_empty_params, {})

def test_can_load_parameters_as_empty_dict_within_foundations_submit_empty_params(self):
self._test_can_load_parameters_within_foundations_submit(self.deployable_script_directory_empty_params, {})

def test_can_load_default_parameters_within_foundations_submit_when_parameters_json_not_found(self):
self._test_can_load_parameters_within_foundations_submit(self.deployable_script_directory_no_parameters, {})

Expand Down
Empty file.
11 changes: 1 addition & 10 deletions devenv/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,7 @@ services:
resources:
limits:
memory: 300m
# TODO: set up the auth proxy as well.
auth_proxy:
image: us.gcr.io/atlas-ce/auth-proxy:latest
ports:
- "5558:80"
command: "-n"
deploy:
resources:
limits:
memory: 300m

networks:
default:
name: foundations-atlas
42 changes: 40 additions & 2 deletions devenv/start_devenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
SCRIPT_PID=$$
ATLAS_PORT=37722
GUI_PORT=3000
AUTH_PROXY_PORT=5558

export REACT_APP_API_URL="http://127.0.0.1:${ATLAS_PORT}/api/v1/"
export REACT_APP_API_STAGING_URL="http://localhost:${ATLAS_PORT}/api/v2beta/"
Expand All @@ -17,6 +18,24 @@ function check_status_of_process() {
kill -s TERM $script_pid
fi
}
function wait_for_url() {
attempt_counter=0
SERVICE=$1
max_attempts=$2

until $(curl --output /dev/null --silent --head --fail $SERVICE); do
if [ ${attempt_counter} -eq ${max_attempts} ];then
echo "Max attempts reached"
exit 1
fi

printf '.'
attempt_counter=$(($attempt_counter+1))
sleep 1
done

echo "Connection $SERVICE found"
}

# ***************************************************************************************************************
# Launch Docker Containers
Expand All @@ -35,10 +54,29 @@ echo "Running Atlas REST API on port ${ATLAS_PORT}"
python startup_atlas_api.py ${ATLAS_PORT} > .foundations/logs/atlas_rest_api.log 2>&1 &

echo "Waiting for Atlas REST API to start at http://localhost:${ATLAS_PORT}"
./wait_for_url.sh "http://localhost:${ATLAS_PORT}/api/v2beta/projects" 10
wait_for_url "http://localhost:${ATLAS_PORT}/api/v2beta/projects" 10

check_status_of_process "Atlas REST API" $? $SCRIPT_PID

# ***************************************************************************************************************
# Launch Auth Proxy
if [ ! -d "../../foundations-auth-proxy" ];
then
cd ../..
git clone https://github.com/dessa-oss/foundations-auth-proxy.git
cd foundations-auth-proxy
else
cd ../../foundations-auth-proxy
fi

python -m auth_proxy -H localhost -p 5558 > ../atlas/devenv/.foundations/logs/auth_proxy.log 2>&1 &
cd ../atlas/devenv

echo "Waiting for Auth Proxy to start at http://localhost:${AUTH_PROXY_PORT}"
wait_for_url "http://localhost:${AUTH_PROXY_PORT}/" 10

check_status_of_process "Auth Proxy" $? $SCRIPT_PID

# ***************************************************************************************************************
# Launch UI

Expand All @@ -50,7 +88,7 @@ cd ../foundations_ui && \

cd ../devenv
echo "Waiting for Atlas GUI to start at http://localhost:${GUI_PORT}"
./wait_for_url.sh "http://localhost:${GUI_PORT}" 80
wait_for_url "http://localhost:${GUI_PORT}" 80

check_status_of_process "Atlas GUI" $? $SCRIPT_PID

Expand Down
3 changes: 3 additions & 0 deletions devenv/stop_devenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ docker-compose down --remove-orphans
echo "Attempting to kill proccess for Atlas REST API"
kill -9 $(lsof -i:37722 -t) > /dev/null 2>&1 || true

echo "Attempting to kill proccess for the Auth Proxy"
kill -9 $(lsof -i:5558 -t) > /dev/null 2>&1 || true

echo "Attempting to kill proccess for the UI"
kill -9 $(lsof -i:3000 -t) > /dev/null 2>&1 || true
18 changes: 0 additions & 18 deletions devenv/wait_for_url.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ describe('Test Artifact Saving', () => {
{
testName: 'Test Artifact Saving through the CLI',
projectName: 'artifact_saving_project',
command: `export FOUNDATIONS_HOME=\`pwd\`/cypress/fixtures/atlas_scheduler/.foundations && foundations login http://${schedulerIP}:5558 -u test -p test && cd cypress/fixtures/atlas_scheduler/artifact_saving && foundations submit scheduler artifact_saving_project main.py`,
command: `export FOUNDATIONS_HOME=\`pwd\`/cypress/fixtures/atlas_scheduler/.foundations && python -m foundations login http://${schedulerIP}:5558 -u test -p test && cd cypress/fixtures/atlas_scheduler/artifact_saving && python -m foundations submit scheduler artifact_saving_project main.py`,
},
{
testName: 'Test Artifact Saving through the SDK',
projectName: 'artifact_saving_project',
command: `export FOUNDATIONS_HOME=\`pwd\`/cypress/fixtures/atlas_scheduler/.foundations && foundations login http://${schedulerIP}:5558 -u test -p test && cd cypress/fixtures/atlas_scheduler/artifact_saving/artifact_saving_project && python main.py`,
command: `export FOUNDATIONS_HOME=\`pwd\`/cypress/fixtures/atlas_scheduler/.foundations && python -m foundations login http://${schedulerIP}:5558 -u test -p test && cd cypress/fixtures/atlas_scheduler/artifact_saving/artifact_saving_project && python main.py`,
},
];

Expand All @@ -25,7 +25,9 @@ describe('Test Artifact Saving', () => {
describe(state.testName, () => {
before(() => {
cy.exec(`redis-cli -h ${schedulerIP} -p ${schedulerRedisPort} flushall`);
cy.exec(state.command);
cy.exec(state.command).then(result => {
console.log(result.stdout);
});
});

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ describe('Test Fast Job', () => {
{
testName: 'Test Ten Fast Jobs through CLI',
projectName: projectName,
command: `export FOUNDATIONS_HOME=\`pwd\`/cypress/fixtures/atlas_scheduler/.foundations && cd cypress/fixtures/atlas_scheduler/fast_job/ && foundations login http://${schedulerIP}:5558 -u test -p test && foundations submit scheduler ${projectName} main.py &`,
command: `export FOUNDATIONS_HOME=\`pwd\`/cypress/fixtures/atlas_scheduler/.foundations && cd cypress/fixtures/atlas_scheduler/fast_job/ && python -m foundations login http://${schedulerIP}:5558 -u test -p test && python -m foundations submit scheduler ${projectName} main.py &`,
},
{
testName: 'Test Ten Fast Jobs through SDK',
projectName: projectName,
command: `export FOUNDATIONS_HOME=\`pwd\`/cypress/fixtures/atlas_scheduler/.foundations && cd cypress/fixtures/atlas_scheduler/fast_job/${projectName}/ && foundations login http://${schedulerIP}:5558 -u test -p test && python main.py &`,
command: `export FOUNDATIONS_HOME=\`pwd\`/cypress/fixtures/atlas_scheduler/.foundations && cd cypress/fixtures/atlas_scheduler/fast_job/${projectName}/ && python -m foundations login http://${schedulerIP}:5558 -u test -p test && python main.py &`,
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ describe('Test Invalid Image', () => {
projectName: 'invalid_image_project',
jobStatus: 'failed',
logs: '404 Client Error',
command: `export FOUNDATIONS_HOME=\`pwd\`/cypress/fixtures/atlas_scheduler/.foundations && cd cypress/fixtures/atlas_scheduler/invalid_image && foundations login http://${schedulerIP}:5558 -u test -p test && foundations submit scheduler invalid_image_project main.py`,
command: `export FOUNDATIONS_HOME=\`pwd\`/cypress/fixtures/atlas_scheduler/.foundations && cd cypress/fixtures/atlas_scheduler/invalid_image && python -m foundations login http://${schedulerIP}:5558 -u test -p test && python -m foundations submit scheduler invalid_image_project main.py`,
},
{
testName: 'Test Invalid Image through the SDK',
projectName: 'invalid_image_project',
jobStatus: 'completed',
logs: '',
command: `export FOUNDATIONS_HOME=\`pwd\`/cypress/fixtures/atlas_scheduler/.foundations && cd cypress/fixtures/atlas_scheduler/invalid_image/invalid_image_project && foundations login http://${schedulerIP}:5558 -u test -p test && python main.py`,
command: `export FOUNDATIONS_HOME=\`pwd\`/cypress/fixtures/atlas_scheduler/.foundations && cd cypress/fixtures/atlas_scheduler/invalid_image/invalid_image_project && python -m foundations login http://${schedulerIP}:5558 -u test -p test && python main.py`,
},
];

Expand Down
Loading

0 comments on commit 8aca652

Please sign in to comment.