github.com/kaydxh/golang@v0.0.131/pkg/pool/task/batch_process_test.go (about) 1 package task_test 2 3 import ( 4 "fmt" 5 "testing" 6 7 task_ "github.com/kaydxh/golang/pkg/pool/task" 8 ) 9 10 func processTask(data []int) error { 11 fmt.Printf("process %v\n", data) 12 return nil 13 } 14 15 func TestBatchProcessSync(t *testing.T) { 16 testCases := []struct { 17 data []int 18 batchSize int 19 expected string 20 }{ 21 { 22 data: []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, 23 batchSize: 4, 24 expected: "", 25 }, 26 } 27 28 for i, testCase := range testCases { 29 t.Run(fmt.Sprintf("%d\n", i), func(t *testing.T) { 30 err := task_.BatchProcess(testCase.data, testCase.batchSize, processTask) 31 if err != nil { 32 t.Fatalf("failed to batch process task %d, got : %v", i, err) 33 34 } 35 36 }) 37 } 38 39 }