Skip to content

Commit

Permalink
remove docker_processes from core rspec and selenium test runs
Browse files Browse the repository at this point in the history
refs DE-467

it is no longer possible to spin up multiple docker containers
ona  single rspec or selenium agent when running tests. parallelization
is now exclusively done through multple rspec processes on
a single container.

test plan:
- setting docker_processes ENV variable has no effect
- settting rspec_processes still runs multiple test threads
- tests continue to run as expected given that docker_processes has
been set to 1 for multiple months.

Change-Id: I604d953a71ad220373b6a71d558f46bff29f820e
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/263701
Tested-by: Service Cloud Jenkins <[email protected]>
Reviewed-by: James Butters <[email protected]>
QA-Review: James Butters <[email protected]>
Product-Review: James Butters <[email protected]>
  • Loading branch information
Kyle Rosenbaum authored and jbutte committed May 12, 2021
1 parent 51e5ca0 commit 347f73b
Show file tree
Hide file tree
Showing 16 changed files with 23 additions and 59 deletions.
1 change: 0 additions & 1 deletion Jenkinsfile.contract-tests
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ pipeline {
environment {
BUILD_REGISTRY_FQDN = configuration.buildRegistryFQDN()
COMPOSE_FILE = 'docker-compose.new-jenkins.yml:docker-compose.new-jenkins-contract-tests.yml'
DOCKER_PROCESSES = '1'
POSTGRES_PASSWORD = 'sekret'
PACT_BROKER = credentials('PACT_BROKER')
PACT_BROKER_USERNAME="${env.PACT_BROKER_USR}"
Expand Down
3 changes: 1 addition & 2 deletions Jenkinsfile.selenium.flakey_spec_catcher
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def computeTestCount() {
}

sh """
docker-compose --project-name canvas-lms0 run --rm -v \$(pwd)/\$LOCAL_WORKDIR/tmp:\$DOCKER_WORKDIR/tmp \
docker-compose run --rm -v \$(pwd)/\$LOCAL_WORKDIR/tmp:\$DOCKER_WORKDIR/tmp \
canvas \
bash -c "bundle exec rspec --dry-run ${changed_tests_arr.join(' ')} --require ./build/new-jenkins/rspec_location.rb --format RSpecLocationFormatter --out ${env.DOCKER_WORKDIR}/tmp/test_list_split"
"""
Expand Down Expand Up @@ -204,7 +204,6 @@ pipeline {
// repeats each test FSC_REPEAT_FACTOR times.
// Assumption: non-selenium tests take 500ms / test
// Assumption: selenium tests take 500ms * SELENIUM_RATIO / test
DOCKER_PROCESSES = 1
FSC_REPEAT_FACTOR = 10
MAX_NODES = configuration.getString('fsc-max-nodes', '10')
RSPEC_PROCESSES = 3
Expand Down
11 changes: 3 additions & 8 deletions build/new-jenkins/docker-compose-build-up.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
#!/bin/bash

set -o errexit -o errtrace -o nounset -o pipefail -o xtrace
# ':' is a bash "no-op" and then we pass an empty argument which isn't used
parallel --will-cite ::: :

PROCESSES=$((${DOCKER_PROCESSES:=1}-1))

docker-compose build

seq 0 $PROCESSES | parallel "docker-compose --project-name canvas-lms{} up -d"
docker-compose up -d

for service in cassandra:9160 dynamodb:8000 redis:6379; do
seq 0 $PROCESSES | parallel "docker-compose --project-name canvas-lms{} exec -T canvas ./build/new-jenkins/wait-for-it ${service}"
docker-compose exec -T canvas ./build/new-jenkins/wait-for-it ${service}
done

seq 0 $PROCESSES | parallel "docker-compose --project-name canvas-lms{} exec -T postgres /bin/bash -c /wait-for-it"
docker-compose exec -T postgres /bin/bash -c /wait-for-it
7 changes: 0 additions & 7 deletions build/new-jenkins/docker-compose-rspec-parallel.sh

This file was deleted.

14 changes: 0 additions & 14 deletions build/new-jenkins/docker-compose-setup-cassandra-keyspaces.sh

This file was deleted.

18 changes: 7 additions & 11 deletions build/new-jenkins/docker-compose-setup-databases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,21 @@ set -o errexit -o errtrace -o nounset -o pipefail -o xtrace
# ':' is a bash "no-op" and then we pass an empty argument which isn't used
parallel --will-cite ::: :

PROCESSES=$((${DOCKER_PROCESSES:=1}-1))
DATABASE_PROCESSES=$((${RSPEC_PROCESSES:=1}-1))

create_cmd=""
for keyspace in auditors global_lookups page_views; do
create_cmd+="CREATE KEYSPACE IF NOT EXISTS ${keyspace} WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };"
done

seq 0 $PROCESSES | parallel "docker-compose --project-name canvas-lms{} exec -T cassandra cqlsh -e \"${create_cmd[@]}\""
docker-compose exec -T cassandra cqlsh -e "${create_cmd[@]}"

seq 0 $PROCESSES | parallel "docker-compose --project-name canvas-lms{} exec -T canvas bin/rails db:migrate >> ./migrate-{}.log"
seq 0 $PROCESSES | parallel "docker-compose --project-name canvas-lms{} exec -T canvas bin/rails runner \"require 'switchman/test_helper'; Switchman::TestHelper.recreate_persistent_test_shards\""
docker-compose exec -T canvas bin/rails db:migrate >> ./migrate.log
docker-compose exec -T canvas bin/rails runner "require 'switchman/test_helper'; Switchman::TestHelper.recreate_persistent_test_shards"

for i in $(seq 0 $PROCESSES); do
for keyspace in auditors global_lookups page_views; do
seq 0 $DATABASE_PROCESSES | parallel "docker-compose --project-name canvas-lms${i} exec -T cassandra bash -c 'cqlsh -e \"DESCRIBE KEYSPACE ${keyspace}\" | sed \"s/CREATE KEYSPACE ${keyspace}/CREATE KEYSPACE ${keyspace}{}/g ; s/CREATE TABLE ${keyspace}/CREATE TABLE ${keyspace}{}/g\" > ${keyspace}{} && cqlsh -f \"${keyspace}{}\"'"
done
for keyspace in auditors global_lookups page_views; do
seq 0 $DATABASE_PROCESSES | parallel "docker-compose exec -T cassandra bash -c 'cqlsh -e \"DESCRIBE KEYSPACE ${keyspace}\" | sed \"s/CREATE KEYSPACE ${keyspace}/CREATE KEYSPACE ${keyspace}{}/g ; s/CREATE TABLE ${keyspace}/CREATE TABLE ${keyspace}{}/g\" > ${keyspace}{} && cqlsh -f \"${keyspace}{}\"'"
done

for i in $(seq 0 $PROCESSES); do
seq 0 $DATABASE_PROCESSES | parallel "docker-compose --project-name canvas-lms${i} exec -T postgres sh -c 'createdb -U postgres -T canvas_test canvas_test_{}'"
done
seq 0 $DATABASE_PROCESSES | parallel "docker-compose exec -T postgres sh -c 'createdb -U postgres -T canvas_test canvas_test_{}'"

6 changes: 1 addition & 5 deletions build/new-jenkins/library/vars/rspec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def runSeleniumSuite(total, index) {
config.reruns_retry,
'^./(spec|gems/plugins/.*/spec_canvas)/selenium',
'.*/performance',
'1',
'3',
config.force_failure,
config.patchsetTag
Expand Down Expand Up @@ -65,7 +64,6 @@ def runRSpecSuite(total, index) {
config.reruns_retry,
'^./(spec|gems/plugins/.*/spec_canvas)/',
'.*/(selenium|contracts)',
'1',
'4',
config.force_failure,
config.patchsetTag
Expand All @@ -81,7 +79,6 @@ def _runRspecTestSuite(
rerunsRetry,
testFilePattern,
excludeRegex,
dockerProcesses,
rspecProcesses,
forceFailure,
patchsetTag
Expand All @@ -94,7 +91,6 @@ def _runRspecTestSuite(
"TEST_PATTERN=$testFilePattern",
"EXCLUDE_TESTS=$excludeRegex",
"CI_NODE_TOTAL=$total",
"DOCKER_PROCESSES=$dockerProcesses",
"RSPEC_PROCESSES=$rspecProcesses",
"FORCE_FAILURE=$forceFailure",
'POSTGRES_PASSWORD=sekret',
Expand All @@ -109,7 +105,7 @@ def _runRspecTestSuite(
sh(script: 'build/new-jenkins/docker-compose-pull.sh', label: 'Pull Images')
}
sh(script: 'build/new-jenkins/docker-compose-build-up.sh', label: 'Start Containers')
sh(script: 'build/new-jenkins/docker-compose-rspec-parallel.sh', label: 'Run Tests')
sh(script: 'docker-compose exec -T -e RSPEC_PROCESSES -e ENABLE_AXE_SELENIUM canvas bash -c \'build/new-jenkins/rspec-with-retries.sh\'', label: 'Run Tests')
}
} catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e) {
if (e.causes[0] instanceof org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution.ExceededTimeout) {
Expand Down
2 changes: 1 addition & 1 deletion build/new-jenkins/rspec-flakey-spec-catcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

set -o errexit -o errtrace -o nounset -o pipefail -o xtrace

docker-compose --project-name "canvas-lms0" exec -T -e RSPEC_PROCESSES=$RSPEC_PROCESSES -e FORCE_FAILURE=$FORCE_FAILURE -e FSC_REPEAT_FACTOR=$FSC_REPEAT_FACTOR -e FSC_TESTS=$FSC_TESTS canvas bash -c 'build/new-jenkins/rspec-flakey-spec-catcher-parallel.sh'
docker-compose exec -T -e RSPEC_PROCESSES=$RSPEC_PROCESSES -e FORCE_FAILURE=$FORCE_FAILURE -e FSC_REPEAT_FACTOR=$FSC_REPEAT_FACTOR -e FSC_TESTS=$FSC_TESTS canvas bash -c 'build/new-jenkins/rspec-flakey-spec-catcher-parallel.sh'
2 changes: 1 addition & 1 deletion build/new-jenkins/rspec-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ parallel_index=$1
only_failures=${2-}

# calculate which group to run
max=$((CI_NODE_TOTAL * (DOCKER_PROCESSES * RSPEC_PROCESSES)))
max=$((CI_NODE_TOTAL * RSPEC_PROCESSES))
group=$(((max-CI_NODE_TOTAL * $parallel_index) - CI_NODE_INDEX))
maybeOnlyFailures=()
if [ "${only_failures}" = 'only-failures' ] && [ ! "${RSPEC_LOG:-}" == "1" ]; then
Expand Down
4 changes: 2 additions & 2 deletions build/new-jenkins/rspec-with-retries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ while true; do

if [[ $reruns_started ]]; then
if [ $1 ] && [ $1 = 'performance' ]; then
commands+=("docker-compose --project-name canvas-lms0 exec -T canvas bundle exec rspec --options spec/spec.opts spec/selenium/performance/ --only-failures --failure-exit-code 99")
commands+=("docker-compose exec -T canvas bundle exec rspec --options spec/spec.opts spec/selenium/performance/ --only-failures --failure-exit-code 99")
fi
else
if [ $1 ] && [ $1 = 'performance' ]; then
commands+=("docker-compose --project-name canvas-lms0 exec -T canvas bundle exec rspec --options spec/spec.opts spec/selenium/performance/ --failure-exit-code 99")
commands+=("docker-compose exec -T canvas bundle exec rspec --options spec/spec.opts spec/selenium/performance/ --failure-exit-code 99")
else
for i in $(seq 0 $PROCESSES); do
commands+=("build/new-jenkins/rspec-tests.sh $i")
Expand Down
2 changes: 1 addition & 1 deletion build/new-jenkins/test-engines.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

set -x -o errexit -o errtrace -o nounset -o pipefail

docker-compose --project-name canvas-lms0 exec -T canvas ./engines/test_all_engines.sh
docker-compose exec -T canvas ./engines/test_all_engines.sh
2 changes: 1 addition & 1 deletion build/new-jenkins/test-gems.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

set -x -o errexit -o errtrace -o nounset -o pipefail

docker-compose --project-name canvas-lms0 exec -T canvas ./gems/test_all_gems.sh
docker-compose exec -T canvas ./gems/test_all_gems.sh
2 changes: 1 addition & 1 deletion build/new-jenkins/xbrowser-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

set -x -o errexit -o errtrace -o nounset -o pipefail

docker-compose --project-name canvas-lms0 exec -T canvas bundle exec rspec --options spec/spec.opts --tag xbrowser spec/selenium/
docker-compose exec -T canvas bundle exec rspec --options spec/spec.opts --tag xbrowser spec/selenium/
2 changes: 1 addition & 1 deletion docker-compose.new-jenkins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ services:
# parallel_tests
CI_NODE_TOTAL:
CI_NODE_INDEX:
DOCKER_PROCESSES:
RSPEC_PROCESSES:
EXCLUDE_TESTS:
TEST_PATTERN:
# rspec-parallel-log build
Expand Down
2 changes: 1 addition & 1 deletion spec/coverage_tool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def self.start(command_name)
# no formatting by default, just get the json
SimpleCov.at_exit {
# generate an HTML report if this is running locally / not on jenkins:
SimpleCov.result.format! unless ENV['DOCKER_PROCESSES']
SimpleCov.result.format! unless ENV['RSPEC_PROCESSES']
SimpleCov.result
}
end
Expand Down
4 changes: 2 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ def assert_require_login
config.include PGCollkeyHelper
config.project_source_dirs << "gems" # so that failures here are reported properly

# DOCKER_PROCESSES is only used on Jenkins and we only care to have RspecJunitFormatter on Jenkins.
if ENV['DOCKER_PROCESSES']
# RSPEC_PROCESSES is only used on Jenkins and we only care to have RspecJunitFormatter on Jenkins.
if ENV['RSPEC_PROCESSES']
file = "log/results/results-#{ENV.fetch('PARALLEL_INDEX', '0').to_i}.xml"
# if file already exists this is a rerun of a failed spec, don't generate new xml.
config.add_formatter "RspecJunitFormatter", file unless File.file?(file)
Expand Down

0 comments on commit 347f73b

Please sign in to comment.