Skip to content

ci: Make TestEnv not depend on Rails nor a DB connection (take 2)

Take 2 of !61145 (merged).

What does this MR do?

Control job

7 seconds

Preparing the "docker+machine" executor
Using Docker executor with image registry.gitlab.com/gitlab-org/gitlab-build-images:ruby-2.7.2.patched-golang-1.14-git-2.31-lfs-2.9-chrome-89-node-14.15-yarn-1.22-postgresql-12-graphicsmagick-1.3.36 ...
Starting service postgres:12 ...
Pulling docker image postgres:12 ...
Using docker image sha256:e782ad565d74bbe4dc50b2e76612e386c6cfbf3dcb32720b2b4c2fdec71bd822 for postgres:12 with digest postgres@sha256:06277995d7028f4455e56f21864146ee2425c83308dc96283c7a96e6881cc826 ...
Starting service redis:5.0-alpine ...
Pulling docker image redis:5.0-alpine ...
Using docker image sha256:618083532dc7c70fde98a8bb5b20e663d5046b3032824d8d2ab8e487ce2369cf for redis:5.0-alpine with digest redis@sha256:01cbc10aa79db974c374820566a46bbdf89c8378a05c795040e2bf9ef02a880e ...
Waiting for services to be up and running...
Authenticating with credentials from job payload (GitLab Registry)
Pulling docker image registry.gitlab.com/gitlab-org/gitlab-build-images:ruby-2.7.2.patched-golang-1.14-git-2.31-lfs-2.9-chrome-89-node-14.15-yarn-1.22-postgresql-12-graphicsmagick-1.3.36 ...
Using docker image sha256:5427fd94dbf6ac018804070018547f6d744519aeb670f43df73f168d1fd11192 for registry.gitlab.com/gitlab-org/gitlab-build-images:ruby-2.7.2.patched-golang-1.14-git-2.31-lfs-2.9-chrome-89-node-14.15-yarn-1.22-postgresql-12-graphicsmagick-1.3.36 with digest registry.gitlab.com/gitlab-org/gitlab-build-images@sha256:db1858ab2c8b8fc1c1801c264355338fc6a342aca82c0367104267a59f30152c ...

25 seconds

$ setup_db_user_only
CREATE ROLE
GRANT
==> 'setup_db_user_only' succeeded in 0 seconds.
$ bundle exec rake db:drop db:create db:structure:load db:migrate gitlab:db:setup_ee
Dropped database 'gitlabhq_test'
Created database 'gitlabhq_test'
Dropped database 'gitlabhq_geo_test'
Created database 'gitlabhq_geo_test'
==> 'bundle exec rake db:drop db:create db:structure:load db:migrate gitlab:db:setup_ee' succeeded in 25 seconds.

92 seconds

$ run_timed_command "bundle exec ruby -I. -e 'require \"config/environment\"; TestEnv.init'"
$ bundle exec ruby -I. -e 'require "config/environment"; TestEnv.init'
==> Setting up Gitaly...
 Warning 
  You are running as user root, we hope you know what you are doing.
  Things may work/fail for the wrong reasons.
  For correct results you should run this as user git.
    Gitaly set up in 11.722514348 seconds...
==> Setting up GitLab Workhorse...
    GitLab Workhorse set up in 38.727959213 seconds...
==> Setting up gitlab-test repository in /builds/gitlab-org/gitlab/tmp/tests/gitlab-test...
    /builds/gitlab-org/gitlab/tmp/tests/gitlab-test set up in 1.160882047 seconds...
==> Setting up gitlab-test bare repository in /builds/gitlab-org/gitlab/tmp/tests/gitlab-test_bare...
    /builds/gitlab-org/gitlab/tmp/tests/gitlab-test_bare set up in 0.018316986 seconds...
==> Setting up gitlab-test-fork repository in /builds/gitlab-org/gitlab/tmp/tests/gitlab-test-fork...
    /builds/gitlab-org/gitlab/tmp/tests/gitlab-test-fork set up in 0.537366234 seconds...
==> Setting up gitlab-test-fork bare repository in /builds/gitlab-org/gitlab/tmp/tests/gitlab-test-fork_bare...
    /builds/gitlab-org/gitlab/tmp/tests/gitlab-test-fork_bare set up in 0.016710016 seconds...
==> Setting up GitLab Elasticsearch Indexer...
    GitLab Elasticsearch Indexer set up in 29.597748479 seconds...
==> 'bundle exec ruby -I. -e 'require "config/environment"; TestEnv.init'' succeeded in 92 seconds.

112 seconds

$ run_timed_command "scripts/gitaly-test-build"
$ scripts/gitaly-test-build
...
The Gemfile's dependencies are satisfied
Trying to connect to gitaly: ...... OK
Trying to connect to gitaly2: ............... OK
Trying to connect to praefect: ...... OK
==> 'scripts/gitaly-test-build' succeeded in 112 seconds.

Improved job

3 seconds (-4 seconds)

Using Docker executor with image registry.gitlab.com/gitlab-org/gitlab-build-images:ruby-2.7.2.patched-golang-1.14-git-2.31-lfs-2.9-chrome-89-node-14.15-yarn-1.22-postgresql-11-graphicsmagick-1.3.36 ...
Authenticating with credentials from job payload (GitLab Registry)
Pulling docker image registry.gitlab.com/gitlab-org/gitlab-build-images:ruby-2.7.2.patched-golang-1.14-git-2.31-lfs-2.9-chrome-89-node-14.15-yarn-1.22-postgresql-11-graphicsmagick-1.3.36 ...
Using docker image sha256:9b06bf3dd0ab8d484e8c9e9c611f75eab098939f568d587a7fd23a3c96eceb87 for registry.gitlab.com/gitlab-org/gitlab-build-images:ruby-2.7.2.patched-golang-1.14-git-2.31-lfs-2.9-chrome-89-node-14.15-yarn-1.22-postgresql-11-graphicsmagick-1.3.36 with digest registry.gitlab.com/gitlab-org/gitlab-build-images@sha256:eb4fdeb3196481dd022d7d166468834e40a046b46a29e3349fb3bf3657176290 ...

No setup_db_user_only (-25 seconds)

72 seconds (-20 seconds)

$ run_timed_command "scripts/setup-test-env"
$ scripts/setup-test-env
 Warning 
  You are running as user root, we hope you know what you are doing.
  Things may work/fail for the wrong reasons.
  For correct results you should run this as user git.
==> Gitaly set up in 7.602206887 seconds...
==> /builds/gitlab-org/gitlab/tmp/tests/gitlab-test set up in 1.310897097 seconds...
==> /builds/gitlab-org/gitlab/tmp/tests/gitlab-test_bare set up in 0.032068611 seconds...
==> /builds/gitlab-org/gitlab/tmp/tests/gitlab-test-fork set up in 0.526055063 seconds...
==> /builds/gitlab-org/gitlab/tmp/tests/gitlab-test-fork_bare set up in 0.01137741 seconds...
==> GitLab Elasticsearch Indexer set up in 49.831956437 seconds...
==> GitLab Workhorse set up in 67.6907328 seconds...
Test environment set up in 69.560884227 seconds
==> 'scripts/setup-test-env' succeeded in 72 seconds.

117 seconds (+5 seconds, most probably unrelated)

$ run_timed_command "scripts/gitaly-test-build"
$ scripts/gitaly-test-build
...
The Gemfile's dependencies are satisfied
Trying to connect to gitaly: ........ OK
Trying to connect to gitaly2: ............... OK
Trying to connect to praefect: ....... OK
==> 'scripts/gitaly-test-build' succeeded in 117 seconds.

Total savings per job: 44 seconds

  • setup-test-env jobs per day: around 600

Total savings per day: 26,400 seconds = 7.3 hours

Ensuring we don't break local development workflow

› bin/rake lint:static_verification
WARNING: This version of GitLab depends on gitlab-shell 13.19.0, but you're running 13.18.0. Please update gitlab-shell.
/Users/remy/Code/GitLab/gdk/gitlab/lib/gitlab/json.rb:9: warning: already initialized constant Gitlab::Json::INVALID_LEGACY_TYPES
/Users/remy/Code/GitLab/gdk/gitlab/lib/gitlab/json.rb:9: warning: previous definition of INVALID_LEGACY_TYPES was here
/Users/remy/Code/GitLab/gdk/gitlab/lib/gitlab/json.rb:208: warning: already initialized constant Gitlab::Json::PrecompiledJson::UnsupportedFormatError
/Users/remy/Code/GitLab/gdk/gitlab/lib/gitlab/json.rb:208: warning: previous definition of UnsupportedFormatError was here
/Users/remy/Code/GitLab/gdk/gitlab/lib/gitlab/json.rb:234: warning: already initialized constant Gitlab::Json::LimitedEncoder::LimitExceeded
/Users/remy/Code/GitLab/gdk/gitlab/lib/gitlab/json.rb:234: warning: previous definition of LimitExceeded was here

› bin/rake gitlab:gitaly:install                   
WARNING: This version of GitLab depends on gitlab-shell 13.19.0, but you're running 13.18.0. Please update gitlab-shell.
Please specify the directory where you want to install gitaly and the path for the default storage
Usage: rake "gitlab:gitaly:install[/installation/dir,/storage/path]"

Without tmp/tests/gitaly already set up

› bin/rspec './spec/db/schema_spec.rb[1:1:140:1:1]'
Running via Spring preloader in process 51241
WARNING: `around(:context)` hooks are not supported and behave like `around(:example). Called from /Users/remy/Code/GitLab/gdk/gitlab/spec/support/omniauth_strategy.rb:36:in `block in <main>'.
Run options: include {:focus=>true, :ids=>{"./spec/db/schema_spec.rb"=>["1:1:140:1:1"]}}
==> Gitaly set up in 107.819346 seconds...

Test environment set up in 112.206128 seconds
.

Finished in 1 minute 55.09 seconds (files took 5.4 seconds to load)
1 example, 0 failures

With tmp/tests/gitaly already set up

› bin/rspec './spec/db/schema_spec.rb[1:1:140:1:1]'
Running via Spring preloader in process 55507
WARNING: `around(:context)` hooks are not supported and behave like `around(:example). Called from /Users/remy/Code/GitLab/gdk/gitlab/spec/support/omniauth_strategy.rb:36:in `block in <main>'.
Run options: include {:focus=>true, :ids=>{"./spec/db/schema_spec.rb"=>["1:1:140:1:1"]}}

Test environment set up in 3.914732 seconds
.

Finished in 6.63 seconds (files took 5.34 seconds to load)
1 example, 0 failures

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Related to #118623 (closed).

Edited by Rémy Coutable

Merge request reports

Loading