| 60 | } |
| 61 | |
| 62 | func TestAbsoluteTimeout(t *testing.T) { |
| 63 | initialWorkers := 1 |
| 64 | extraWorkers := 10 |
| 65 | |
| 66 | pool := workerpool.New(initialWorkers, 2) |
| 67 | |
| 68 | quit1 := make(chan struct{}) |
| 69 | pool.Expand(extraWorkers, 0, quit1) |
| 70 | |
| 71 | done := make(chan bool) |
| 72 | absoluteTimeout := func() { |
| 73 | defer close(done) |
| 74 | <-time.After(time.Millisecond * 100) |
| 75 | close(quit1) |
| 76 | } |
| 77 | |
| 78 | go absoluteTimeout() |
| 79 | <-done |
| 80 | <-time.After(time.Millisecond * 400) |
| 81 | |
| 82 | assert.NoError(t, waitFunc(pool.Stop, _timeout)) |
| 83 | } |
| 84 | |
| 85 | func TestTimeout(t *testing.T) { |
| 86 | initialWorkers := 1 |