Skip to content

Commit 6037973

Browse files
rollback old multithreaded testing
1 parent a306898 commit 6037973

File tree

3 files changed

+24
-36
lines changed

3 files changed

+24
-36
lines changed

spec/dummy/app/controllers/inertia_share_controller.rb

Lines changed: 0 additions & 16 deletions
This file was deleted.

spec/dummy/config/routes.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
get 'my_location' => 'inertia_test#my_location'
2020
get 'share_multithreaded' => 'inertia_multithreaded_share#share_multithreaded'
2121
get 'share_multithreaded_error' => 'inertia_multithreaded_share#share_multithreaded_error'
22-
get 'share_without_name' => 'inertia_share#share_without_name'
23-
get 'share_without_inertia' => 'inertia_share#share_without_inertia'
2422
get 'redirect_with_inertia_errors' => 'inertia_test#redirect_with_inertia_errors'
2523
post 'redirect_with_inertia_errors' => 'inertia_test#redirect_with_inertia_errors'
2624
post 'redirect_back_with_inertia_errors' => 'inertia_test#redirect_back_with_inertia_errors'

spec/inertia/sharing_spec.rb

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,35 @@
5454
it { is_expected.to eq props.merge({ errors: errors }) }
5555
end
5656

57-
context 'when multithreaded with shared data' do
57+
context 'multithreaded inertia share' do
5858
let(:props) { { name: 'Michael', has_goat_status: true } }
59+
it 'is expected to render props even when another thread shares Inertia data' do
60+
start_thread1 = false
61+
start_thread2 = false
5962

60-
it 'is expected to not share data from other requests' do
61-
threads = []
62-
threads << Thread.new do
63-
# Its takes one second
64-
get share_multithreaded_path, headers: {'X-Inertia' => true}
65-
body = response.body.dup
66-
props = JSON.parse(body)['props'].deep_symbolize_keys
67-
expect(props).to eq({ name: 'Michael', has_goat_status: true })
68-
end
69-
threads << Thread.new do
70-
# Its take half a second
71-
get share_without_name_path, headers: {'X-Inertia' => true}
72-
body = response.body.dup
73-
props = JSON.parse(body)['props'].deep_symbolize_keys
74-
expect(props).to eq({ someGroupsControllerData: true })
75-
end
63+
thread1 = Thread.new do
64+
sleep 0.1 until start_thread1
65+
66+
get share_multithreaded_path, headers: {'X-Inertia' => true}
67+
expect(subject).to eq props
68+
end
7669

70+
thread2 = Thread.new do
71+
sleep 0.1 until start_thread2
7772

78-
threads.each(&:join)
73+
get share_path, headers: {'X-Inertia' => true}
7974
end
75+
76+
# Thread 1 starts. The controller method runs inertia_share, then sleeps.
77+
# Thread 2 then modifies the shared inertia data before Thread 1 stops sleeping
78+
start_thread1 = true
79+
sleep 0.5
80+
start_thread2 = true
81+
82+
# Make sure that both threads finish before the block returns
83+
thread1.join
84+
thread2.join
85+
end
8086
end
8187

8288
context 'when raises an exception' do

0 commit comments

Comments
 (0)