Skip to content

Commit

Permalink
Fix flaky tests and drop database_cleaner
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
manno committed Dec 18, 2021
1 parent b629eb2 commit 522a7ea
Show file tree
Hide file tree
Showing 14 changed files with 12 additions and 37 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
RAILS_ENV: test

strategy:
fail-fast: false
matrix:
ruby_version:
- 2.7
Expand Down
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 0 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -511,7 +507,6 @@ DEPENDENCIES
cocoon
coffee-rails
dalli
database_cleaner-active_record
devise
dotenv-rails
exception_notification
Expand Down
2 changes: 2 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -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).
#
Expand Down
7 changes: 0 additions & 7 deletions test/application_system_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/factories/event.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 3 additions & 4 deletions test/integration/static_schedule_export_test.rb
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
1 change: 0 additions & 1 deletion test/integration/view_event_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/models/static_program_export_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
5 changes: 2 additions & 3 deletions test/system/editing_event_people_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand Down
8 changes: 1 addition & 7 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions test/unit/i18n_failingtest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
require 'i18n/tasks'

class I18nTest < ActiveSupport::TestCase
self.use_transactional_tests = false

setup do
@i18n = I18n::Tasks::BaseTask.new
end
Expand Down
2 changes: 0 additions & 2 deletions test/unit/mail_template_test.rb
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
2 changes: 0 additions & 2 deletions test/unit/static_program_export_job_test.rb
Original file line number Diff line number Diff line change
@@ -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: '/')
Expand Down

0 comments on commit 522a7ea

Please sign in to comment.