turbo_tests icon indicating copy to clipboard operation
turbo_tests copied to clipboard

Unable to run tests on GitHub CI

Open nrgbistro opened this issue 2 years ago • 3 comments

I'm trying to run turbo_tests on my Ruby project, which requires a postgresql database running, one for each parallel tester. It seems that running bin/rails parallel:create does not properly set the TEST_ENV_NUMBER environment variable in GitHub CI, as the output from the command is:

Database 'test_database' already exists
Database 'test_database' already exists

When I run locally, I get test_database1 and test_database2. I've made sure to set PARALLEL_TEST_FIRST_IS_1=true, but even without that the second database name should be test_database2. Could someone help me run this test suite on in a GitHub action workflow? I would prefer not to use a matrix.

nrgbistro avatar Aug 22 '24 16:08 nrgbistro

@nrgbistro did you ever figure this out?

TheRoyalTnetennba avatar Sep 03 '24 23:09 TheRoyalTnetennba

No I haven't, I'm currently sticking with rspec for my CI. This would be nice to have but isn't a priority for me now. Let me know if you figure it out.

nrgbistro avatar Sep 04 '24 00:09 nrgbistro

@nrgbistro have you tried using bin/rake parallel:setup instead? From what I recall the "setup" commands handle the case where if they exist they drop and recreate them but "create" won't do that I believe.

javierjulio avatar Oct 10 '24 23:10 javierjulio

I just tried using parallel:setup but get the same issues:

Database 'rails_test' already exists
Database 'rails_test' already exists
psql:/home/runner/.../db/structure.sql:16: ERROR:  duplicate key value violates unique constraint "pg_extension_name_index"
DETAIL:  Key (extname)=(pg_stat_statements) already exists.
rake aborted!

It doesn't seem to ever increment the database number on CI. Any ideas on how to debug that specific behavior?

nrgbistro avatar Nov 20 '24 20:11 nrgbistro

After significant headache, I've settled on a more manual approach to this:

- name: Set up databases
        run: |
          for i in $(seq 1 2); do
            TEST_ENV_NUMBER=$i DISABLE_SPRING=1 bin/rake db:create db:schema:load
          done

This works as expected when running bundle exec turbo_tests -n 2. I'm not 100% sure if DISABLE_SPRING is necessary but I think it fixed a bug where the environment variable was being cached.

nrgbistro avatar Nov 20 '24 21:11 nrgbistro

@nrgbistro sorry, it's hard to help without more info about your setup. I did want to suggest one thing based on your last comment though to confirm. Did you end up trying PARALLEL_TEST_FIRST_IS_1=true bin/rake parallel:setup instead? That should work both locally and in CI.

For example, in one project, this is what I use to prep and run turbo_tests in CI:

DEVISE_SECRET_KEY=sample PARALLEL_TEST_FIRST_IS_1=true bin/rake parallel:setup
bin/turbo_tests

You did update your config/database.yml file so the test database name includes <%= ENV['TEST_ENV_NUMBER'] %> right? Not sure what else I can suggest without more info.

I'd advise against using spring nowadays. I removed it shortly after adding turbo_tests, for what its worth. Although the primary reason for that was when upgrading Rails due to Zeitwerk.

javierjulio avatar Nov 20 '24 22:11 javierjulio

You should be able to do this parallel:create[2] PARALLEL_TEST_FIRST_IS_1=true and it'll create test_database1 and test_database2

davidwparker avatar May 23 '25 03:05 davidwparker

Thank you everyone, sorry I've been busy on other projects since I opened this issue.

Using parallel:create[2] PARALLEL_TEST_FIRST_IS_1=true does indeed seem to work without issue and creates both databases. Now facing unrelated WAL issues in my CI, but will close this as the turbo test piece seems to work well now!

nrgbistro avatar Jun 11 '25 15:06 nrgbistro