diff --git a/core/syncx/resourcemanager.go b/core/syncx/resourcemanager.go index 39e14561..cee3aba8 100644 --- a/core/syncx/resourcemanager.go +++ b/core/syncx/resourcemanager.go @@ -33,7 +33,8 @@ func (manager *ResourceManager) Close() error { be.Add(err) } } - + // reset resources + manager.resources = make(map[string]io.Closer) return be.Err() } diff --git a/core/syncx/resourcemanager_test.go b/core/syncx/resourcemanager_test.go index 2debc84c..d4456bfa 100644 --- a/core/syncx/resourcemanager_test.go +++ b/core/syncx/resourcemanager_test.go @@ -44,3 +44,17 @@ func TestResourceManager_GetResourceError(t *testing.T) { assert.NotNil(t, err) } } + +func TestResourceManager_Close(t *testing.T) { + manager := NewResourceManager() + + for i := 0; i < 10; i++ { + _, err := manager.GetResource("key", func() (io.Closer, error) { + return nil, errors.New("fail") + }) + assert.NotNil(t, err) + } + err := manager.Close() + assert.NoError(t, err) + assert.Equal(t, 0, len(manager.resources)) +}