From bf52743953f4c17d739ac54aa67b04ddfe6e1047 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E9=81=87=E6=96=87?= Date: Wed, 10 May 2023 16:39:18 +0800 Subject: [PATCH] fix lack of result num --- read.go | 4 +++- simulate_scenario_test/read_test.go | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/read.go b/read.go index 32cd6d7..3fd64e1 100644 --- a/read.go +++ b/read.go @@ -190,6 +190,7 @@ func (r *Read) Run(fn ImportFunc, num ...int) (results *Result, err error) { var ( row int + dataRow int headerFound bool ) for r.rows.Next() { @@ -211,6 +212,7 @@ func (r *Read) Run(fn ImportFunc, num ...int) (results *Result, err error) { } r.wg.Add(1) + dataRow++ // 向携程池提交任务 if err = r.concPool.Submit(func() { r.exec(row, columns) @@ -222,7 +224,7 @@ func (r *Read) Run(fn ImportFunc, num ...int) (results *Result, err error) { r.wg.Wait() - r.results.totalRow = row - r.results.dataStartRow + r.results.totalRow = dataRow r.results.errorRow = len(r.results.errors) results = r.results diff --git a/simulate_scenario_test/read_test.go b/simulate_scenario_test/read_test.go index f25d52a..ae0c230 100644 --- a/simulate_scenario_test/read_test.go +++ b/simulate_scenario_test/read_test.go @@ -1,6 +1,7 @@ package simulateTest import ( + "errors" "fmt" "os" "strings" @@ -55,7 +56,8 @@ func Test_Batch_Read(t *testing.T) { }) t.Run("each_business_cost_200ms_10_goroutine", func(t *testing.T) { - _, err = r.Run(func(any any) (err error) { + var rr *excelizex.Result + rr, err = r.Run(func(any any) (err error) { b := any.(*batchData) time.Sleep(200 * time.Millisecond) fmt.Println(b) @@ -66,17 +68,24 @@ func Test_Batch_Read(t *testing.T) { if err != nil { t.Error(err) } + + fmt.Println(rr.TotalNum()) + fmt.Println(rr.ErrorNum()) }) t.Run("each_business_cost_200ms_100_goroutine", func(t *testing.T) { - if _, err = r.Run(func(any any) (err error) { + var rr *excelizex.Result + if rr, err = r.Run(func(any any) (err error) { b := any.(*batchData) time.Sleep(200 * time.Millisecond) fmt.Println(b) - return + return errors.New("test") }, 100); err != nil { t.Error(err) } + + fmt.Println(rr.TotalNum()) + fmt.Println(rr.ErrorNum()) }) }