Skip to content

Commit

Permalink
feat(kitmw): fix race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Reasno committed Mar 10, 2021
1 parent 0392be1 commit aad54e7
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions kitmw/async_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ import (
"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/mocktracer"
"github.com/stretchr/testify/assert"
"go.uber.org/atomic"
)

func TestMakeAsyncMiddleware(t *testing.T) {
var c int
var c atomic.Int32
m := MakeAsyncMiddleware(log.NewNopLogger(), 5)
f := m(func(ctx context.Context, request interface{}) (response interface{}, err error) {
c++
assert.Less(t, c, 5)
c.Inc()
assert.Less(t, c.Load(), 5)
time.Sleep(time.Duration(rand.Float64()) * time.Second)
c--
c.Dec()
return nil, nil
})

Expand Down

0 comments on commit aad54e7

Please sign in to comment.