diff --git a/.gitlab/ci/rails.gitlab-ci.yml b/.gitlab/ci/rails.gitlab-ci.yml index b85a0f6c1e893478437db1f0a189c7655fd28daa..983cebd2b434dd1f6335bfb77cee2731a2219073 100644 --- a/.gitlab/ci/rails.gitlab-ci.yml +++ b/.gitlab/ci/rails.gitlab-ci.yml @@ -168,7 +168,6 @@ setup-test-env: - .rails:rules:code-backstage-qa stage: prepare variables: - GITLAB_TEST_EAGER_LOAD: "0" SETUP_DB: "false" script: - run_timed_command "scripts/setup-test-env" diff --git a/.gitpod.yml b/.gitpod.yml index d546cc7f64ad0034657eb5fe00962613b9aacb1a..c9adad3e3fe43f1e5cafef4fc9c2868953986428 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -69,15 +69,13 @@ tasks: printf "Waiting for GitLab at $(gp url 3000) ..." # Check /-/readiness which returns JSON, but we're only interested in the exit code # - # We use http://localhost:3000 instead of the public hostname because + # We use http://localhost:3000 instead of the public hostname because # it's no longer possible to access as specific cookies are required until curl --silent --no-buffer --fail http://localhost:3000/-/readiness > /dev/null 2>&1; do printf '.'; sleep 5; done && echo "" # Give Gitpod a few more seconds to set up everything ... sleep 5 printf "$(date) – GitLab is up (took ~%.1f minutes)\n" "$((10*$SECONDS/60))e-1" | tee -a /workspace/startup.log gp preview $(gp url 3000) || true - # Speed up backend tests - export GITLAB_TEST_EAGER_LOAD=false ) ports: diff --git a/config/environments/test.rb b/config/environments/test.rb index 9fa8a1b762c7bea2465f1e625b52489e381962b1..07e0c729d8ccc45f69f24ed8d6830b5c7b3534f5 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -49,7 +49,7 @@ Rails.application.configure do # Print deprecation notices to the stderr config.active_support.deprecation = :stderr - config.eager_load = Gitlab::Utils.to_boolean(ENV['GITLAB_TEST_EAGER_LOAD'], default: true) + config.eager_load = Gitlab::Utils.to_boolean(ENV['GITLAB_TEST_EAGER_LOAD'], default: ENV['CI'].present?) config.cache_store = :null_store diff --git a/doc/development/testing_guide/best_practices.md b/doc/development/testing_guide/best_practices.md index 52e89a10556e28cb4a1da63929cdfe045fbd463f..2acb79041b6c81af7b015e767e2f86ecc75a3304 100644 --- a/doc/development/testing_guide/best_practices.md +++ b/doc/development/testing_guide/best_practices.md @@ -50,6 +50,20 @@ bundle exec guard When using spring and guard together, use `SPRING=1 bundle exec guard` instead to make use of spring. +### Eager loading the application code + +By default, the application code: + +- Isn't eagerly loaded in the `test` environment. +- Is eagerly loaded in CI/CD (when `ENV['CI'].present?`) to surface any potential loading issues. + +If you need to enable eager loading when executing tests, +use the `GITLAB_TEST_EAGER_LOAD` environment variable: + +```shell +GITLAB_TEST_EAGER_LOAD=1 bin/rspec spec/models/project_spec.rb +``` + ### Ruby warnings > [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/47767) in GitLab 13.7.