|
54 | 54 | it { is_expected.to eq props.merge({ errors: errors }) }
|
55 | 55 | end
|
56 | 56 |
|
57 |
| - context 'multithreaded intertia share' do |
| 57 | + context 'when multithreaded with shared data' do |
58 | 58 | 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 |
62 | 59 |
|
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 |
| 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 |
69 | 76 |
|
70 |
| - thread2 = Thread.new do |
71 |
| - sleep 0.1 until start_thread2 |
72 | 77 |
|
73 |
| - # Would prefer to make this a second get request, but RSpec will overwrite |
74 |
| - # the @response variable if another request is made in the second thread. |
75 |
| - # This simulates the relevant effects of another call to a different |
76 |
| - # controller with different values for inertia_share |
77 |
| - # TODO: Make this test work |
78 |
| - # InertiaRails.reset! |
79 |
| - # InertiaRails.share(name: 'Brian', has_goat_status: false) |
| 78 | + threads.each(&:join) |
80 | 79 | end
|
81 | 80 |
|
82 |
| - # Thread 1 starts. The controller method runs inertia_share, then sleeps. |
83 |
| - # Thread 2 then modifies the shared inertia data before Thread 1 stops sleeping |
84 |
| - start_thread1 = true |
85 |
| - sleep 0.5 |
86 |
| - start_thread2 = true |
87 |
| - |
88 |
| - # Make sure that both threads finish before the block returns |
89 |
| - thread1.join |
90 |
| - thread2.join |
91 |
| - end |
92 |
| - |
93 | 81 | describe 'deep or shallow merging shared data' do
|
94 | 82 | context 'with default settings (shallow merge)' do
|
95 | 83 | describe 'shallow merging by default' do
|
|
138 | 126 | rescue Exception
|
139 | 127 | end
|
140 | 128 |
|
141 |
| - # TODO: Comment test |
| 129 | + # TODO: How to test this? We really neeed? |
142 | 130 | # expect(InertiaRails.shared_plain_data).to be_empty
|
143 | 131 | # expect(InertiaRails.shared_blocks).to be_empty
|
144 | 132 | end
|
|
0 commit comments