Skip to content

Optionally run rspec tests with Gitaly Praefect using real database

Toon Claes requested to merge toon-praefect-db-in-test into master

What does this MR do and why?

At the moment tests use Praefect with the in-memory election strategy. This strategy is deprecated, and we at Gitaly like to get rid of it. But it's still used in testing.

This MR introduces the first to move toward an in-database election strategy. The user can optionally use it when setting GITALY_PRAEFECT_WITH_DB=1 in the environment. There's also a job added to CI to run tests like this, but for now it's only triggered manually and allowed to fail.

Part of #336749 (closed)

How to set up and validate locally

  1. You need to make sure PostgreSQL is running:

    gdk start db
  2. You need to load the DB environment from GDK:

    cd ../gitaly && eval $(gdk env) && cd -
  3. Create the database:

    createdb --encoding=UTF8 --locale=C --echo praefect_test
  4. By default Praefect isn't used in GDK, so enable that in config/gitlab.yml:

    diff --git a/config/gitlab.yml b/config/gitlab.yml
    index 5d6b720b..115606f4 100644
    --- a/config/gitlab.yml
    +++ b/config/gitlab.yml
    @@ -1065,7 +1065,7 @@ test:
         storages:
           default:
             path: tmp/tests/repositories/
    -        gitaly_address: unix:tmp/tests/gitaly/gitaly.socket
    +        gitaly_address: unix:tmp/tests/gitaly/praefect.socket
    
       gitaly:
         token: secret
  5. Run a test that fails when using in-db election:

    GITALY_PRAEFECT_WITH_DB=1 be rspec spec/requests/api/commits_spec.rb

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Toon Claes

Merge request reports

Loading