Skip to content

Fix persistence and timing problems with tests #197

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ end
group :test do
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
gem "capybara"
gem "database_cleaner-active_record"
gem "rails-controller-testing"
gem "selenium-webdriver"
gem "shoulda-matchers"
Expand Down
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ GEM
connection_pool (2.5.3)
crass (1.0.6)
csv (3.3.5)
database_cleaner-active_record (2.2.1)
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
database_cleaner-core (2.0.1)
date (3.4.1)
debug (1.10.0)
irb (~> 1.10)
Expand Down Expand Up @@ -501,6 +505,7 @@ DEPENDENCIES
bullet
capybara
csv
database_cleaner-active_record
debug
dotenv-rails
factory_bot_rails
Expand Down
23 changes: 23 additions & 0 deletions spec/support/database_cleaner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
RSpec.configure do |config|
require "database_cleaner/active_record"

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

config.before(:each) do
DatabaseCleaner.strategy = :transaction
end

config.before(:each, type: :system) do
DatabaseCleaner.strategy = :truncation
end

config.before(:each) do
DatabaseCleaner.start
end

config.after(:each) do
DatabaseCleaner.clean
end
end
4 changes: 3 additions & 1 deletion spec/system/user_search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
context "when sorting" do
it "displays users in the selected order" do
select "By least recently added", from: "search_order"
expect(page).to have_text(/#{admin.email}.+#{martin.email}.+#{rosemary.email}/m)
Capybara.using_wait_time(7) do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there something that can take 7 seconds to load search results when we have only several users in the DB?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmitrytrager does this happen to you locally, or is this something you saw in the CI? I added the config.profile_examples = true to RSpec.configure do |config| (rails_helper.rb) and I got decent times. Here my report:

Top 10 slowest examples (14.5 seconds, 31.5% of total time):
  User Login with correct email and password contributor logs in the user
    2.83 seconds ./spec/system/login_spec.rb:13
  Creating a Topic there is a create topic button as an Admin when successful creates a Topic
    1.8 seconds ./spec/system/topic_creation_spec.rb:18
  Creating a Topic there is a create topic button as a contributor when successful creates a Topic
    1.74 seconds ./spec/system/topic_creation_spec.rb:45
  Upload Management when updating a topic  when adding a document does not replace pre-existing documents
    1.23 seconds ./spec/system/upload_management_spec.rb:43
  User search when searching by role only displays users matching the search
    1.22 seconds ./spec/system/user_search_spec.rb:28
  Upload Management when updating a topic  when removing a document removes the document
    1.18 seconds ./spec/system/upload_management_spec.rb:85
  Upload Management when updating a topic  when adding a document when the user does not confirm the addition of files does not add the document
    1.16 seconds ./spec/system/upload_management_spec.rb:56
  Upload Management when updating a topic  when removing a document when the user does not confirm the deletion does not remove the document
    1.15 seconds ./spec/system/upload_management_spec.rb:96
  Creating a Tag as an Admin creates a tag
    1.11 seconds ./spec/system/tag_creation_spec.rb:12
  Upload Management when creating a new topic deletes added documents
    1.08 seconds ./spec/system/upload_management_spec.rb:20

Top 10 slowest example groups:
  Creating a Topic
    1.37 seconds average (5.47 seconds / 4 examples) ./spec/system/topic_creation_spec.rb:3
  Upload Management
    1.12 seconds average (7.86 seconds / 7 examples) ./spec/system/upload_management_spec.rb:3
  Creating a Tag
    1.11 seconds average (1.11 seconds / 1 example) ./spec/system/tag_creation_spec.rb:3
  Updating a Tag
    1.08 seconds average (1.08 seconds / 1 example) ./spec/system/tag_update_spec.rb:3
  Deleting a Tag
    1.06 seconds average (1.06 seconds / 1 example) ./spec/system/tag_delete_spec.rb:3
  User Login
    0.91743 seconds average (4.59 seconds / 5 examples) ./spec/system/login_spec.rb:3
  User search
    0.80926 seconds average (3.24 seconds / 4 examples) ./spec/system/user_search_spec.rb:3
  Topics search
    0.61706 seconds average (14.19 seconds / 23 examples) ./spec/system/topic_search_spec.rb:3
  Creating a Topic
    0.33265 seconds average (0.33265 seconds / 1 example) ./spec/features/topics/create_spec.rb:3
  Creating a Language
    0.32262 seconds average (0.32262 seconds / 1 example) ./spec/features/languages/create_spec.rb:3

Finished in 46.06 seconds (files took 1.11 seconds to load)
257 examples, 0 failures

Copy link
Collaborator

@hernanvicente hernanvicente Jun 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dcollie2 This problem also happened to me, but something broke my test database. In the meantime, I just deleted my test DB and restored it, and I changed my database.yml to:

test:
  primary:
    <<: *default
    database: skillrx_test
  queue:
    <<: *default
    database: skillrx_test_queue

Since then, I haven't had this problem. Meanwhile, @dmitrytrager is trying to determine the problem in the #199

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to close this one.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hernanvicente actually, I did not even try)
But now, since we closed the other one PR, I will switch to tests problem

expect(page).to have_text(/#{admin.email}.+#{martin.email}.+#{rosemary.email}/m)
end
end
end
end