Maintenance: Slice RSpec tests for faster test turnaround times.

This commit is contained in:
Martin Gruner 2021-09-10 11:48:31 +02:00
parent 58028f7081
commit f32b184f7b
10 changed files with 115 additions and 24 deletions

View File

@ -38,6 +38,14 @@
variables:
APP_RESTART_CMD: "bundle exec rake environment zammad:ci:app:restart"
.variables_rspec_slicing: &variables_rspec_slicing
variables:
RSPEC_EXAMPLE_MATCHES: "." # Default: all. Set this to one of the slices in a job to run only that slice.
RSPEC_EXAMPLE_SLICE_1_OF_4: "^[A-H]"
RSPEC_EXAMPLE_SLICE_2_OF_4: "^[I-P]"
RSPEC_EXAMPLE_SLICE_3_OF_4: "^[Q-S]"
RSPEC_EXAMPLE_SLICE_4_OF_4: "^[^A-S]" # Rest, including lower case and other characters like '#'
.rules_singletest: &rules_singletest
rules:
- if: $CI_MERGE_REQUEST_ID

View File

@ -82,11 +82,13 @@ include:
extends:
- .env_base
- .variables_es
- .variables_rspec_slicing
variables:
RAILS_ENV: "test"
script:
- bundle exec rake zammad:ci:test:prepare
- bundle exec rspec --fail-fast -t type:system -t ~integration
- echo "RSpec filter:" "$RSPEC_EXAMPLE_MATCHES"
- bundle exec rspec --require ./spec/rspec_extensions.rb --example-matches "$RSPEC_EXAMPLE_MATCHES" --fail-fast -t ~integration --profile 10 spec/system
.template_browser-core_capybara_chrome: &template_browser-core_capybara_chrome
extends:

View File

@ -1,3 +1,23 @@
capybara_chrome:
capybara:chrome:1:
extends:
- .template_browser-core_capybara_chrome
variables:
RSPEC_EXAMPLE_MATCHES: $RSPEC_EXAMPLE_SLICE_1_OF_4
capybara:chrome:2:
extends:
- .template_browser-core_capybara_chrome
variables:
RSPEC_EXAMPLE_MATCHES: $RSPEC_EXAMPLE_SLICE_2_OF_4
capybara:chrome:3:
extends:
- .template_browser-core_capybara_chrome
variables:
RSPEC_EXAMPLE_MATCHES: $RSPEC_EXAMPLE_SLICE_3_OF_4
capybara:chrome:4:
extends:
- .template_browser-core_capybara_chrome
variables:
RSPEC_EXAMPLE_MATCHES: $RSPEC_EXAMPLE_SLICE_4_OF_4

View File

@ -1,3 +1,23 @@
capybara_ff:
capybara:firefox:1:
extends:
- .template_browser-core_capybara_firefox
variables:
RSPEC_EXAMPLE_MATCHES: $RSPEC_EXAMPLE_SLICE_1_OF_4
capybara:firefox:2:
extends:
- .template_browser-core_capybara_firefox
variables:
RSPEC_EXAMPLE_MATCHES: $RSPEC_EXAMPLE_SLICE_2_OF_4
capybara:firefox:3:
extends:
- .template_browser-core_capybara_firefox
variables:
RSPEC_EXAMPLE_MATCHES: $RSPEC_EXAMPLE_SLICE_3_OF_4
capybara:firefox:4:
extends:
- .template_browser-core_capybara_firefox
variables:
RSPEC_EXAMPLE_MATCHES: $RSPEC_EXAMPLE_SLICE_4_OF_4

View File

@ -18,7 +18,7 @@ include:
RAILS_ENV: "test"
script:
- bundle exec rake zammad:ci:test:prepare
- bundle exec rspec --fail-fast --pattern "spec/system/**/*_spec.rb" -t integration
- bundle exec rspec --fail-fast --pattern "spec/system/**/*_spec.rb" -t integration --profile 10
.template_browser-integration_capybara_chrome: &template_browser-integration_capybara_chrome
extends:

View File

@ -10,7 +10,7 @@
- bundle exec rake zammad:db:unseeded
- bundle exec rails test test/integration/elasticsearch_active_test.rb
- bundle exec rails test test/integration/elasticsearch_test.rb
- bundle exec rspec --tag searchindex --tag ~type:system
- bundle exec rspec --tag searchindex --tag ~type:system --profile 10
- bundle exec rails test test/integration/report_test.rb
es:7:

View File

@ -5,20 +5,11 @@ include:
.template_rspec: &template_rspec
extends:
- .env_base
variables:
RAILS_ENV: "test"
- .variables_rspec_slicing
script:
- bundle exec rake zammad:db:init
- bundle exec rspec --exclude-pattern "spec/{system,integration}/**/*_spec.rb" -t ~searchindex -t ~db_strategy:reset
.template_rspec_db_reset: &template_rspec_db_reset
extends:
- .env_base
variables:
RAILS_ENV: "test"
script:
- bundle exec rake zammad:db:init
- bundle exec rspec --exclude-pattern "spec/{system,integration}/**/*_spec.rb" -t ~searchindex -t db_strategy:reset
- echo "RSpec filter:" "$RSPEC_EXAMPLE_MATCHES"
- bundle exec rspec --require ./spec/rspec_extensions.rb --example-matches "$RSPEC_EXAMPLE_MATCHES" --exclude-pattern "spec/{system,integration}/**/*_spec.rb" -t ~searchindex --profile 10
# RSpec 3rd party integration tests are independent of the database
# therefore we need only one job and choose a random database for each run
@ -41,4 +32,4 @@ rspec:integration:
- when: always
script:
- bundle exec rake zammad:db:init
- bundle exec rspec -t type:integration
- bundle exec rspec -t type:integration --profile 10

View File

@ -1,11 +1,31 @@
rspec:mysql:
rspec:mysql:1:
stage: test
variables:
RSPEC_EXAMPLE_MATCHES: $RSPEC_EXAMPLE_SLICE_1_OF_4
extends:
- .services_mysql_redis_memcached
- .template_rspec
rspec:mysql:db_reset:
rspec:mysql:2:
stage: test
variables:
RSPEC_EXAMPLE_MATCHES: $RSPEC_EXAMPLE_SLICE_2_OF_4
extends:
- .services_mysql_redis_memcached
- .template_rspec_db_reset
- .template_rspec
rspec:mysql:3:
stage: test
variables:
RSPEC_EXAMPLE_MATCHES: $RSPEC_EXAMPLE_SLICE_3_OF_4
extends:
- .services_mysql_redis_memcached
- .template_rspec
rspec:mysql:4:
stage: test
variables:
RSPEC_EXAMPLE_MATCHES: $RSPEC_EXAMPLE_SLICE_4_OF_4
extends:
- .services_mysql_redis_memcached
- .template_rspec

View File

@ -1,11 +1,31 @@
rspec:postgresql:
rspec:postgresql:1:
stage: test
variables:
RSPEC_EXAMPLE_MATCHES: $RSPEC_EXAMPLE_SLICE_1_OF_4
extends:
- .services_postgresql_redis_memcached
- .template_rspec
rspec:postgresql:db_reset:
rspec:postgresql:2:
stage: test
variables:
RSPEC_EXAMPLE_MATCHES: $RSPEC_EXAMPLE_SLICE_2_OF_4
extends:
- .services_postgresql_redis_memcached
- .template_rspec_db_reset
- .template_rspec
rspec:postgresql:3:
stage: test
variables:
RSPEC_EXAMPLE_MATCHES: $RSPEC_EXAMPLE_SLICE_3_OF_4
extends:
- .services_postgresql_redis_memcached
- .template_rspec
rspec:postgresql:4:
stage: test
variables:
RSPEC_EXAMPLE_MATCHES: $RSPEC_EXAMPLE_SLICE_4_OF_4
extends:
- .services_postgresql_redis_memcached
- .template_rspec

10
spec/rspec_extensions.rb Normal file
View File

@ -0,0 +1,10 @@
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
# Small patch for rspec: don't treat --example-matches/-E as a standalone
# filter that suppresses other exclusion filters, but combine all filters instead.
require 'rspec/core/filter_manager'
class RSpec::Core::InclusionRules
def standalone?
false
end
end