[gzep] Add race test.
This commit is contained in:
parent
4150e84d20
commit
ea21dc3f95
1 changed files with 18 additions and 1 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"bytes"
|
||||
"compress/gzip"
|
||||
"io"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -26,7 +27,7 @@ func BenchmarkEncode(b *testing.B) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestRoundTrip(t *testing.T) {
|
||||
func TestEncode_RoundTrip(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
in string
|
||||
|
@ -49,6 +50,22 @@ func TestRoundTrip(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestEncode_Stress(t *testing.T) {
|
||||
n := 100
|
||||
|
||||
wg := &sync.WaitGroup{}
|
||||
wg.Add(n)
|
||||
for i := 0; i < n; i++ {
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
require.NoError(t, Encode([]byte("payload"), io.Discard))
|
||||
}()
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func decode(data []byte) ([]byte, error) {
|
||||
r, err := gzip.NewReader(bytes.NewReader(data))
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue