mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 17:20:24 +08:00
28 lines
454 B
Go
28 lines
454 B
Go
|
package syncx
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func TestRefCleaner(t *testing.T) {
|
||
|
var count int
|
||
|
clean := func() {
|
||
|
count += 1
|
||
|
}
|
||
|
|
||
|
cleaner := NewRefResource(clean)
|
||
|
err := cleaner.Use()
|
||
|
assert.Nil(t, err)
|
||
|
err = cleaner.Use()
|
||
|
assert.Nil(t, err)
|
||
|
cleaner.Clean()
|
||
|
cleaner.Clean()
|
||
|
assert.Equal(t, 1, count)
|
||
|
cleaner.Clean()
|
||
|
cleaner.Clean()
|
||
|
assert.Equal(t, 1, count)
|
||
|
assert.Equal(t, ErrUseOfCleaned, cleaner.Use())
|
||
|
}
|