go-zero/core/syncx/limit_test.go

18 lines
330 B
Go
Raw Normal View History

2020-07-26 17:09:05 +08:00
package syncx
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestLimit(t *testing.T) {
limit := NewLimit(2)
limit.Borrow()
assert.True(t, limit.TryBorrow())
assert.False(t, limit.TryBorrow())
assert.Nil(t, limit.Return())
assert.Nil(t, limit.Return())
2020-10-10 11:53:49 +08:00
assert.Equal(t, ErrLimitReturn, limit.Return())
2020-07-26 17:09:05 +08:00
}