github.com/lingyao2333/mo-zero@v1.4.1/core/syncx/managedresource_test.go (about) 1 package syncx 2 3 import ( 4 "sync/atomic" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestManagedResource(t *testing.T) { 11 var count int32 12 resource := NewManagedResource(func() interface{} { 13 return atomic.AddInt32(&count, 1) 14 }, func(a, b interface{}) bool { 15 return a == b 16 }) 17 18 assert.Equal(t, resource.Take(), resource.Take()) 19 old := resource.Take() 20 resource.MarkBroken(old) 21 assert.NotEqual(t, old, resource.Take()) 22 }