Skip to content

Commit 1785e3b

Browse files
committed
Fix flaky test
1 parent 8707dc5 commit 1785e3b

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

spec/inertia/action_filter_spec.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
# frozen_string_literal: true
22

3-
# spec/lib/inertia_rails/action_filter_spec.rb
4-
5-
require 'rails_helper'
6-
73
RSpec.describe InertiaRails::ActionFilter do
84
let(:controller) do
95
instance_double(

spec/inertia/middleware_spec.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
RSpec.describe InertiaRails::Middleware, type: :request do
3+
RSpec.describe 'InertiaRails::Middleware', type: :request do
44
context 'the version is set' do
55
with_inertia_config version: '1.0'
66

@@ -52,21 +52,25 @@
5252
end
5353

5454
it 'is thread safe' do
55-
delete_request_proc = -> { delete redirect_test_path, headers: { 'X-Inertia' => true } }
56-
get_request_proc = -> { get empty_test_path }
55+
# Capture route paths to fix flakiness
56+
redirect_path = redirect_test_path
57+
empty_path = empty_test_path
5758

58-
statusses = []
59+
delete_request_proc = -> { delete redirect_path, headers: { 'X-Inertia' => true } }
60+
get_request_proc = -> { get empty_path }
61+
62+
statuses = Concurrent::Array.new
5963

6064
threads = []
6165

6266
100.times do
63-
threads << Thread.new { statusses << delete_request_proc.call }
67+
threads << Thread.new { statuses << delete_request_proc.call }
6468
threads << Thread.new { get_request_proc.call }
6569
end
6670

6771
threads.each(&:join)
6872

69-
expect(statusses.uniq).to eq([303])
73+
expect(statuses.uniq).to eq([303])
7074
end
7175
end
7276
end

0 commit comments

Comments
 (0)