Skip to content

Commit 8aca652

Browse files
authored
[CYPRESS TESTS - PART 1] Start auth proxy as a local process (#175)
* 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 <amackillop@squareup.com> * fix workflow file again * add redis-cli * remove cypress from actions Co-authored-by: Austin Mackillop <amackillop@squareup.com>
1 parent 50cefef commit 8aca652

22 files changed

+108
-86
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# This is a basic workflow to help you get started with Actions
2-
31
name: CI
42

53
# Controls when the action will run. Triggers the workflow on push or pull request
@@ -24,10 +22,8 @@ jobs:
2422
uses: actions/setup-python@v1
2523
with:
2624
python-version: 3.7
27-
2825
- name: Install requirements
2926
run: pip install -r requirements_test.txt
30-
3127
- name: Run unit tests
3228
run: |
3329
. ./activate_dev_env.sh
@@ -36,3 +32,10 @@ jobs:
3632
run: |
3733
. ./activate_dev_env.sh
3834
make devenv-start
35+
36+
# - name: Run Cypress tests
37+
# run: |
38+
# sudo apt-get install redis-tools
39+
# . ./activate_dev_env.sh
40+
# make cypress-tests
41+

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,8 @@ integration-tests:
2020

2121
.PHONY: acceptance-tests
2222
acceptance-tests:
23-
./run_acceptance_tests.sh
23+
./run_acceptance_tests.sh
24+
25+
.PHONY: cypress-tests
26+
cypress-tests: devenv-start
27+
cd foundations_ui && yarn cy:run

activate_dev_env.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ export REDIS_URL="redis://localhost:5556"
2727
UI_FOLDER="foundations_ui"
2828
FIXTURE_FOLDER="atlas_scheduler"
2929

30-
export CYPRESS_LOCAL_FOUNDATIONS_HOME="${CWD}/${UI_FOLDER}/cypress/fixtures/${FIXTURE_FOLDER}/.foundations" \
30+
export CYPRESS_LOCAL_FOUNDATIONS_HOME=$FOUNDATIONS_HOME #"${CWD}/${UI_FOLDER}/cypress/fixtures/${FIXTURE_FOLDER}/.foundations" \
3131
export CYPRESS_SCHEDULER_IP="localhost"
3232
export CYPRESS_SCHEDULER_FOUNDATIONS_HOME=$FOUNDATIONS_HOME
33-
export CYPRESS_SCHEDULER_REDIS_PORT=$REDIS_PORT
33+
export CYPRESS_SCHEDULER_REDIS_PORT="5556"
3434
export CYPRESS_GUI_HOST="localhost"
35-
export CYPRESS_GUI_PORT=$GUI_PORT
35+
export CYPRESS_GUI_PORT="3000"
36+
export CYPRESS_REST_API_HOST="localhost"
37+
export CYPRESS_REST_API_PORT="37722"

atlas/testing/acceptance/test_can_load_parameters.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ def test_can_load_parameters_within_foundations_submit(self):
7272
def test_can_load_parameters_as_empty_dict_within_python_empty_params(self):
7373
self._test_can_load_parameters_within_python(self.script_directory_empty_params, {})
7474

75-
def test_can_load_parameters_as_empty_dict_within_foundations_submit_empty_params(self):
76-
self._test_can_load_parameters_within_foundations_submit(self.deployable_script_directory_empty_params, {})
77-
7875
def test_can_load_default_parameters_within_foundations_submit_when_parameters_json_not_found(self):
7976
self._test_can_load_parameters_within_foundations_submit(self.deployable_script_directory_no_parameters, {})
8077

devenv/.foundations/job_data/archive/.gitkeep

Whitespace-only changes.

devenv/docker-compose.yaml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,7 @@ services:
8484
resources:
8585
limits:
8686
memory: 300m
87-
# TODO: set up the auth proxy as well.
88-
auth_proxy:
89-
image: us.gcr.io/atlas-ce/auth-proxy:latest
90-
ports:
91-
- "5558:80"
92-
command: "-n"
93-
deploy:
94-
resources:
95-
limits:
96-
memory: 300m
87+
9788
networks:
9889
default:
9990
name: foundations-atlas

devenv/start_devenv.sh

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
SCRIPT_PID=$$
44
ATLAS_PORT=37722
55
GUI_PORT=3000
6+
AUTH_PROXY_PORT=5558
67

78
export REACT_APP_API_URL="http://127.0.0.1:${ATLAS_PORT}/api/v1/"
89
export REACT_APP_API_STAGING_URL="http://localhost:${ATLAS_PORT}/api/v2beta/"
@@ -17,6 +18,24 @@ function check_status_of_process() {
1718
kill -s TERM $script_pid
1819
fi
1920
}
21+
function wait_for_url() {
22+
attempt_counter=0
23+
SERVICE=$1
24+
max_attempts=$2
25+
26+
until $(curl --output /dev/null --silent --head --fail $SERVICE); do
27+
if [ ${attempt_counter} -eq ${max_attempts} ];then
28+
echo "Max attempts reached"
29+
exit 1
30+
fi
31+
32+
printf '.'
33+
attempt_counter=$(($attempt_counter+1))
34+
sleep 1
35+
done
36+
37+
echo "Connection $SERVICE found"
38+
}
2039

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

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

4059
check_status_of_process "Atlas REST API" $? $SCRIPT_PID
4160

61+
# ***************************************************************************************************************
62+
# Launch Auth Proxy
63+
if [ ! -d "../../foundations-auth-proxy" ];
64+
then
65+
cd ../..
66+
git clone https://github.com/dessa-oss/foundations-auth-proxy.git
67+
cd foundations-auth-proxy
68+
else
69+
cd ../../foundations-auth-proxy
70+
fi
71+
72+
python -m auth_proxy -H localhost -p 5558 > ../atlas/devenv/.foundations/logs/auth_proxy.log 2>&1 &
73+
cd ../atlas/devenv
74+
75+
echo "Waiting for Auth Proxy to start at http://localhost:${AUTH_PROXY_PORT}"
76+
wait_for_url "http://localhost:${AUTH_PROXY_PORT}/" 10
77+
78+
check_status_of_process "Auth Proxy" $? $SCRIPT_PID
79+
4280
# ***************************************************************************************************************
4381
# Launch UI
4482

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

5189
cd ../devenv
5290
echo "Waiting for Atlas GUI to start at http://localhost:${GUI_PORT}"
53-
./wait_for_url.sh "http://localhost:${GUI_PORT}" 80
91+
wait_for_url "http://localhost:${GUI_PORT}" 80
5492

5593
check_status_of_process "Atlas GUI" $? $SCRIPT_PID
5694

devenv/stop_devenv.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ docker-compose down --remove-orphans
55
echo "Attempting to kill proccess for Atlas REST API"
66
kill -9 $(lsof -i:37722 -t) > /dev/null 2>&1 || true
77

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

devenv/wait_for_url.sh

Lines changed: 0 additions & 18 deletions
This file was deleted.

foundations_ui/cypress/integration/atlas_scheduler/test_artifact_saving.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ describe('Test Artifact Saving', () => {
88
{
99
testName: 'Test Artifact Saving through the CLI',
1010
projectName: 'artifact_saving_project',
11-
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`,
11+
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`,
1212
},
1313
{
1414
testName: 'Test Artifact Saving through the SDK',
1515
projectName: 'artifact_saving_project',
16-
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`,
16+
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`,
1717
},
1818
];
1919

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

3133
beforeEach(() => {

0 commit comments

Comments
 (0)