MCPcopy Create free account
hub / github.com/ClashDotNetFramework/experimental-clash / TestBatch

Function TestBatch

common/batch/batch_test.go:13–37  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func 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
39func TestBatchWithConcurrencyNum(t *testing.T) {
40 b, _ := New(

Callers

nothing calls this directly

Calls 4

WaitAndGetResultMethod · 0.80
NewFunction · 0.70
NowMethod · 0.45
GoMethod · 0.45

Tested by

no test coverage detected