|
|
|
@ -3,6 +3,7 @@ package errorx
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
"sync"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
@ -33,7 +34,7 @@ func TestBatchErrorNilFromFunc(t *testing.T) {
|
|
|
|
|
func TestBatchErrorOneError(t *testing.T) {
|
|
|
|
|
var batch BatchError
|
|
|
|
|
batch.Add(errors.New(err1))
|
|
|
|
|
assert.NotNil(t, batch)
|
|
|
|
|
assert.NotNil(t, batch.Err())
|
|
|
|
|
assert.Equal(t, err1, batch.Err().Error())
|
|
|
|
|
assert.True(t, batch.NotNil())
|
|
|
|
|
}
|
|
|
|
@ -42,7 +43,26 @@ func TestBatchErrorWithErrors(t *testing.T) {
|
|
|
|
|
var batch BatchError
|
|
|
|
|
batch.Add(errors.New(err1))
|
|
|
|
|
batch.Add(errors.New(err2))
|
|
|
|
|
assert.NotNil(t, batch)
|
|
|
|
|
assert.NotNil(t, batch.Err())
|
|
|
|
|
assert.Equal(t, fmt.Sprintf("%s\n%s", err1, err2), batch.Err().Error())
|
|
|
|
|
assert.True(t, batch.NotNil())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestBatchErrorConcurrentAdd(t *testing.T) {
|
|
|
|
|
const count = 10000
|
|
|
|
|
var batch BatchError
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
|
|
|
|
|
wg.Add(count)
|
|
|
|
|
for i := 0; i < count; i++ {
|
|
|
|
|
go func() {
|
|
|
|
|
defer wg.Done()
|
|
|
|
|
batch.Add(errors.New(err1))
|
|
|
|
|
}()
|
|
|
|
|
}
|
|
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
|
|
assert.NotNil(t, batch.Err())
|
|
|
|
|
assert.Equal(t, count, len(batch.errs))
|
|
|
|
|
assert.True(t, batch.NotNil())
|
|
|
|
|
}
|
|
|
|
|