0

I have a Rails 4 app with simple specs. When I run a spec, it takes 26 seconds. If I look at the log, I can see this :

   (38.5ms)  ALTER TABLE "schema_migrations" DISABLE TRIGGER ALL;ALTER TABLE .............# tons of tables
   (10.3ms)            SELECT schemaname || '.' || tablename
          FROM pg_tables
          WHERE
            tablename !~ '_prt_' AND
            tablename <> 'schema_migrations' AND
            schemaname = ANY (current_schemas(false))

   (2.3ms)  select table_name from information_schema.views where table_schema = 'lap-test'
   (10708.2ms)  TRUNCATE TABLE "public"."bounded_facets_service_boutiques", "public"."versions", ..... # Tons of tables
   (10823.0ms)  TRUNCATE TABLE "public"."bounded_facets_service_boutiques", "public"."versions", .... #Tons of tables
   (26.2ms)  ALTER TABLE "schema_migrations" ENABLE TRIGGER ALL;ALTER TABLE "bounded_facets_service_boutiques" ENABLE TRIGGER ALL;ALTER TABLE "versions" .... #Tons of tables
   (0.6ms)  BEGIN
   (0.3ms)  COMMIT
   (0.2ms)  BEGIN
   (0.2ms)  SAVEPOINT active_record_1
   (0.2ms)  RELEASE SAVEPOINT active_record_1
   (0.2ms)  SAVEPOINT active_record_1
   (0.5ms)  SAVEPOINT active_record_2
  Administrator Exists (1.9ms)  SELECT  1 AS one FROM "administrators" WHERE "administrators"."email" = 'person1@labandprocess.com' LIMIT 1
  SQL (2.3ms)  INSERT INTO "administrators" .....
   (0.6ms)  RELEASE SAVEPOINT active_record_2
   (0.4ms)  ROLLBACK TO SAVEPOINT active_record_1
   (0.6ms)  ROLLBACK

As you can see, The truncation takes 10 seconds 2 times.

I use database cleaner with this :

RSpec.configure do |config|
  config.include Devise::TestHelpers, type: :controller

  config.before(:suite) do
    DatabaseCleaner.strategy = :transaction
    DatabaseCleaner.clean_with(:truncation)
  end

  config.around(:each) do |example|
    DatabaseCleaner.cleaning do
      example.run
    end
  end
end

I tested with other strategies without result.

There is a lot of seeds in development mod but it's on another database. There is 107 models in this project.

Is there a solution ?

Dougui
  • 7,142
  • 7
  • 52
  • 87

0 Answers0