Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All tables are truncated when using tests in parallel. #38164

Closed
cduez opened this issue Jan 6, 2020 · 9 comments
Closed

All tables are truncated when using tests in parallel. #38164

cduez opened this issue Jan 6, 2020 · 9 comments
Labels

Comments

@cduez
Copy link

cduez commented Jan 6, 2020

I was wondering why rails was truncating all the tables only when the tests are executed in parallel using the :fork strategy and not with the :thread strategy?

I have noticed this after creating a new rails application with an already existing database: My first test was already taking seconds to run which didn't seem right. The test log showed that before the first test is executed, all the tables are truncated which take few seconds in my case.

When a fork is created rails calls the method:

def reconstruct_from_schema(db_config, format = ActiveRecord::Base.schema_format, file = nil) # :nodoc:
which truncates the tables if there is no change in the schema:

if schema_up_to_date?(db_config, format, file)
  truncate_tables(db_config)
else
  purge(db_config)
  load_schema(db_config, format, file)
end

Would it be acceptable to do nothing if the schema is up to date in order to save some time?

System configuration

Rails version: 6.0.2.1

Ruby version: 2.6.5

@rails-bot
Copy link

rails-bot bot commented Apr 5, 2020

This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails team are limited, and so we are asking for your help.
If you can still reproduce this error on the 6-0-stable branch or on master, please reply with all of the information you have about it in order to keep the issue open.
Thank you for all your contributions.

@rails-bot rails-bot bot added the stale label Apr 5, 2020
@rails-bot rails-bot bot closed this as completed Apr 12, 2020
@joegaudet
Copy link

I'm seeing the same issue, which wouldn't normally be a problem but it's nuking my PostGIS constants.

@brendon
Copy link
Contributor

brendon commented Apr 22, 2021

Yes this caught me too. I was seeding my test database and this just wiped it again before the tests ran.

@feliperaul
Copy link
Contributor

This caught me as well. How are we supposed to seed the test database when using parallel tests?

@joegaudet
Copy link

joegaudet commented Oct 25, 2021 via email

@malomalo
Copy link
Contributor

malomalo commented May 17, 2024

Anyone figure this out? Truncating all the tables in the database truncates spatial_ref_sys which breaks PostGIS. I don't see a way to ignore certain table either.

@malomalo
Copy link
Contributor

Ah for anyone else who runs into this PostGIS adapter has its own truncate_tables which hides the table from Rails. Currently no way to ignore certain tables for test, so best to monkey patch truncate_tables on your adapter

@cduez
Copy link
Author

cduez commented May 17, 2024

An environment variable was added which skips the table truncation and mitigates this issue, see #51686

@malomalo
Copy link
Contributor

@cduez that works if all the tables don't need truncating and getting all the devs to set the variable. But that seem more just like a CI solution.

A better solution would be a config setting. But for now patching the connection adapter ala Postgis Adapter works better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants