(t *testing.T)
| 11 | ) |
| 12 | |
| 13 | func TestBatch(t *testing.T) { |
| 14 | b, _ := New(context.Background()) |
| 15 | |
| 16 | now := time.Now() |
| 17 | b.Go("foo", func() (interface{}, error) { |
| 18 | time.Sleep(time.Millisecond * 100) |
| 19 | return "foo", nil |
| 20 | }) |
| 21 | b.Go("bar", func() (interface{}, error) { |
| 22 | time.Sleep(time.Millisecond * 150) |
| 23 | return "bar", nil |
| 24 | }) |
| 25 | result, err := b.WaitAndGetResult() |
| 26 | |
| 27 | assert.Nil(t, err) |
| 28 | |
| 29 | duration := time.Since(now) |
| 30 | assert.Less(t, duration, time.Millisecond*200) |
| 31 | assert.Equal(t, 2, len(result)) |
| 32 | |
| 33 | for k, v := range result { |
| 34 | assert.NoError(t, v.Err) |
| 35 | assert.Equal(t, k, v.Value.(string)) |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | func TestBatchWithConcurrencyNum(t *testing.T) { |
| 40 | b, _ := New( |
nothing calls this directly
no test coverage detected