Commit 2d1eacec authored by Bogdan Denkovych's avatar Bogdan Denkovych

Do not `eager_load` by default in the test environment

Usually, developers run a single test locally.
Disabling eager loading by default in test environment should increase
productivity since it saves around 10 seconds:

With `eager_load` as `true`:
```bash
bogdanvlviv@lenovo:~/gitlab-development-kit/gitlab$ bin/rspec spec/models/users_statistics_spec.rb
Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}

Test environment set up in 5.122837013 seconds
......

Finished in 8.51 seconds (files took 16.46 seconds to load)
6 examples, 0 failures
```

With `eager_load` as `false`:
```bash
bogdanvlviv@lenovo:~/gitlab-development-kit/gitlab$ bin/rspec spec/models/users_statistics_spec.rb
Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}

Test environment set up in 5.013345478 seconds
......

Finished in 8.24 seconds (files took 7.18 seconds to load)
6 examples, 0 failures
```

Inspired by https://github.com/rails/rails/pull/43508.

It is important to eager load app before deploying it to catch any
issues with constants loading.
I see that we disable eager_loading on CI, https://gitlab.com/gitlab-org/gitlab/-/merge_requests/30368/diffs#c1e8bf49d38a49639de4f3b2f3cef9ebdbe50dd4_16_26
For mentioned reason above I thik we should enable eager loading on CI.
@rymai What do you think about that?

I also found that we 'Speed up backend tests in Gitpod environment',
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/68482.
/cc @splattael

Remove `GITLAB_TEST_EAGER_LOAD: "0"` for scripts/setup-test-env
It doesn't make any difference for this script.
See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/72964#note_713013642

Document `GITLAB_TEST_EAGER_LOAD`.
Closes https://gitlab.com/gitlab-org/gitlab/-/issues/343751
parent a2d053e6
...@@ -168,7 +168,6 @@ setup-test-env: ...@@ -168,7 +168,6 @@ setup-test-env:
- .rails:rules:code-backstage-qa - .rails:rules:code-backstage-qa
stage: prepare stage: prepare
variables: variables:
GITLAB_TEST_EAGER_LOAD: "0"
SETUP_DB: "false" SETUP_DB: "false"
script: script:
- run_timed_command "scripts/setup-test-env" - run_timed_command "scripts/setup-test-env"
......
...@@ -69,15 +69,13 @@ tasks: ...@@ -69,15 +69,13 @@ tasks:
printf "Waiting for GitLab at $(gp url 3000) ..." printf "Waiting for GitLab at $(gp url 3000) ..."
# Check /-/readiness which returns JSON, but we're only interested in the exit code # 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 # 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 "" 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 ... # Give Gitpod a few more seconds to set up everything ...
sleep 5 sleep 5
printf "$(date) – GitLab is up (took ~%.1f minutes)\n" "$((10*$SECONDS/60))e-1" | tee -a /workspace/startup.log 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 gp preview $(gp url 3000) || true
# Speed up backend tests
export GITLAB_TEST_EAGER_LOAD=false
) )
ports: ports:
......
...@@ -49,7 +49,7 @@ Rails.application.configure do ...@@ -49,7 +49,7 @@ Rails.application.configure do
# Print deprecation notices to the stderr # Print deprecation notices to the stderr
config.active_support.deprecation = :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 config.cache_store = :null_store
......
...@@ -50,6 +50,20 @@ bundle exec guard ...@@ -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. 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 ### Ruby warnings
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/47767) in GitLab 13.7. > [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/47767) in GitLab 13.7.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment