Skip to content

Commit

Permalink
test: check pools concurrently
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Oct 31, 2021
1 parent 075f757 commit ad81f70
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions jx_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package jx

import (
"bytes"
"encoding/json"
"sync"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand All @@ -14,3 +17,41 @@ func requireCompat(t testing.TB, exp []byte, v interface{}) {
require.NoError(t, err)
require.Equal(t, exp, buf)
}

func TestPutEncoder(t *testing.T) {
var wg sync.WaitGroup
for j := 0; j < 4; j++ {
wg.Add(1)
go func() {
defer wg.Done()
for i := 0; i < 1024; i++ {
e := GetEncoder()
e.Raw("false")
assert.Equal(t, "false", e.String())
PutEncoder(e)
}
}()
}
wg.Wait()
}

func TestPutDecoder(t *testing.T) {
var wg sync.WaitGroup
for j := 0; j < 4; j++ {
wg.Add(1)
go func() {
defer wg.Done()
for i := 0; i < 1024; i++ {
d := GetDecoder()
assert.Equal(t, d.Next(), Invalid)
d.Reset(bytes.NewBufferString("false"))
v, err := d.Bool()
assert.NoError(t, err)
assert.Equal(t, d.Next(), Invalid)
assert.False(t, v)
PutDecoder(d)
}
}()
}
wg.Wait()
}

0 comments on commit ad81f70

Please sign in to comment.