Skip to content

Commit

Permalink
fix(test): Add frontend integration test manual run (#8767)
Browse files Browse the repository at this point in the history
* Fix bug in the front-end test

* Add local debugging to the FE test

* Save testing artifacts to GCS

* Address comments
  • Loading branch information
gkcalat authored Jan 31, 2023
1 parent 9a32f76 commit c79d35f
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 20 deletions.
6 changes: 6 additions & 0 deletions test/deploy-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function clean_up {
ALL_PODS=($(kubectl get pods -o=custom-columns=:metadata.name -n $NAMESPACE))
for POD_NAME in "${ALL_PODS[@]}"; do
pod_info_file="$POD_INFO_DIR/$POD_NAME.txt"
echo "Saving log of $POD_NAME to $pod_info_file"
echo "Pod name: $POD_NAME" >> "$pod_info_file"
echo "Detailed logs:" >> "$pod_info_file"
echo "https://console.cloud.google.com/logs/viewer?project=$PROJECT&advancedFilter=resource.type%3D%22k8s_container%22%0Aresource.labels.project_id%3D%22$PROJECT%22%0Aresource.labels.location%3D%22us-east1-b%22%0Aresource.labels.cluster_name%3D%22${TEST_CLUSTER}%22%0Aresource.labels.namespace_name%3D%22$NAMESPACE%22%0Aresource.labels.pod_name%3D%22$POD_NAME%22" \
Expand All @@ -50,6 +51,11 @@ function clean_up {
echo "--------" >> "$pod_info_file"
kubectl get pod $POD_NAME -n $NAMESPACE -o yaml >> "$pod_info_file"
done

echo "Archiving ${ARTIFACTS} into ./${COMMIT_SHA}_logs.tar.gz"
tar -czf ./${COMMIT_SHA}_logs.tar.gz ${ARTIFACTS}
echo "Uploading ./${COMMIT_SHA}_logs.tar.gz to ${TEST_RESULTS_GCS_DIR}/logs"
gsutil cp ${COMMIT_SHA}_logs.tar.gz "${TEST_RESULTS_GCS_DIR}/logs"

echo "Clean up cluster..."
if [ $SHOULD_CLEANUP_CLUSTER == true ]; then
Expand Down
24 changes: 24 additions & 0 deletions test/frontend-integration-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Frontend integration test

This test gets triggered by the end-to-end testing workflows.

## Local run

1. Deploy KFP on a k8s cluster and enable port forwarding. Replace the default namespace `kubeflow` below if needed.

```bash
POD=`kubectl get pods -n kubeflow -l app=ml-pipeline-ui -o jsonpath='{.items[0].metadata.name}'`
kubectl port-forward -n kubeflow ${POD} 3000:3000 &
```

1. Build the container with the tests:

```bash
docker build . -t kfp-frontend-integration-test:local
```

1. Run the test with enabled networking (**this exposes your local networking stack to the testing container**):

```bash
docker run --net=host kfp-frontend-integration-test:local --remote-run true
```
61 changes: 41 additions & 20 deletions test/frontend-integration-test/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,39 @@ set -xe

# K8s Namespace that all resources deployed to
NAMESPACE=kubeflow
REMOTE_RUN=false

usage()
{
echo "usage: run_test.sh
--results-gcs-dir GCS directory for the test results. Usually gs://<project-id>/<commit-sha>/e2e_test
[--namespace k8s namespace where ml-pipelines is deployed. The tests run against the instance in this namespace]
[--remote-run host address of a remote KFP UI. Used for local tests only.]
[-h help]"
}

while [ "$1" != "" ]; do
function parse_bool {
local str="${1:-false}"
local pat='^(true|1|yes)$'
if [[ "$str" =~ $pat ]]
then
echo 'true'
else
echo 'false'
fi
}

while [[ "$1" != "" ]]; do
case $1 in
--results-gcs-dir )shift
RESULTS_GCS_DIR=$1
;;
--namespace ) shift
NAMESPACE=$1
;;
--remote-run ) shift
REMOTE_RUN=$(parse_bool "${1:-}")
;;
-h | --help ) usage
exit
;;
Expand All @@ -44,29 +60,32 @@ while [ "$1" != "" ]; do
shift
done

if [ -z "$RESULTS_GCS_DIR" ]; then
usage
exit 1
fi

if [[ ! -z "${GOOGLE_APPLICATION_CREDENTIALS}" ]]; then
gcloud auth activate-service-account --key-file="${GOOGLE_APPLICATION_CREDENTIALS}"
if [[ "$REMOTE_RUN" != "true" ]]; then
if [[ -z "$RESULTS_GCS_DIR" ]]; then
usage
exit 1
fi
if [[ ! -z "${GOOGLE_APPLICATION_CREDENTIALS}" ]]; then
gcloud auth activate-service-account --key-file="${GOOGLE_APPLICATION_CREDENTIALS}"
fi
fi

npm install

function clean_up() {
set +e
if [[ "$REMOTE_RUN" != "true" ]]; then
function clean_up() {
set +e

echo "Stopping background jobs..."
kill -15 %1
kill -15 %2
}
trap clean_up EXIT SIGINT SIGTERM
echo "Stopping background jobs..."
kill -15 %1
kill -15 %2
}
trap clean_up EXIT SIGINT SIGTERM

# Port forward the UI so tests can work against localhost
POD=`kubectl get pods -n ${NAMESPACE} -l app=ml-pipeline-ui -o jsonpath='{.items[0].metadata.name}'`
kubectl port-forward -n ${NAMESPACE} ${POD} 3000:3000 &
# Port forward the UI so tests can work against localhost
POD=`kubectl get pods -n ${NAMESPACE} -l app=ml-pipeline-ui -o jsonpath='{.items[0].metadata.name}'`
kubectl port-forward -n ${NAMESPACE} ${POD} 3000:3000 &
fi

# Run Selenium server
/opt/bin/entry_point.sh &
Expand All @@ -82,7 +101,9 @@ set -e

JUNIT_TEST_RESULT=junit_FrontendIntegrationTestOutput.xml

echo "Copy test result to GCS ${RESULTS_GCS_DIR}/${JUNIT_TEST_RESULT}"
gsutil cp ${JUNIT_TEST_RESULT} ${RESULTS_GCS_DIR}/${JUNIT_TEST_RESULT}
if [[ "$REMOTE_RUN" != "true" ]]; then
echo "Copy test result to GCS ${RESULTS_GCS_DIR}/${JUNIT_TEST_RESULT}"
gsutil cp ${JUNIT_TEST_RESULT} ${RESULTS_GCS_DIR}/${JUNIT_TEST_RESULT}
fi

exit $TEST_EXIT_CODE

0 comments on commit c79d35f

Please sign in to comment.