mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-24 01:30:25 +08:00
18 lines
330 B
Go
18 lines
330 B
Go
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())
|
|
assert.Equal(t, ErrLimitReturn, limit.Return())
|
|
}
|