mirror of
https://gitee.com/milvus-io/milvus.git
synced 2026-01-07 19:31:51 +08:00
issue: #46500 - simplify the run_go_codecov.sh to make sure the set -e to protect any sub command failure. - remove all embed etcd in test to make full test can be run at local. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## PR Summary: Simplify Go Unit Tests by Removing Embedded etcd and Async Startup Scaffolding **Core Invariant:** This PR assumes that unit tests can be simplified by running without embedded etcd servers (delegating to environment-based or external etcd instances via `kvfactory.GetEtcdAndPath()` or `ETCD_ENDPOINTS`) and by removing goroutine-based async startup scaffolding in favor of synchronous component initialization. Tests remain functionally equivalent while becoming simpler to run and debug locally. **What is Removed or Simplified:** 1. **Embedded etcd test infrastructure deleted**: Removes `EmbedEtcdUtil` type and its public methods (SetupEtcd, TearDownEmbedEtcd) from `pkg/util/testutils/embed_etcd.go`, removes the `StartTestEmbedEtcdServer()` helper from `pkg/util/etcd/etcd_util.go`, and removes etcd embedding from test suites (e.g., `TaskSuite`, `EtcdSourceSuite`, `mixcoord/client_test.go`). Tests now either skip etcd-dependent tests (via `MILVUS_UT_WITHOUT_KAFKA=1` environment flag in `kafka_test.go`) or source etcd from external configuration (via `kvfactory.GetEtcdAndPath()` in `task_test.go`, or `ETCD_ENDPOINTS` environment variable in `etcd_source_test.go`). This eliminates the overhead of spinning up temporary etcd servers for unit tests. 2. **Async startup scaffolding replaced with synchronous initialization**: In `internal/proxy/proxy_test.go` and `proxy_rpc_test.go`, the `startGrpc()` method signature removes the `sync.WaitGroup` parameter; components are now created, prepared, and run synchronously in-place rather than in goroutines (e.g., `go testServer.startGrpc(ctx, &p)` becomes `testServer.startGrpc(ctx, &p)` running synchronously). Readiness checks (e.g., `waitForGrpcReady()`) remain in place to ensure startup safety without concurrency constructs. This simplifies control flow and reduces debugging complexity. 3. **Shell script orchestration unified with proper error handling**: In `scripts/run_go_codecov.sh` and `scripts/run_intergration_test.sh`, per-package inline test invocations are consolidated into a single `test_cmd()` function with unified `TEST_CMD_WITH_ARGS` array containing race, coverage, verbose, and other flags. The problematic `set -ex` is replaced with `set -e` alone (removing debug output noise while preserving strict error semantics), ensuring the scripts fail fast on any command failure. **Why No Regression:** - Test assertions and code paths remain unchanged; only deployment source of etcd (embedded → external) and startup orchestration (async → sync) change. - Readiness verification (e.g., `waitForGrpcReady()`) is retained, ensuring components are initialized before test execution. - Test flags (race detection, coverage, verbosity) are uniformly applied across all packages via unified `TEST_CMD_WITH_ARGS`, preserving test coverage and quality. - `set -e` alone is sufficient for strict failure detection without the `-x` flag's verbose output. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: chyezh <chyezh@outlook.com>
77 lines
2.2 KiB
Go
77 lines
2.2 KiB
Go
package proxy
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
|
|
grpcproxyclient "github.com/milvus-io/milvus/internal/distributed/proxy/client"
|
|
"github.com/milvus-io/milvus/internal/util/dependency"
|
|
"github.com/milvus-io/milvus/pkg/v2/log"
|
|
"github.com/milvus-io/milvus/pkg/v2/proto/internalpb"
|
|
"github.com/milvus-io/milvus/pkg/v2/proto/proxypb"
|
|
"github.com/milvus-io/milvus/pkg/v2/util/commonpbutil"
|
|
"github.com/milvus-io/milvus/pkg/v2/util/funcutil"
|
|
"github.com/milvus-io/milvus/pkg/v2/util/paramtable"
|
|
"github.com/milvus-io/milvus/pkg/v2/util/typeutil"
|
|
)
|
|
|
|
func TestProxyRpcLimit(t *testing.T) {
|
|
var err error
|
|
|
|
path := "/tmp/milvus/rocksmq" + funcutil.GenRandomStr()
|
|
t.Setenv("ROCKSMQ_PATH", path)
|
|
defer os.RemoveAll(path)
|
|
|
|
ctx := GetContext(context.Background(), "root:123456")
|
|
localMsg := true
|
|
factory := dependency.NewDefaultFactory(localMsg)
|
|
|
|
bt := paramtable.NewBaseTable(paramtable.SkipRemote(true))
|
|
base := ¶mtable.ComponentParam{}
|
|
base.Init(bt)
|
|
var p paramtable.GrpcServerConfig
|
|
assert.NoError(t, err)
|
|
p.Init(typeutil.ProxyRole, bt)
|
|
base.Save("proxy.grpc.serverMaxRecvSize", "1")
|
|
|
|
assert.Equal(t, p.ServerMaxRecvSize.GetAsInt(), 1)
|
|
log.Info("Initialize parameter table of Proxy")
|
|
|
|
proxy, err := NewProxy(ctx, factory)
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, proxy)
|
|
|
|
testServer := newProxyTestServer(proxy)
|
|
testServer.Proxy.SetAddress(p.GetAddress())
|
|
go testServer.startGrpc(ctx, &p)
|
|
assert.NoError(t, testServer.waitForGrpcReady())
|
|
defer testServer.grpcServer.Stop()
|
|
client, err := grpcproxyclient.NewClient(ctx, "localhost:"+p.Port.GetValue(), 1)
|
|
assert.NoError(t, err)
|
|
proxy.UpdateStateCode(commonpb.StateCode_Healthy)
|
|
|
|
rates := make([]*internalpb.Rate, 0)
|
|
|
|
req := &proxypb.SetRatesRequest{
|
|
Base: commonpbutil.NewMsgBase(
|
|
commonpbutil.WithMsgID(int64(0)),
|
|
commonpbutil.WithTimeStamp(0),
|
|
),
|
|
Rates: []*proxypb.CollectionRate{
|
|
{
|
|
Collection: 1,
|
|
Rates: rates,
|
|
},
|
|
},
|
|
}
|
|
_, err = client.SetRates(ctx, req)
|
|
// should be limited because of the rpc limit
|
|
assert.Error(t, err)
|
|
assert.True(t, strings.Contains(err.Error(), "ResourceExhausted"))
|
|
}
|