mirror of
https://gitee.com/milvus-io/milvus.git
synced 2026-01-07 03:13:22 +08:00
- Add SafeChan interface in lifetime package - Embed SafeChan into interface - Replace private lifetime struct in delegator package with - Refine delegator on-going task lifetime control and wait all accepted task done - Fix potential goroutine leakage from if delegator closed concurrently /kind improvement Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
38 lines
1.0 KiB
Go
38 lines
1.0 KiB
Go
package lifetime
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/typeutil"
|
|
"github.com/stretchr/testify/suite"
|
|
)
|
|
|
|
type SafeChanSuite struct {
|
|
suite.Suite
|
|
}
|
|
|
|
func (s *SafeChanSuite) TestClose() {
|
|
sc := NewSafeChan()
|
|
|
|
s.False(sc.IsClosed(), "IsClosed() shall return false before Close()")
|
|
s.False(typeutil.IsChanClosed(sc.CloseCh()), "CloseCh() returned channel shall not be closed before Close()")
|
|
|
|
s.NotPanics(func() {
|
|
sc.Close()
|
|
}, "SafeChan shall not panic during first close")
|
|
|
|
s.True(sc.IsClosed(), "IsClosed() shall return true after Close()")
|
|
s.True(typeutil.IsChanClosed(sc.CloseCh()), "CloseCh() returned channel shall be closed after Close()")
|
|
|
|
s.NotPanics(func() {
|
|
sc.Close()
|
|
}, "SafeChan shall not panic during second close")
|
|
|
|
s.True(sc.IsClosed(), "IsClosed() shall return true after double Close()")
|
|
s.True(typeutil.IsChanClosed(sc.CloseCh()), "CloseCh() returned channel shall be still closed after double Close()")
|
|
}
|
|
|
|
func TestSafeChan(t *testing.T) {
|
|
suite.Run(t, new(SafeChanSuite))
|
|
}
|