|
96 | 96 | then_future.wait
|
97 | 97 | expect(then_future.value).to eq('Hello, Bob')
|
98 | 98 | end
|
| 99 | + |
| 100 | + describe 'aggregations' do |
| 101 | + it 'can pass on all' do |
| 102 | + f1 = Factor::Workflow::Future.new { 'a' } |
| 103 | + f2 = Factor::Workflow::Future.new { 'a' } |
| 104 | + |
| 105 | + f_all = Factor::Workflow::Future.all(f1,f2) { |f| f == 'a' } |
| 106 | + f_all.wait |
| 107 | + |
| 108 | + expect(f_all.value).to be true |
| 109 | + end |
| 110 | + |
| 111 | + it 'can fail on all' do |
| 112 | + f1 = Factor::Workflow::Future.new { 'a' } |
| 113 | + f2 = Factor::Workflow::Future.new { 'b' } |
| 114 | + |
| 115 | + f_all = Factor::Workflow::Future.all(f1,f2) { |f| f == 'a' } |
| 116 | + f_all.wait |
| 117 | + |
| 118 | + expect(f_all.state).to be :rejected |
| 119 | + expect(f_all.reason).to be_a(StandardError) |
| 120 | + expect(f_all.reason.message).to eq('There were no successful events') |
| 121 | + end |
| 122 | + |
| 123 | + it 'can pass on any with all true' do |
| 124 | + f1 = Factor::Workflow::Future.new { 'a' } |
| 125 | + f2 = Factor::Workflow::Future.new { 'a' } |
| 126 | + |
| 127 | + f_any = Factor::Workflow::Future.any(f1,f2) { |f| f == 'a' } |
| 128 | + f_any.wait |
| 129 | + |
| 130 | + expect(f_any.value).to be true |
| 131 | + end |
| 132 | + |
| 133 | + it 'can pass on any with one true' do |
| 134 | + f1 = Factor::Workflow::Future.new { 'a' } |
| 135 | + f2 = Factor::Workflow::Future.new { 'b' } |
| 136 | + |
| 137 | + f_any = Factor::Workflow::Future.any(f1,f2) { |f| f == 'a' } |
| 138 | + f_any.wait |
| 139 | + |
| 140 | + expect(f_any.value).to be true |
| 141 | + end |
| 142 | + |
| 143 | + it 'can fail on any' do |
| 144 | + f1 = Factor::Workflow::Future.new { 'b' } |
| 145 | + f2 = Factor::Workflow::Future.new { 'b' } |
| 146 | + |
| 147 | + f_any = Factor::Workflow::Future.any(f1,f2) { |f| f == 'a' } |
| 148 | + f_any.wait |
| 149 | + |
| 150 | + expect(f_any.state).to be :rejected |
| 151 | + expect(f_any.reason).to be_a(StandardError) |
| 152 | + expect(f_any.reason.message).to eq('There were no successful events') |
| 153 | + end |
| 154 | + end |
99 | 155 | end
|
0 commit comments