(timeout time.Duration, f func() (bool, errors.Error))
| 327 | } |
| 328 | |
| 329 | func runWithTimeout(timeout time.Duration, f func() (bool, errors.Error)) errors.Error { |
| 330 | if timeout == 0 { |
| 331 | timeout = math.MaxInt |
| 332 | } |
| 333 | type response struct { |
| 334 | err errors.Error |
| 335 | completed bool |
| 336 | } |
| 337 | timer := time.After(timeout) |
| 338 | resChan := make(chan response) |
| 339 | resp := response{} |
| 340 | for { |
| 341 | go func() { |
| 342 | done, err := f() |
| 343 | resChan <- response{err, done} |
| 344 | }() |
| 345 | select { |
| 346 | case <-timer: |
| 347 | if !resp.completed { |
| 348 | return errors.Default.New(fmt.Sprintf("timed out calling function after %d milliseconds", timeout.Milliseconds())) |
| 349 | } |
| 350 | return nil |
| 351 | case resp = <-resChan: |
| 352 | if resp.err != nil { |
| 353 | return resp.err |
| 354 | } |
| 355 | if resp.completed { |
| 356 | return nil |
| 357 | } |
| 358 | time.Sleep(1 * time.Second) |
| 359 | continue |
| 360 | } |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | func sendHttpRequest[Res any](t *testing.T, timeout time.Duration, ctx *testContext, httpMethod string, endpoint string, headers map[string]string, body any) Res { |
| 365 | t.Helper() |
no test coverage detected