milvus/pkg/util/lifetime/safe_chan_test.go
congqixia af5c01082b
Refine delegator lifetime control (#26881)
- 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>
2023-09-07 10:11:15 +08:00

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))
}