Commit 7511d1c4 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Fix failing specs when on Puma

We need to clear the thread memory cache because with Puma
we now share threads across requests
parent 030f57bd
require 'gitlab/testing/request_blocker_middleware' require 'gitlab/testing/request_blocker_middleware'
require 'gitlab/testing/request_inspector_middleware' require 'gitlab/testing/request_inspector_middleware'
require 'gitlab/testing/clear_thread_memory_cache_middleware'
Rails.application.configure do Rails.application.configure do
# Make sure the middleware is inserted first in middleware chain # Make sure the middleware is inserted first in middleware chain
config.middleware.insert_before(ActionDispatch::Static, Gitlab::Testing::RequestBlockerMiddleware) config.middleware.insert_before(ActionDispatch::Static, Gitlab::Testing::RequestBlockerMiddleware)
config.middleware.insert_before(ActionDispatch::Static, Gitlab::Testing::RequestInspectorMiddleware) config.middleware.insert_before(ActionDispatch::Static, Gitlab::Testing::RequestInspectorMiddleware)
config.middleware.insert_before(ActionDispatch::Static, Gitlab::Testing::ClearThreadMemoryCacheMiddleware)
# Settings specified here will take precedence over those in config/application.rb # Settings specified here will take precedence over those in config/application.rb
......
# frozen_string_literal: true
module Gitlab
module Testing
class ClearThreadMemoryCacheMiddleware
def initialize(app)
@app = app
end
def call(env)
Gitlab::ThreadMemoryCache.cache_backend.clear
@app.call(env)
end
end
end
end
...@@ -143,16 +143,11 @@ describe "Issues > User edits issue", :js do ...@@ -143,16 +143,11 @@ describe "Issues > User edits issue", :js do
end end
it 'allows user to unselect themselves' do it 'allows user to unselect themselves' do
issue2 = create(:issue, project: project, author: user) issue2 = create(:issue, project: project, author: user, assignees: [user])
visit project_issue_path(project, issue2) visit project_issue_path(project, issue2)
page.within '.assignee' do page.within '.assignee' do
click_link 'Edit'
click_link user.name
close_dropdown_menu_if_visible
page.within '.value .author' do page.within '.value .author' do
expect(page).to have_content user.name expect(page).to have_content user.name
end end
......
...@@ -11,81 +11,77 @@ describe 'Profile > Active Sessions', :clean_gitlab_redis_shared_state do ...@@ -11,81 +11,77 @@ describe 'Profile > Active Sessions', :clean_gitlab_redis_shared_state do
let(:admin) { create(:admin) } let(:admin) { create(:admin) }
around do |example|
Timecop.freeze(Time.zone.parse('2018-03-12 09:06')) do
example.run
end
end
it 'User sees their active sessions' do it 'User sees their active sessions' do
Capybara::Session.new(:session1) Timecop.freeze(Time.zone.parse('2018-03-12 09:06')) do
Capybara::Session.new(:session2) Capybara::Session.new(:session1)
Capybara::Session.new(:session3) Capybara::Session.new(:session2)
Capybara::Session.new(:session3)
# note: headers can only be set on the non-js (aka. rack-test) driver
using_session :session1 do # note: headers can only be set on the non-js (aka. rack-test) driver
Capybara.page.driver.header( using_session :session1 do
'User-Agent', Capybara.page.driver.header(
'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0' 'User-Agent',
) 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0'
)
gitlab_sign_in(user)
end gitlab_sign_in(user)
end
# set an additional session on another device
using_session :session2 do # set an additional session on another device
Capybara.page.driver.header( using_session :session2 do
'User-Agent', Capybara.page.driver.header(
'Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12B466 [FBDV/iPhone7,2]' 'User-Agent',
) 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12B466 [FBDV/iPhone7,2]'
)
gitlab_sign_in(user)
end gitlab_sign_in(user)
end
# set an admin session impersonating the user
using_session :session3 do # set an admin session impersonating the user
Capybara.page.driver.header( using_session :session3 do
'User-Agent', Capybara.page.driver.header(
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36' 'User-Agent',
) 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36'
)
gitlab_sign_in(admin)
gitlab_sign_in(admin)
visit admin_user_path(user)
visit admin_user_path(user)
click_link 'Impersonate'
end click_link 'Impersonate'
end
using_session :session1 do
visit profile_active_sessions_path using_session :session1 do
visit profile_active_sessions_path
expect(page).to(
have_selector('ul.list-group li.list-group-item', { text: 'Signed in on', expect(page).to(
count: 2 })) have_selector('ul.list-group li.list-group-item', { text: 'Signed in on',
count: 2 }))
expect(page).to have_content(
'127.0.0.1 ' \ expect(page).to have_content(
'This is your current session ' \ '127.0.0.1 ' \
'Firefox on Ubuntu ' \ 'This is your current session ' \
'Signed in on 12 Mar 09:06' 'Firefox on Ubuntu ' \
) 'Signed in on 12 Mar 09:06'
)
expect(page).to have_selector '[title="Desktop"]', count: 1
expect(page).to have_selector '[title="Desktop"]', count: 1
expect(page).to have_content(
'127.0.0.1 ' \ expect(page).to have_content(
'Last accessed on 12 Mar 09:06 ' \ '127.0.0.1 ' \
'Mobile Safari on iOS ' \ 'Last accessed on 12 Mar 09:06 ' \
'Signed in on 12 Mar 09:06' 'Mobile Safari on iOS ' \
) 'Signed in on 12 Mar 09:06'
)
expect(page).to have_selector '[title="Smartphone"]', count: 1
expect(page).to have_selector '[title="Smartphone"]', count: 1
expect(page).not_to have_content('Chrome on Windows')
expect(page).not_to have_content('Chrome on Windows')
end
end end
end end
it 'User can revoke a session', :js, :redis_session_store do it 'User can revoke a session', :js do
Capybara::Session.new(:session1) Capybara::Session.new(:session1)
Capybara::Session.new(:session2) Capybara::Session.new(:session2)
......
...@@ -200,7 +200,7 @@ describe 'Gcp Cluster', :js, :do_not_mock_admin_mode do ...@@ -200,7 +200,7 @@ describe 'Gcp Cluster', :js, :do_not_mock_admin_mode do
end end
end end
context 'when third party offers are disabled' do context 'when third party offers are disabled', :clean_gitlab_redis_shared_state do
let(:admin) { create(:admin) } let(:admin) { create(:admin) }
before do before do
......
...@@ -60,6 +60,7 @@ Capybara.register_driver :chrome do |app| ...@@ -60,6 +60,7 @@ Capybara.register_driver :chrome do |app|
) )
end end
Capybara.server = :puma
Capybara.javascript_driver = :chrome Capybara.javascript_driver = :chrome
Capybara.default_max_wait_time = timeout Capybara.default_max_wait_time = timeout
Capybara.ignore_hidden_elements = true Capybara.ignore_hidden_elements = true
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment