limit_test.go 330 B

1234567891011121314151617
  1. package syncx
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. func TestLimit(t *testing.T) {
  7. limit := NewLimit(2)
  8. limit.Borrow()
  9. assert.True(t, limit.TryBorrow())
  10. assert.False(t, limit.TryBorrow())
  11. assert.Nil(t, limit.Return())
  12. assert.Nil(t, limit.Return())
  13. assert.Equal(t, ErrLimitReturn, limit.Return())
  14. }