Skip to content

Commit

Permalink
fix lack of result num
Browse files Browse the repository at this point in the history
  • Loading branch information
陈遇文 committed May 10, 2023
1 parent b97599c commit bf52743
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 3 additions & 1 deletion read.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)
Expand All @@ -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
Expand Down
15 changes: 12 additions & 3 deletions simulate_scenario_test/read_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package simulateTest

import (
"errors"
"fmt"
"os"
"strings"
Expand Down Expand Up @@ -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)
Expand All @@ -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())
})
}

0 comments on commit bf52743

Please sign in to comment.