(t *testing.T)
| 155 | } |
| 156 | |
| 157 | func TestAsyncResponseFansIn(t *testing.T) { |
| 158 | leakOpts := goleak.IgnoreCurrent() |
| 159 | |
| 160 | // create a random hierarchy of async responses and add a bunch of responses. |
| 161 | // count the added responses and confirm the number we pull is the same. |
| 162 | wg := sync.WaitGroup{} |
| 163 | rootResp := newAsyncResponse() |
| 164 | |
| 165 | expected := 0 |
| 166 | wg.Add(1) |
| 167 | go func() { |
| 168 | defer wg.Done() |
| 169 | defer rootResp.SendComplete() |
| 170 | |
| 171 | expected = addResponses(rootResp) |
| 172 | }() |
| 173 | |
| 174 | actual := 0 |
| 175 | wg.Add(1) |
| 176 | go func() { |
| 177 | defer wg.Done() |
| 178 | |
| 179 | for { |
| 180 | resp, done, err := rootResp.Next(context.Background()) |
| 181 | if done { |
| 182 | return |
| 183 | } |
| 184 | actual++ |
| 185 | require.NoError(t, err) |
| 186 | require.NotNil(t, resp) |
| 187 | } |
| 188 | }() |
| 189 | |
| 190 | wg.Wait() |
| 191 | require.Equal(t, expected, actual) |
| 192 | |
| 193 | goleak.VerifyNone(t, leakOpts) |
| 194 | } |
| 195 | |
| 196 | func addResponses(r *asyncResponse) int { |
| 197 | responsesToAdd := rand.Intn(5) |
nothing calls this directly
no test coverage detected