Skip to content

Commit

Permalink
Removed unneeded tests
Browse files Browse the repository at this point in the history
Signed-off-by: Nischay <[email protected]>
  • Loading branch information
nish112022 committed Nov 19, 2024
1 parent c87259b commit cd19f4f
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 651 deletions.
4 changes: 4 additions & 0 deletions cmd/tools/config/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ func WriteYaml(w io.Writer) {
name: "tls",
header: "\n# Configure the proxy tls enable.",
},
{
name: "internaltls",
header: "\n# Configure the node-tls enable.",
},
{
name: "common",
},
Expand Down
9 changes: 5 additions & 4 deletions configs/milvus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -784,10 +784,11 @@ tls:
serverKeyPath: configs/cert/server.key
caPemPath: configs/cert/ca.pem

# Configure the node-tls enable.
internaltls:
serverPemPath: #path to server.pem
serverKeyPath: #path to server.key
caPemPath: #path to ca.key
serverPemPath: configs/cert/server.pem
serverKeyPath: configs/cert/server.key
caPemPath: configs/cert/ca.pem

common:
defaultPartitionName: _default # Name of the default partition when a collection is created
Expand Down Expand Up @@ -844,8 +845,8 @@ common:
privileges: Query,Search,IndexDetail,GetFlushState,GetLoadState,GetLoadingProgress,HasPartition,ShowPartitions,DescribeCollection,DescribeAlias,GetStatistics,ListAliases,Load,Release,Insert,Delete,Upsert,Import,Flush,Compaction,LoadBalance,RenameCollection,CreateIndex,DropIndex,CreatePartition,DropPartition # Collection level readwrite privileges
admin:
privileges: Query,Search,IndexDetail,GetFlushState,GetLoadState,GetLoadingProgress,HasPartition,ShowPartitions,DescribeCollection,DescribeAlias,GetStatistics,ListAliases,Load,Release,Insert,Delete,Upsert,Import,Flush,Compaction,LoadBalance,RenameCollection,CreateIndex,DropIndex,CreatePartition,DropPartition,CreateAlias,DropAlias # Collection level admin privileges
internaltlsEnabled: false
tlsMode: 0
internaltlsEnabled : false
session:
ttl: 30 # ttl value when session granting a lease to register service
retryTimes: 30 # retry times when session sending etcd requests
Expand Down
87 changes: 4 additions & 83 deletions internal/distributed/datacoord/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ import (
"time"

"github.com/cockroachdb/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"go.uber.org/zap"

"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
"github.com/milvus-io/milvus/internal/distributed/utils"
"github.com/milvus-io/milvus/internal/mocks"
"github.com/milvus-io/milvus/internal/proto/datapb"
"github.com/milvus-io/milvus/internal/proto/indexpb"
Expand All @@ -36,10 +39,6 @@ import (
"github.com/milvus-io/milvus/pkg/util/etcd"
"github.com/milvus-io/milvus/pkg/util/merr"
"github.com/milvus-io/milvus/pkg/util/paramtable"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
testify_mock "github.com/stretchr/testify/mock"
"go.uber.org/zap"
)

var mockErr = errors.New("mock grpc err")
Expand Down Expand Up @@ -73,84 +72,6 @@ func Test_NewClient(t *testing.T) {
assert.NoError(t, err)
}

func Test_InternalTLS(t *testing.T) {
paramtable.Init()
validPath := "../../../../configs/cert1/ca.pem"

ctx := context.Background()
client, err := NewClient(ctx)
assert.NoError(t, err)
assert.NotNil(t, client)
defer client.Close()

mockDC := mocks.NewMockDataCoordClient(t)
mockGrpcClient := mocks.NewMockGrpcClient[datapb.DataCoordClient](t)

// Set mock expectations
mockGrpcClient.EXPECT().Close().Return(nil)
mockGrpcClient.EXPECT().GetNodeID().Return(1)
mockGrpcClient.EXPECT().ReCall(testify_mock.Anything, testify_mock.Anything).RunAndReturn(func(ctx context.Context, f func(datapb.DataCoordClient) (interface{}, error)) (interface{}, error) {
return f(mockDC)
})
// Sub-test for nil cert pool
t.Run("NoCertPool", func(t *testing.T) {
var ErrNoCertPool = errors.New("no cert pool")
mockGrpcClient.EXPECT().SetInternalTLSCertPool(testify_mock.Anything).Return().Once()
client.(*Client).grpcClient = mockGrpcClient
client.(*Client).grpcClient.SetInternalTLSCertPool(nil) // Simulate no cert pool

mockDC.EXPECT().Flush(testify_mock.Anything, testify_mock.Anything).Return(nil, ErrNoCertPool)

_, err := client.Flush(ctx, &datapb.FlushRequest{})
assert.Error(t, err) // Check for an error
assert.Equal(t, ErrNoCertPool, err) // Check that it's the expected error
})

// Sub-test for invalid certificate path
t.Run("InvalidCertPath", func(t *testing.T) {
invalidCAPath := "invalid/path/to/ca.pem"
cp, err := utils.CreateCertPoolforClient(invalidCAPath, "datacoord")
assert.NotNil(t, err) // Expect an error while creating cert pool
assert.Nil(t, cp) // Cert pool should be nil
})

// Sub-test for TLS handshake failure
t.Run("TlsHandshakeFailed", func(t *testing.T) {
cp, err := utils.CreateCertPoolforClient(validPath, "datacoord")
assert.Nil(t, err)

mockGrpcClient.EXPECT().SetInternalTLSCertPool(cp).Return().Once()

mockDC.ExpectedCalls = nil
mockDC.EXPECT().Flush(mock.Anything, mock.Anything).Return(nil, errors.New("TLS handshake failed"))

client.(*Client).grpcClient = mockGrpcClient
client.(*Client).grpcClient.SetInternalTLSCertPool(cp)

_, err = client.Flush(ctx, &datapb.FlushRequest{})
assert.NotNil(t, err)
assert.EqualError(t, err, "TLS handshake failed")
})

t.Run("SuccessfulFlush", func(t *testing.T) {
cp, err := utils.CreateCertPoolforClient(validPath, "datacoord")
assert.NoError(t, err)
assert.NotNil(t, cp)

mockGrpcClient.EXPECT().SetInternalTLSCertPool(cp).Return().Once()
client.(*Client).grpcClient = mockGrpcClient
client.(*Client).grpcClient.SetInternalTLSCertPool(cp)

mockDC.ExpectedCalls = nil
mockDC.EXPECT().Flush(mock.Anything, mock.Anything).Return(&datapb.FlushResponse{
Status: merr.Success(),
}, mockErr)

_, err = client.Flush(ctx, &datapb.FlushRequest{})
assert.NotNil(t, err)
})
}

func Test_GetComponentStates(t *testing.T) {
paramtable.Init()

Expand Down
91 changes: 0 additions & 91 deletions internal/distributed/datanode/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,11 @@ package grpcdatanodeclient
import (
"context"
"testing"
"time"

"github.com/cockroachdb/errors"
"github.com/stretchr/testify/assert"
testify_mock "github.com/stretchr/testify/mock"
"google.golang.org/grpc"

"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
"github.com/milvus-io/milvus/internal/distributed/utils"
"github.com/milvus-io/milvus/internal/mocks"
"github.com/milvus-io/milvus/internal/proto/datapb"
"github.com/milvus-io/milvus/internal/util/mock"
"github.com/milvus-io/milvus/pkg/util/paramtable"
Expand Down Expand Up @@ -130,89 +125,3 @@ func Test_NewClient(t *testing.T) {
err = client.Close()
assert.NoError(t, err)
}

func Test_InternalTLS(t *testing.T) {
paramtable.Init()
validPath := "../../../../configs/cert1/ca.pem"
ctx := context.Background()
client, err := NewClient(ctx, "test", 1)
assert.NoError(t, err)
assert.NotNil(t, client)
defer client.Close()

mockDataNode := mocks.NewMockDataNodeClient(t)
mockGrpcClient := mocks.NewMockGrpcClient[datapb.DataNodeClient](t)

mockGrpcClient.EXPECT().Close().Return(nil)
mockGrpcClient.EXPECT().GetNodeID().Return(1)
mockGrpcClient.EXPECT().ReCall(testify_mock.Anything, testify_mock.Anything).RunAndReturn(func(ctx context.Context, f func(datapb.DataNodeClient) (interface{}, error)) (interface{}, error) {
return f(mockDataNode)
})

t.Run("NoCertPool", func(t *testing.T) {
var ErrNoCertPool = errors.New("no cert pool")
mockGrpcClient.EXPECT().SetInternalTLSCertPool(testify_mock.Anything).Return().Once()
client.(*Client).grpcClient = mockGrpcClient
client.(*Client).grpcClient.GetNodeID()
client.(*Client).grpcClient.SetInternalTLSCertPool(nil)

mockDataNode.EXPECT().GetComponentStates(testify_mock.Anything, testify_mock.Anything).Return(nil, ErrNoCertPool)

_, err := client.GetComponentStates(ctx, nil)
assert.Error(t, err)
assert.Equal(t, ErrNoCertPool, err)
})

// Sub-test for invalid certificate path
t.Run("InvalidCertPath", func(t *testing.T) {
invalidCAPath := "invalid/path/to/ca.pem"
cp, err := utils.CreateCertPoolforClient(invalidCAPath, "datanode")
assert.NotNil(t, err)
assert.Nil(t, cp)
})

// Sub-test for TLS handshake failure
t.Run("TlsHandshakeFailed", func(t *testing.T) {
cp, err := utils.CreateCertPoolforClient(validPath, "datanode")
assert.Nil(t, err)
mockDataNode.ExpectedCalls = nil

mockGrpcClient.EXPECT().SetInternalTLSCertPool(cp).Return().Once()
mockGrpcClient.EXPECT().GetNodeID().Return(1)
mockDataNode.EXPECT().GetComponentStates(testify_mock.Anything, testify_mock.Anything).Return(nil, errors.New("TLS handshake failed"))

client.(*Client).grpcClient.GetNodeID()
client.(*Client).grpcClient.SetInternalTLSCertPool(cp)

_, err = client.GetComponentStates(ctx, nil)
assert.NotNil(t, err)
assert.EqualError(t, err, "TLS handshake failed")
})

t.Run("TlsHandshakeSuccess", func(t *testing.T) {
cp, err := utils.CreateCertPoolforClient(validPath, "datanode")
assert.Nil(t, err)
mockDataNode.ExpectedCalls = nil

mockGrpcClient.EXPECT().SetInternalTLSCertPool(cp).Return().Once()
mockGrpcClient.EXPECT().GetNodeID().Return(1)
mockDataNode.EXPECT().GetComponentStates(testify_mock.Anything, testify_mock.Anything).Return(&milvuspb.ComponentStates{}, nil)

client.(*Client).grpcClient.GetNodeID()
client.(*Client).grpcClient.SetInternalTLSCertPool(cp)

componentStates, err := client.GetComponentStates(ctx, nil)
assert.Nil(t, err)
assert.NotNil(t, componentStates)
assert.IsType(t, &milvuspb.ComponentStates{}, componentStates)
})

t.Run("ContextDeadlineExceeded", func(t *testing.T) {
ctx, cancel := context.WithTimeout(ctx, 10*time.Millisecond)
defer cancel()
time.Sleep(20 * time.Millisecond)

_, err := client.GetComponentStates(ctx, nil)
assert.ErrorIs(t, err, context.DeadlineExceeded)
})
}
91 changes: 0 additions & 91 deletions internal/distributed/indexnode/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package grpcindexnodeclient

import (
"context"
"errors"
"math/rand"
"os"
"strings"
Expand All @@ -29,17 +28,13 @@ import (
"github.com/stretchr/testify/mock"
"go.uber.org/zap"

"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
"github.com/milvus-io/milvus/internal/distributed/utils"
"github.com/milvus-io/milvus/internal/mocks"
"github.com/milvus-io/milvus/internal/proto/indexpb"
"github.com/milvus-io/milvus/internal/proto/internalpb"
"github.com/milvus-io/milvus/internal/proto/workerpb"
"github.com/milvus-io/milvus/pkg/log"
"github.com/milvus-io/milvus/pkg/util/etcd"
"github.com/milvus-io/milvus/pkg/util/metricsinfo"
"github.com/milvus-io/milvus/pkg/util/paramtable"
testify_mock "github.com/stretchr/testify/mock"
)

func TestMain(m *testing.M) {
Expand Down Expand Up @@ -182,89 +177,3 @@ func TestIndexNodeClient(t *testing.T) {
err = client.Close()
assert.NoError(t, err)
}

func Test_InternalTLS_IndexNode(t *testing.T) {
paramtable.Init()
validPath := "../../../../configs/cert1/ca.pem"
ctx := context.Background()
client, err := NewClient(ctx, "test", 1, false)
assert.NoError(t, err)
assert.NotNil(t, client)
defer client.Close()

mockIndexNode := mocks.NewMockIndexNodeClient(t)
mockGrpcClient := mocks.NewMockGrpcClient[indexpb.IndexNodeClient](t)

mockGrpcClient.EXPECT().Close().Return(nil)
mockGrpcClient.EXPECT().GetNodeID().Return(1)
mockGrpcClient.EXPECT().ReCall(testify_mock.Anything, testify_mock.Anything).RunAndReturn(func(ctx context.Context, f func(indexpb.IndexNodeClient) (interface{}, error)) (interface{}, error) {
return f(mockIndexNode)
})

t.Run("NoCertPool", func(t *testing.T) {
var ErrNoCertPool = errors.New("no cert pool")
mockGrpcClient.EXPECT().SetInternalTLSCertPool(testify_mock.Anything).Return().Once()
client.(*Client).grpcClient = mockGrpcClient
client.(*Client).grpcClient.GetNodeID()
client.(*Client).grpcClient.SetInternalTLSCertPool(nil)

mockIndexNode.EXPECT().GetComponentStates(testify_mock.Anything, testify_mock.Anything).Return(nil, ErrNoCertPool)

_, err := client.GetComponentStates(ctx, nil)
assert.Error(t, err)
assert.Equal(t, ErrNoCertPool, err)
})

// Sub-test for invalid certificate path
t.Run("InvalidCertPath", func(t *testing.T) {
invalidCAPath := "invalid/path/to/ca.pem"
cp, err := utils.CreateCertPoolforClient(invalidCAPath, "indexnode")
assert.NotNil(t, err)
assert.Nil(t, cp)
})

// Sub-test for TLS handshake failure
t.Run("TlsHandshakeFailed", func(t *testing.T) {
cp, err := utils.CreateCertPoolforClient(validPath, "indexnode")
assert.Nil(t, err)
mockIndexNode.ExpectedCalls = nil

mockGrpcClient.EXPECT().SetInternalTLSCertPool(cp).Return().Once()
mockGrpcClient.EXPECT().GetNodeID().Return(1)
mockIndexNode.EXPECT().GetComponentStates(testify_mock.Anything, testify_mock.Anything).Return(nil, errors.New("TLS handshake failed"))

client.(*Client).grpcClient.GetNodeID()
client.(*Client).grpcClient.SetInternalTLSCertPool(cp)

_, err = client.GetComponentStates(ctx, nil)
assert.NotNil(t, err)
assert.EqualError(t, err, "TLS handshake failed")
})

t.Run("TlsHandshakeSuccess", func(t *testing.T) {
cp, err := utils.CreateCertPoolforClient(validPath, "indexnode")
assert.Nil(t, err)
mockIndexNode.ExpectedCalls = nil

mockGrpcClient.EXPECT().SetInternalTLSCertPool(cp).Return().Once()
mockGrpcClient.EXPECT().GetNodeID().Return(1)
mockIndexNode.EXPECT().GetComponentStates(testify_mock.Anything, testify_mock.Anything).Return(&milvuspb.ComponentStates{}, nil)

client.(*Client).grpcClient.GetNodeID()
client.(*Client).grpcClient.SetInternalTLSCertPool(cp)

componentStates, err := client.GetComponentStates(ctx, nil)
assert.Nil(t, err)
assert.NotNil(t, componentStates)
assert.IsType(t, &milvuspb.ComponentStates{}, componentStates)
})

t.Run("ContextDeadlineExceeded", func(t *testing.T) {
ctx, cancel := context.WithTimeout(ctx, 10*time.Millisecond)
defer cancel()
time.Sleep(20 * time.Millisecond)

_, err := client.GetComponentStates(ctx, nil)
assert.ErrorIs(t, err, context.DeadlineExceeded)
})
}
Loading

0 comments on commit cd19f4f

Please sign in to comment.