Skip to content

Commit

Permalink
add a controller delay in test env to fix test erros in docker enviro…
Browse files Browse the repository at this point in the history
…nments
  • Loading branch information
amtuannguyen committed Mar 31, 2024
1 parent 77ea8ba commit 30ff27b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
11 changes: 3 additions & 8 deletions .github/workflows/rubyonrails.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
RAILS_ENV: test
DATABASE_URL: sqlite3:db/test.sqlite3
SELENIUM_SERVER: 127.0.0.1
TEST_CONTROLLERS_DELAY: 0.1
run: |
bundle exec rake db:reset
bundle exec rake test
Expand All @@ -51,14 +52,8 @@ jobs:
RAILS_ENV: test
DATABASE_URL: mysql2://test:[email protected]:3306/test
SELENIUM_SERVER: 127.0.0.1
TEST_CONTROLLERS_DELAY: 0.1
run: |
bundle exec rake db:reset
bundle exec rake test TEST=test/models
bundle exec rake test TEST=test/mailers
# skip controllers for now due to random errors when running these tests with mysql
#bundle exec rake test TEST=test/controllers
bundle exec rake test
bundle exec rake test:system
12 changes: 12 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class ApplicationController < ActionController::Base
check_authorization

before_action :login_required
after_action :_after_action

def current_user
@current_user ||= User.find_by_id(session[:user_id]) if session[:user_id]
Expand All @@ -21,4 +22,15 @@ def login_required
rescue_from CanCan::AccessDenied do |exception|
redirect_to unauthorized_url, alert: exception.message.to_s
end

private

def _after_action
if Rails.env.test?
test_controllers_delay = ENV['TEST_CONTROLLERS_DELAY']
if !test_controllers_delay.nil?
sleep test_controllers_delay.to_f
end
end
end
end
2 changes: 1 addition & 1 deletion test/system/theses_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ThesesTest < ApplicationSystemTestCase
test 'Assign a thesis to ME and unassign this' do
visit root_url
click_on('Unassigned')
click_on('Me')
click_on('Me (')
click_on("I'm working on it")
# click_on('Unassign This Thesis')
# refute_selector 'a', text: 'Unassign This Thesis'
Expand Down

0 comments on commit 30ff27b

Please sign in to comment.