milvus/pkg/util/lifetime/safe_chan_test.go
SimFG 26f06dd732
Format the code (#27275)
Signed-off-by: SimFG <bang.fu@zilliz.com>
2023-09-21 09:45:27 +08:00

39 lines
1.0 KiB
Go

package lifetime
import (
"testing"
"github.com/stretchr/testify/suite"
"github.com/milvus-io/milvus/pkg/util/typeutil"
)
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))
}