(t *testing.T)
| 12 | ) |
| 13 | |
| 14 | func TestNegWorkers(t *testing.T) { |
| 15 | pool := workerpool.New(-1, -1) |
| 16 | |
| 17 | quit := make(chan struct{}) |
| 18 | |
| 19 | n := int64(runtime.NumCPU()) |
| 20 | var backSlot int64 |
| 21 | var job = func() { |
| 22 | atomic.AddInt64(&backSlot, 1) |
| 23 | <-quit |
| 24 | } |
| 25 | for pool.Queue(job, time.Millisecond*50) { |
| 26 | } |
| 27 | |
| 28 | actual := atomic.LoadInt64(&backSlot) |
| 29 | assert.Equal(t, n, actual) |
| 30 | |
| 31 | close(quit) |
| 32 | |
| 33 | assert.NoError(t, waitFunc(pool.Stop, _timeout)) |
| 34 | } |
| 35 | |
| 36 | func TestZeroWorkers(t *testing.T) { |
| 37 | pool := workerpool.New(0, 0) |