From bd92139848b5c2de50aec9cd4a4db0c3f96c22a9 Mon Sep 17 00:00:00 2001 From: BruceAko Date: Sun, 22 Sep 2024 18:02:41 +0800 Subject: [PATCH] feat: add E2E tests for cases that peers going offline Signed-off-by: BruceAko --- .../template/scheduler.template.yaml | 2 +- pkg/rpc/scheduler/client/client_v1.go | 2 +- test/e2e/v2/leave_host_test.go | 39 +++++++++++++++++++ test/testdata/charts/config-v2.yaml | 1 + 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 test/e2e/v2/leave_host_test.go diff --git a/deploy/docker-compose/template/scheduler.template.yaml b/deploy/docker-compose/template/scheduler.template.yaml index c7e5d33c692..0eb27b47d52 100644 --- a/deploy/docker-compose/template/scheduler.template.yaml +++ b/deploy/docker-compose/template/scheduler.template.yaml @@ -61,7 +61,7 @@ scheduler: # then the task will also be reclaimed. taskGCInterval: 30m # hostGCInterval is the interval of host gc. - hostGCInterval: 6h + hostGCInterval: 5m # hostTTL is time to live of host. If host announces message to scheduler, # then HostTTl will be reset. hostTTL: 1h diff --git a/pkg/rpc/scheduler/client/client_v1.go b/pkg/rpc/scheduler/client/client_v1.go index badbcf8e47f..00ad33603c7 100644 --- a/pkg/rpc/scheduler/client/client_v1.go +++ b/pkg/rpc/scheduler/client/client_v1.go @@ -90,7 +90,7 @@ func GetV1(ctx context.Context, dynconfig config.Dynconfig, opts ...grpc.DialOpt }, nil } -// GetV1ByAddr returns v2 version of the scheduler client by address. +// GetV1ByAddr returns v1 version of the scheduler client by address. func GetV1ByAddr(ctx context.Context, target string, opts ...grpc.DialOption) (V1, error) { conn, err := grpc.DialContext( ctx, diff --git a/test/e2e/v2/leave_host_test.go b/test/e2e/v2/leave_host_test.go new file mode 100644 index 00000000000..1bc8e17aa00 --- /dev/null +++ b/test/e2e/v2/leave_host_test.go @@ -0,0 +1,39 @@ +/* + * Copyright 2024 The Dragonfly Authors + * + * Licensed 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 e2e + +import ( + "context" + "fmt" + + schedulerclient "d7y.io/dragonfly/v2/pkg/rpc/scheduler/client" + . "github.com/onsi/ginkgo/v2" //nolint + . "github.com/onsi/gomega" //nolint + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" +) + +var _ = Describe("Clients go offline normally and abnormally", func() { + Context("scheduler clears peer metadata", func() { + It("number of hosts should be ok", Label("host", "leave"), func() { + grpcCredentials := insecure.NewCredentials() + schedulerClient, err := schedulerclient.GetV2ByAddr(context.Background(), "127.0.0.1:8002", grpc.WithTransportCredentials(grpcCredentials)) + Expect(err).NotTo(HaveOccurred()) + fmt.Println(schedulerClient) + }) + }) +}) diff --git a/test/testdata/charts/config-v2.yaml b/test/testdata/charts/config-v2.yaml index 230e4ba8e7d..3e7896527a1 100644 --- a/test/testdata/charts/config-v2.yaml +++ b/test/testdata/charts/config-v2.yaml @@ -96,6 +96,7 @@ seedClient: client: enable: true + replicas: 3 image: repository: dragonflyoss/client tag: latest