|
54 | 54 | it { is_expected.to eq props.merge({ errors: errors }) }
|
55 | 55 | end
|
56 | 56 |
|
57 |
| - context 'when multithreaded with shared data' do |
| 57 | + context 'multithreaded inertia share' 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 |
59 | 62 |
|
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 |
76 | 69 |
|
| 70 | + thread2 = Thread.new do |
| 71 | + sleep 0.1 until start_thread2 |
77 | 72 |
|
78 |
| - threads.each(&:join) |
| 73 | + get share_path, headers: {'X-Inertia' => true} |
79 | 74 | 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 |
80 | 86 | end
|
81 | 87 |
|
82 | 88 | context 'when raises an exception' do
|
|
0 commit comments