From 522a7ea2bd4d962ff441c3f795fc4e9d0a8731c3 Mon Sep 17 00:00:00 2001 From: Mario Manno Date: Sun, 5 Dec 2021 14:05:39 +0100 Subject: [PATCH] Fix flaky tests and drop database_cleaner * this drops database_cleaner, the default transactional tests work fine * don't fail-fast the github actions matrix, so we now if it's a database related failure * frab test event title doesn't contain database id, multiply by 3 to avoid flakes in filter tests * editing_event_people_test waits for hidden field to change * turn on parallelized tests, one can set PARALLEL_WORKERS for more workers --- .github/workflows/ci.yaml | 1 + Gemfile | 1 - Gemfile.lock | 5 ----- db/seeds.rb | 2 ++ test/application_system_test_case.rb | 7 ------- test/factories/event.rb | 2 +- test/integration/static_schedule_export_test.rb | 7 +++---- test/integration/view_event_test.rb | 1 - test/models/static_program_export_test.rb | 4 ++-- test/system/editing_event_people_test.rb | 5 ++--- test/test_helper.rb | 8 +------- test/unit/i18n_failingtest.rb | 2 -- test/unit/mail_template_test.rb | 2 -- test/unit/static_program_export_job_test.rb | 2 -- 14 files changed, 12 insertions(+), 37 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b976c6e62..72b8bd6e2 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -13,6 +13,7 @@ jobs: RAILS_ENV: test strategy: + fail-fast: false matrix: ruby_version: - 2.7 diff --git a/Gemfile b/Gemfile index 2666452f8..a8d2895b3 100644 --- a/Gemfile +++ b/Gemfile @@ -106,7 +106,6 @@ end group :test do gem 'rexml' gem 'factory_bot_rails' - gem 'database_cleaner-active_record' gem 'rails-controller-testing' gem 'capybara', '>= 3.26' diff --git a/Gemfile.lock b/Gemfile.lock index bfe647c61..0a08a427e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -149,10 +149,6 @@ GEM concurrent-ruby (1.1.9) crass (1.0.6) dalli (3.0.2) - database_cleaner-active_record (2.0.1) - activerecord (>= 5.a) - database_cleaner-core (~> 2.0.0) - database_cleaner-core (2.0.1) devise (4.8.0) bcrypt (~> 3.0) orm_adapter (~> 0.1) @@ -511,7 +507,6 @@ DEPENDENCIES cocoon coffee-rails dalli - database_cleaner-active_record devise dotenv-rails exception_notification diff --git a/db/seeds.rb b/db/seeds.rb index a4f614beb..9d6aeb07f 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,3 +1,5 @@ +exit if Rails.env.test? + # This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). # diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index 43997733e..000b66d00 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -4,14 +4,7 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase include CapybaraHelper driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400] - DatabaseCleaner.strategy = :truncation - def setup - DatabaseCleaner.start I18n.locale = I18n.default_locale end - - def teardown - DatabaseCleaner.clean - end end diff --git a/test/factories/event.rb b/test/factories/event.rb index 249ff9ae4..74b176ffb 100644 --- a/test/factories/event.rb +++ b/test/factories/event.rb @@ -1,6 +1,6 @@ FactoryBot.define do sequence :event_title do |n| - "Introducing frap part #{n}" + "Introducing frap part #{3 * n}" end factory :event do diff --git a/test/integration/static_schedule_export_test.rb b/test/integration/static_schedule_export_test.rb index 5cb3b57d6..a2ba77c52 100644 --- a/test/integration/static_schedule_export_test.rb +++ b/test/integration/static_schedule_export_test.rb @@ -1,10 +1,11 @@ require 'test_helper' +require 'tmpdir' class StaticScheduleExportTest < ActionDispatch::IntegrationTest setup do @conference = create(:three_day_conference_with_events_and_speakers, program_export_base_url: '/') - @target_dir = Rails.root.join('tmp', 'static_export') + @target_dir = Dir.mktmpdir('frab_static_export') @dir = Pathname.new(@target_dir).join(@conference.acronym) end @@ -44,8 +45,6 @@ class StaticScheduleExportTest < ActionDispatch::IntegrationTest end teardown do - unless @dir.nil? - FileUtils.remove_dir(@dir) if File.exist?(@dir) - end + FileUtils.remove_entry_secure @target_dir if @target_dir end end diff --git a/test/integration/view_event_test.rb b/test/integration/view_event_test.rb index 3d1d325a2..92510cab8 100644 --- a/test/integration/view_event_test.rb +++ b/test/integration/view_event_test.rb @@ -44,7 +44,6 @@ class ViewEventTest < ActionDispatch::IntegrationTest assert_includes @response.body, 'proposal' # proposal appears as a table header, not a link assert_select 'a', {text: 'proposal', count: 0} - end test 'reports no results for missing terms' do diff --git a/test/models/static_program_export_test.rb b/test/models/static_program_export_test.rb index 25eaa14d5..922737869 100644 --- a/test/models/static_program_export_test.rb +++ b/test/models/static_program_export_test.rb @@ -5,7 +5,7 @@ class StaticSchedule::ExportText < ActiveSupport::TestCase @conference = create(:three_day_conference_with_events, program_export_base_url: '/') @locale = 'en' - @target_dir = File.join(Rails.root, 'tmp', 'static_export') + @target_dir = Dir.mktmpdir('frab_static_export') end test 'static exporter can create a tarball' do @@ -21,6 +21,6 @@ class StaticSchedule::ExportText < ActiveSupport::TestCase end teardown do - FileUtils.remove_dir File.join(@target_dir, @conference.acronym) + FileUtils.remove_entry_secure @target_dir if @target_dir end end diff --git a/test/system/editing_event_people_test.rb b/test/system/editing_event_people_test.rb index e2feab6a4..f1bbfe91f 100644 --- a/test/system/editing_event_people_test.rb +++ b/test/system/editing_event_people_test.rb @@ -20,9 +20,8 @@ class EditingEventsPeopleTest < ApplicationSystemTestCase fill_in 'filter', with: @user.person.email select 'Speaker' - Capybara.using_wait_time(10) do - assert_content page, @user.person.public_name - end + assert_content page, @user.person.public_name + page.has_field?("span#person_id input", with: "1") click_on 'Update event' assert_content page, 'Event was successfully updated.' diff --git a/test/test_helper.rb b/test/test_helper.rb index b27687f8d..4e9d33139 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -4,7 +4,6 @@ require 'minitest/pride' require 'minitest/spec' -require 'database_cleaner/active_record' require 'sucker_punch/testing/inline' Dir[Rails.root.join('test/support/**/*.rb')].each { |f| require f } @@ -13,21 +12,16 @@ class ActiveSupport::TestCase ActiveRecord::Migration.check_pending! include FactoryBot::Syntax::Methods + parallelize # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. # fixtures :all # Add more helper methods to be used by all tests here... - DatabaseCleaner.strategy = :truncation def setup - DatabaseCleaner.start I18n.locale = I18n.default_locale end - - def teardown - DatabaseCleaner.clean - end end # Controller tests in test/controllers diff --git a/test/unit/i18n_failingtest.rb b/test/unit/i18n_failingtest.rb index 0f7110100..819c0d415 100644 --- a/test/unit/i18n_failingtest.rb +++ b/test/unit/i18n_failingtest.rb @@ -2,8 +2,6 @@ require 'i18n/tasks' class I18nTest < ActiveSupport::TestCase - self.use_transactional_tests = false - setup do @i18n = I18n::Tasks::BaseTask.new end diff --git a/test/unit/mail_template_test.rb b/test/unit/mail_template_test.rb index e9957a2af..5de330565 100644 --- a/test/unit/mail_template_test.rb +++ b/test/unit/mail_template_test.rb @@ -1,8 +1,6 @@ require 'test_helper' class MailTemplateTest < ActiveSupport::TestCase - self.use_transactional_tests = false - setup do ActionMailer::Base.deliveries = [] @event = create(:event, state: 'confirmed') diff --git a/test/unit/static_program_export_job_test.rb b/test/unit/static_program_export_job_test.rb index f9852cf64..8f2a1f04b 100644 --- a/test/unit/static_program_export_job_test.rb +++ b/test/unit/static_program_export_job_test.rb @@ -1,8 +1,6 @@ require 'test_helper' class StaticProgramExportJobTest < ActiveSupport::TestCase - self.use_transactional_tests = false - setup do @conference = create(:three_day_conference_with_events_and_speakers, program_export_base_url: '/')