fix ut timeout (#23636)

Signed-off-by: Wei Liu <wei.liu@zilliz.com>
pull/23682/head
wei liu 2023-04-25 10:24:35 +08:00 committed by GitHub
parent a7796e61e7
commit 88bef1b1a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 107 additions and 2 deletions

View File

@ -70,7 +70,7 @@ func NewCheckerController(
return &CheckerController{
stopCh: make(chan struct{}),
checkCh: make(chan struct{}),
checkCh: make(chan struct{}, 1),
meta: meta,
dist: dist,
targetMgr: targetMgr,
@ -112,7 +112,11 @@ func (controller *CheckerController) Stop() {
}
func (controller *CheckerController) Check() {
controller.checkCh <- struct{}{}
// prevent call check caused stuck here after controller stop
select {
case controller.checkCh <- struct{}{}:
default:
}
}
// check is the real implementation of Check

View File

@ -0,0 +1,101 @@
// Licensed to the LF AI & Data foundation under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package checkers
import (
"context"
"testing"
etcdkv "github.com/milvus-io/milvus/internal/kv/etcd"
"github.com/milvus-io/milvus/internal/querycoordv2/balance"
"github.com/milvus-io/milvus/internal/querycoordv2/meta"
. "github.com/milvus-io/milvus/internal/querycoordv2/params"
"github.com/milvus-io/milvus/internal/querycoordv2/session"
"github.com/milvus-io/milvus/internal/querycoordv2/task"
"github.com/milvus-io/milvus/internal/util/etcd"
"github.com/stretchr/testify/suite"
)
type ControllerSuite struct {
suite.Suite
//dependency
kv *etcdkv.EtcdKV
nodeMgr *session.NodeManager
meta *meta.Meta
broker *meta.MockBroker
distManager *meta.DistributionManager
targetManager *meta.TargetManager
balancer *balance.MockBalancer
scheduler *task.MockScheduler
controller *CheckerController
}
func (suite *ControllerSuite) SetupSuite() {
Params.InitOnce()
}
func (suite *ControllerSuite) SetupTest() {
var err error
config := GenerateEtcdConfig()
cli, err := etcd.GetEtcdClient(
config.UseEmbedEtcd,
config.EtcdUseSSL,
config.Endpoints,
config.EtcdTLSCert,
config.EtcdTLSKey,
config.EtcdTLSCACert,
config.EtcdTLSMinVersion)
suite.Require().NoError(err)
suite.kv = etcdkv.NewEtcdKV(cli, config.MetaRootPath)
// meta
store := meta.NewMetaStore(suite.kv)
idAllocator := RandomIncrementIDAllocator()
suite.nodeMgr = session.NewNodeManager()
suite.meta = meta.NewMeta(idAllocator, store, suite.nodeMgr)
suite.distManager = meta.NewDistributionManager()
suite.broker = meta.NewMockBroker(suite.T())
suite.targetManager = meta.NewTargetManager(suite.broker, suite.meta)
suite.balancer = balance.NewMockBalancer(suite.T())
suite.scheduler = task.NewMockScheduler(suite.T())
suite.controller = NewCheckerController(suite.meta, suite.distManager, suite.targetManager, suite.balancer, suite.nodeMgr, suite.scheduler)
suite.scheduler.EXPECT().GetSegmentTaskNum().Return(0).Maybe()
}
func (suite *ControllerSuite) TearDownTest() {
suite.kv.Close()
}
func (suite *ControllerSuite) TestCheckAfterStop() {
suite.controller.Start(context.Background())
suite.controller.Stop()
suite.controller.Check()
}
func (suite *ControllerSuite) TestCheck() {
// test close chan
close(suite.controller.checkCh)
}
func TestController(t *testing.T) {
suite.Run(t, new(ControllerSuite))
}