-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tests] create gantry_jobs.spec.sh, improve setup time of tests.
Try to reduce the conflict of ports.
- Loading branch information
Showing
9 changed files
with
373 additions
and
328 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,245 @@ | ||
#!/bin/bash spellspec | ||
# Copyright (C) 2024 Shizun Ge | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
# | ||
|
||
Describe 'update-jobs' | ||
SUITE_NAME="update-jobs" | ||
BeforeAll "initialize_all_tests ${SUITE_NAME}" | ||
AfterAll "finish_all_tests ${SUITE_NAME}" | ||
Describe "test_update_jobs_skipping" "container_test:true" "coverage:true" | ||
# For `docker service ls --filter`, the name filter matches on all or the prefix of a service's name | ||
# See https://docs.docker.com/engine/reference/commandline/service_ls/#name | ||
# It does not do the exact match of the name. See https://github.com/moby/moby/issues/32985 | ||
# This test also checks whether we do an extra step to to perform the exact match. | ||
TEST_NAME="test_update_jobs_skipping" | ||
IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") | ||
SERVICE_NAME="gantry-test-$(unique_id)" | ||
SERVICE_NAME_SUFFIX="${SERVICE_NAME}-suffix" | ||
test_start() { | ||
local TEST_NAME="${1}" | ||
local IMAGE_WITH_TAG="${2}" | ||
local SERVICE_NAME="${3}" | ||
local SERVICE_NAME_SUFFIX="${SERVICE_NAME}-suffix" | ||
common_setup_job "${TEST_NAME}" "${IMAGE_WITH_TAG}" "${SERVICE_NAME_SUFFIX}" | ||
start_replicated_service "${SERVICE_NAME}" "${IMAGE_WITH_TAG}" | ||
} | ||
test_update_jobs_skipping() { | ||
local TEST_NAME="${1}" | ||
local SERVICE_NAME="${2}" | ||
reset_gantry_env "${SERVICE_NAME}" | ||
run_gantry "${TEST_NAME}" | ||
} | ||
test_end() { | ||
local TEST_NAME="${1}" | ||
local IMAGE_WITH_TAG="${2}" | ||
local SERVICE_NAME="${3}" | ||
local SERVICE_NAME_SUFFIX="${SERVICE_NAME}-suffix" | ||
stop_service "${SERVICE_NAME}" | ||
common_cleanup "${TEST_NAME}" "${IMAGE_WITH_TAG}" "${SERVICE_NAME_SUFFIX}" | ||
} | ||
BeforeEach "test_start ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" | ||
AfterEach "test_end ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" | ||
It 'run_test' | ||
When run test_update_jobs_skipping "${TEST_NAME}" "${SERVICE_NAME}" | ||
The status should be success | ||
The stdout should satisfy display_output | ||
The stdout should satisfy spec_expect_no_message ".+" | ||
The stderr should satisfy display_output | ||
The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" | ||
# Check whether it is a job before checking whether there is a new image. | ||
The stderr should satisfy spec_expect_message "${SKIP_UPDATING}.*${SERVICE_NAME_SUFFIX}.*${SKIP_REASON_IS_JOB}" | ||
The stderr should satisfy spec_expect_no_message "${PERFORM_UPDATING}.*${SERVICE_NAME_SUFFIX}" | ||
The stderr should satisfy spec_expect_message "${SKIP_UPDATING}.*${SERVICE_NAME}.*${SKIP_REASON_CURRENT_IS_LATEST}" | ||
The stderr should satisfy spec_expect_no_message "${PERFORM_UPDATING}.*${SERVICE_NAME}" | ||
The stderr should satisfy spec_expect_no_message "${SET_TIMEOUT_TO}" | ||
The stderr should satisfy spec_expect_message "${NUM_SERVICES_SKIP_JOBS}" | ||
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_INSPECT_FAILURE}" | ||
The stderr should satisfy spec_expect_message "${NUM_SERVICES_NO_NEW_IMAGES}" | ||
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_UPDATING}" | ||
The stderr should satisfy spec_expect_no_message "${UPDATED}.*${SERVICE_NAME}" | ||
The stderr should satisfy spec_expect_no_message "${NO_UPDATES}.*${SERVICE_NAME}" | ||
The stderr should satisfy spec_expect_no_message "${ROLLING_BACK}.*${SERVICE_NAME}" | ||
The stderr should satisfy spec_expect_no_message "${FAILED_TO_ROLLBACK}.*${SERVICE_NAME}" | ||
The stderr should satisfy spec_expect_no_message "${ROLLED_BACK}.*${SERVICE_NAME}" | ||
The stderr should satisfy spec_expect_message "${NO_SERVICES_UPDATED}" | ||
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_UPDATED}" | ||
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_UPDATE_FAILED}" | ||
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_ERRORS}" | ||
The stderr should satisfy spec_expect_message "${NO_IMAGES_TO_REMOVE}" | ||
The stderr should satisfy spec_expect_no_message "${REMOVING_NUM_IMAGES}" | ||
The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" | ||
The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" | ||
The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" | ||
End | ||
End | ||
Describe "test_update_jobs_UPDATE_JOBS_true" "container_test:true" "coverage:true" | ||
TEST_NAME="test_update_jobs_UPDATE_JOBS_true" | ||
IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") | ||
SERVICE_NAME="gantry-test-$(unique_id)" | ||
test_update_jobs_UPDATE_JOBS_true() { | ||
local TEST_NAME="${1}" | ||
local SERVICE_NAME="${2}" | ||
reset_gantry_env "${SERVICE_NAME}" | ||
export GANTRY_UPDATE_JOBS="true" | ||
# The job may not reach the desired "Complete" state and blocking update CLI. So add "--detach=true" | ||
export GANTRY_UPDATE_OPTIONS="--detach=true" | ||
run_gantry "${TEST_NAME}" | ||
} | ||
BeforeEach "common_setup_job ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" | ||
AfterEach "common_cleanup ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" | ||
It 'run_test' | ||
When run test_update_jobs_UPDATE_JOBS_true "${TEST_NAME}" "${SERVICE_NAME}" | ||
The status should be success | ||
The stdout should satisfy display_output | ||
The stdout should satisfy spec_expect_no_message ".+" | ||
The stderr should satisfy display_output | ||
The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" | ||
The stderr should satisfy spec_expect_no_message "${SKIP_UPDATING}.*${SERVICE_NAME}" | ||
The stderr should satisfy spec_expect_message "${PERFORM_UPDATING}.*${SERVICE_NAME}.*${PERFORM_REASON_HAS_NEWER_IMAGE}" | ||
The stderr should satisfy spec_expect_no_message "${SET_TIMEOUT_TO}" | ||
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_SKIP_JOBS}" | ||
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_INSPECT_FAILURE}" | ||
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_NO_NEW_IMAGES}" | ||
The stderr should satisfy spec_expect_message "${NUM_SERVICES_UPDATING}" | ||
The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--detach=true.*${SERVICE_NAME}" | ||
The stderr should satisfy spec_expect_message "${UPDATED}.*${SERVICE_NAME}" | ||
The stderr should satisfy spec_expect_no_message "${NO_UPDATES}.*${SERVICE_NAME}" | ||
The stderr should satisfy spec_expect_no_message "${ROLLING_BACK}.*${SERVICE_NAME}" | ||
The stderr should satisfy spec_expect_no_message "${FAILED_TO_ROLLBACK}.*${SERVICE_NAME}" | ||
The stderr should satisfy spec_expect_no_message "${ROLLED_BACK}.*${SERVICE_NAME}" | ||
The stderr should satisfy spec_expect_no_message "${NO_SERVICES_UPDATED}" | ||
The stderr should satisfy spec_expect_message "1 ${SERVICES_UPDATED}" | ||
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_UPDATE_FAILED}" | ||
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_ERRORS}" | ||
The stderr should satisfy spec_expect_no_message "${NO_IMAGES_TO_REMOVE}" | ||
The stderr should satisfy spec_expect_message "${REMOVING_NUM_IMAGES}" | ||
The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" | ||
# Since the job may not reach the desired state, they are still using the image. Image remover will fail. | ||
The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" | ||
The stderr should satisfy spec_expect_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" | ||
End | ||
End | ||
Describe "test_update_jobs_label_UPDATE_JOBS_true" "container_test:true" "coverage:true" | ||
TEST_NAME="test_update_jobs_label_UPDATE_JOBS_true" | ||
IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") | ||
SERVICE_NAME="gantry-test-$(unique_id)" | ||
test_update_jobs_label_UPDATE_JOBS_true() { | ||
local TEST_NAME="${1}" | ||
local SERVICE_NAME="${2}" | ||
reset_gantry_env "${SERVICE_NAME}" | ||
# label should override the global environment variable. | ||
export GANTRY_UPDATE_JOBS="false" | ||
local LABEL_AND_VALUE="gantry.update.jobs=true" | ||
docker_service_update --detach=true --label-add "${LABEL_AND_VALUE}" "${SERVICE_NAME}" | ||
# label should override the global environment variable. | ||
export GANTRY_UPDATE_OPTIONS="--incorrect-option" | ||
# The job may not reach the desired "Complete" state and blocking update CLI. So add "--detach=true" | ||
LABEL_AND_VALUE="gantry.update.options=--detach=true" | ||
docker_service_update --detach=true --label-add "${LABEL_AND_VALUE}" "${SERVICE_NAME}" | ||
run_gantry "${TEST_NAME}" | ||
} | ||
BeforeEach "common_setup_job ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" | ||
AfterEach "common_cleanup ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" | ||
It 'run_test' | ||
When run test_update_jobs_label_UPDATE_JOBS_true "${TEST_NAME}" "${SERVICE_NAME}" | ||
The status should be success | ||
The stdout should satisfy display_output | ||
The stdout should satisfy spec_expect_no_message ".+" | ||
The stderr should satisfy display_output | ||
The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" | ||
The stderr should satisfy spec_expect_no_message "${SKIP_UPDATING}.*${SERVICE_NAME}" | ||
The stderr should satisfy spec_expect_message "${PERFORM_UPDATING}.*${SERVICE_NAME}.*${PERFORM_REASON_HAS_NEWER_IMAGE}" | ||
The stderr should satisfy spec_expect_no_message "${SET_TIMEOUT_TO}" | ||
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_SKIP_JOBS}" | ||
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_INSPECT_FAILURE}" | ||
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_NO_NEW_IMAGES}" | ||
The stderr should satisfy spec_expect_message "${NUM_SERVICES_UPDATING}" | ||
The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--detach=true.*${SERVICE_NAME}" | ||
The stderr should satisfy spec_expect_message "${UPDATED}.*${SERVICE_NAME}" | ||
The stderr should satisfy spec_expect_no_message "${NO_UPDATES}.*${SERVICE_NAME}" | ||
The stderr should satisfy spec_expect_no_message "${ROLLING_BACK}.*${SERVICE_NAME}" | ||
The stderr should satisfy spec_expect_no_message "${FAILED_TO_ROLLBACK}.*${SERVICE_NAME}" | ||
The stderr should satisfy spec_expect_no_message "${ROLLED_BACK}.*${SERVICE_NAME}" | ||
The stderr should satisfy spec_expect_no_message "${NO_SERVICES_UPDATED}" | ||
The stderr should satisfy spec_expect_message "1 ${SERVICES_UPDATED}" | ||
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_UPDATE_FAILED}" | ||
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_ERRORS}" | ||
The stderr should satisfy spec_expect_no_message "${NO_IMAGES_TO_REMOVE}" | ||
The stderr should satisfy spec_expect_message "${REMOVING_NUM_IMAGES}" | ||
The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" | ||
# Since the job may not reach the desired state, they are still using the image. Image remover will fail. | ||
The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" | ||
The stderr should satisfy spec_expect_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" | ||
End | ||
End | ||
Describe "test_update_jobs_no_running_tasks" "container_test:true" "coverage:true" | ||
TEST_NAME="test_update_jobs_no_running_tasks" | ||
IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") | ||
SERVICE_NAME="gantry-test-$(unique_id)" | ||
TASK_SECONDS=1 | ||
test_start() { | ||
local TEST_NAME="${1}" | ||
local IMAGE_WITH_TAG="${2}" | ||
local SERVICE_NAME="${3}" | ||
local TASK_SECONDS="${4}" | ||
common_setup_job "${TEST_NAME}" "${IMAGE_WITH_TAG}" "${SERVICE_NAME}" "${TASK_SECONDS}" | ||
# The tasks should exit after TASK_SECONDS seconds sleep. Then it will have 0 running tasks. | ||
wait_zero_running_tasks "${SERVICE_NAME}" | ||
} | ||
test_update_jobs_no_running_tasks() { | ||
local TEST_NAME="${1}" | ||
local SERVICE_NAME="${2}" | ||
reset_gantry_env "${SERVICE_NAME}" | ||
export GANTRY_UPDATE_JOBS="true" | ||
run_gantry "${TEST_NAME}" | ||
} | ||
# The task will finish in ${TASK_SECONDS} seconds | ||
BeforeEach "test_start ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME} ${TASK_SECONDS}" | ||
AfterEach "common_cleanup ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" | ||
It 'run_test' | ||
When run test_update_jobs_no_running_tasks "${TEST_NAME}" "${SERVICE_NAME}" | ||
The status should be success | ||
The stdout should satisfy display_output | ||
The stdout should satisfy spec_expect_no_message ".+" | ||
The stderr should satisfy display_output | ||
The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" | ||
The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--detach=true.*${SERVICE_NAME}" | ||
# Cannot add "--replicas" to replicated job | ||
The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--replicas=0" | ||
The stderr should satisfy spec_expect_no_message "${SKIP_UPDATING}.*${SERVICE_NAME}" | ||
The stderr should satisfy spec_expect_message "${PERFORM_UPDATING}.*${SERVICE_NAME}.*${PERFORM_REASON_HAS_NEWER_IMAGE}" | ||
The stderr should satisfy spec_expect_no_message "${SET_TIMEOUT_TO}" | ||
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_SKIP_JOBS}" | ||
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_INSPECT_FAILURE}" | ||
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_NO_NEW_IMAGES}" | ||
The stderr should satisfy spec_expect_message "${NUM_SERVICES_UPDATING}" | ||
The stderr should satisfy spec_expect_message "${UPDATED}.*${SERVICE_NAME}" | ||
The stderr should satisfy spec_expect_no_message "${NO_UPDATES}.*${SERVICE_NAME}" | ||
The stderr should satisfy spec_expect_no_message "${ROLLING_BACK}.*${SERVICE_NAME}" | ||
The stderr should satisfy spec_expect_no_message "${FAILED_TO_ROLLBACK}.*${SERVICE_NAME}" | ||
The stderr should satisfy spec_expect_no_message "${ROLLED_BACK}.*${SERVICE_NAME}" | ||
The stderr should satisfy spec_expect_no_message "${NO_SERVICES_UPDATED}" | ||
The stderr should satisfy spec_expect_message "1 ${SERVICES_UPDATED}" | ||
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_UPDATE_FAILED}" | ||
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_ERRORS}" | ||
The stderr should satisfy spec_expect_no_message "${NO_IMAGES_TO_REMOVE}" | ||
The stderr should satisfy spec_expect_message "${REMOVING_NUM_IMAGES}" | ||
The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}" | ||
The stderr should satisfy spec_expect_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}" | ||
The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}" | ||
End | ||
End | ||
End # Describe 'update-jobs' |
Oops, something went wrong.