| 34 | } |
| 35 | |
| 36 | func TestZeroWorkers(t *testing.T) { |
| 37 | pool := workerpool.New(0, 0) |
| 38 | |
| 39 | var backSlot int64 = 10 |
| 40 | var job = func() { |
| 41 | atomic.StoreInt64(&backSlot, 110) |
| 42 | } |
| 43 | pool.Queue(job, 0) |
| 44 | |
| 45 | assert.Equal(t, int64(10), atomic.LoadInt64(&backSlot)) |
| 46 | |
| 47 | pool.Expand(1, 0, nil) |
| 48 | |
| 49 | done := make(chan bool) |
| 50 | job = func() { |
| 51 | defer close(done) |
| 52 | atomic.StoreInt64(&backSlot, 73) |
| 53 | } |
| 54 | assert.True(t, pool.Queue(job, time.Millisecond*50)) |
| 55 | <-done |
| 56 | |
| 57 | assert.Equal(t, int64(73), atomic.LoadInt64(&backSlot)) |
| 58 | |
| 59 | assert.NoError(t, waitFunc(pool.Stop, _timeout)) |
| 60 | } |
| 61 | |
| 62 | func TestAbsoluteTimeout(t *testing.T) { |
| 63 | initialWorkers := 1 |