Skip to content

Commit

Permalink
fix: fix e2e test network topology
Browse files Browse the repository at this point in the history
Signed-off-by: huangmin <2107139596@qq.com>
  • Loading branch information
MinH-09 committed Apr 8, 2024
1 parent fc53dcf commit 9cf6a1b
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 21 deletions.
3 changes: 2 additions & 1 deletion test/e2e/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const (
)

const (
dfdaemonCompatibilityTestMode = "dfdaemon"
dfdaemonCompatibilityTestMode = "dfdaemon"
schedulerCompatibilityTestMode = "scheduler"
)

const (
Expand Down
161 changes: 161 additions & 0 deletions test/e2e/network_topology_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/*
* 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"
"os"
"strconv"
"strings"
"time"

. "github.com/onsi/ginkgo/v2" //nolint
. "github.com/onsi/gomega" //nolint

"d7y.io/dragonfly/v2/test/e2e/util"
)

var _ = Describe("Evaluator with networkTopology", func() {
Context("networkTopology", func() {
It("check networkTopology in redis", Label("networkTopology"), func() {
mode := os.Getenv("DRAGONFLY_COMPATIBILITY_E2E_TEST_MODE")
if mode == schedulerCompatibilityTestMode {
fmt.Println("networkTopology is disable, skip")
return
}
Expect(waitForProbedInNetworkTopology()).Should(BeTrue())

if waitForProbedInNetworkTopology() == true {
time.Sleep(3 * time.Minute)
Expect(checkNetworkTopologyUpdated()).Should(BeTrue())
}
})
})
})

// getRedisExec get redis pod.
func getRedisExec() *util.PodExec {
out, err := util.KubeCtlCommand("-n", dragonflyNamespace, "get", "pod", "-l", "app.kubernetes.io/name=redis",
"-o", "jsonpath='{range .items[0]}{.metadata.name}{end}'").CombinedOutput()
podName := strings.Trim(string(out), "'")
Expect(err).NotTo(HaveOccurred())
fmt.Println(podName)
Expect(strings.HasPrefix(podName, "dragonfly-redis")).Should(BeTrue())
return util.NewPodExec(dragonflyNamespace, podName, "redis")
}

func waitForProbedInNetworkTopology() bool {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()

ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()

redisPod := getRedisExec()

for {
select {
case <-ctx.Done():
return false
case <-ticker.C:
out, err := redisPod.Command("redis-cli", "-a", "dragonfly", "-n", "3", "dbsize").CombinedOutput()
Expect(err).NotTo(HaveOccurred())
key, err := strconv.Atoi(strings.Split(string(out), "\n")[1])
if key == 0 || err != nil {
continue
}

out, err = redisPod.Command("redis-cli", "-a", "dragonfly", "-n", "3", "KEYS", "scheduler:network-topology:*").CombinedOutput()
Expect(err).NotTo(HaveOccurred())
networkTopologyKey := strings.Split(string(out), "\n")[1]
if networkTopologyKey == "" || err != nil {
continue
}
networkTopologyOut, err := redisPod.Command("redis-cli", "-a", "dragonfly", "-n", "3", "HGETALL", networkTopologyKey).CombinedOutput()
Expect(err).NotTo(HaveOccurred())
if networkTopologyOut == nil || err != nil {
continue
}

out, err = redisPod.Command("redis-cli", "-a", "dragonfly", "-n", "3", "KEYS", "scheduler:probes:*").CombinedOutput()
Expect(err).NotTo(HaveOccurred())
probesKey := strings.Split(string(out), "\n")[1]
if probesKey == "" || err != nil {
continue
}
probesOut, err := redisPod.Command("redis-cli", "-a", "dragonfly", "-n", "3", "LRANGE", probesKey, "0", "-1").CombinedOutput()
Expect(err).NotTo(HaveOccurred())
if probesOut == nil || err != nil {
continue
}

out, err = redisPod.Command("redis-cli", "-a", "dragonfly", "-n", "3", "KEYS", "scheduler:probed-count:*").CombinedOutput()
Expect(err).NotTo(HaveOccurred())
probedCountKey := strings.Split(string(out), "\n")[1]
if probedCountKey == "" || err != nil {
continue
}
probedCountOut, err := redisPod.Command("redis-cli", "-a", "dragonfly", "-n", "3", "GET", probedCountKey).CombinedOutput()
Expect(err).NotTo(HaveOccurred())
if probedCountOut == nil || err != nil {
continue
}

return true
}
}
}

func checkNetworkTopologyUpdated() bool {
redisPod := getRedisExec()

out, err := redisPod.Command("redis-cli", "-a", "dragonfly", "-n", "3", "KEYS", "scheduler:network-topology:*").CombinedOutput()
networkTopologyKey := strings.Split(string(out), "\n")
Expect(err).NotTo(HaveOccurred())
for i := 1; i <= 3; i++ {
updatedAtOut, err := redisPod.Command("redis-cli", "-a", "dragonfly", "-n", "3", "HGET", networkTopologyKey[i], "updatedAt").CombinedOutput()
Expect(err).NotTo(HaveOccurred())
createdAtOut, err := redisPod.Command("redis-cli", "-a", "dragonfly", "-n", "3", "HGET", networkTopologyKey[i], "createdAt").CombinedOutput()
Expect(err).NotTo(HaveOccurred())
if strings.Split(string(updatedAtOut), "\n")[1] == strings.Split(string(createdAtOut), "\n")[1] {
return false
}
}

out, err = redisPod.Command("redis-cli", "-a", "dragonfly", "-n", "3", "KEYS", "scheduler:probed-count:*").CombinedOutput()
Expect(err).NotTo(HaveOccurred())
probedCountKey := strings.Split(string(out), "\n")
for i := 1; i <= 3; i++ {
probedCountOut, err := redisPod.Command("redis-cli", "-a", "dragonfly", "-n", "3", "GET", probedCountKey[i]).CombinedOutput()
str := string(probedCountOut)
Expect(err).NotTo(HaveOccurred())
for _, c := range str {
if c < '0' || c > '9' {
str = strings.ReplaceAll(str, string(c), "")
}
}
probedCount, err := strconv.Atoi(str)
Expect(err).NotTo(HaveOccurred())
fmt.Printf("%s probedCount: %d \n", probedCountKey[i], probedCount)
if probedCount <= 1 || probedCount >= 300 {
return false
}
}

return true
}
4 changes: 2 additions & 2 deletions test/testdata/charts/config-cache-list-metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ seedPeer:
networkTopology:
enable: true
probe:
interval: 10s
interval: 15s

dfdaemon:
image: dragonflyoss/dfdaemon
Expand Down Expand Up @@ -106,7 +106,7 @@ dfdaemon:
networkTopology:
enable: true
probe:
interval: 10s
interval: 15s
proxy:
defaultFilter: "Expires&Signature&ns"
security:
Expand Down
4 changes: 2 additions & 2 deletions test/testdata/charts/config-compatibility.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ seedPeer:
networkTopology:
enable: true
probe:
interval: 10s
interval: 15s

dfdaemon:
image: dragonflyoss/dfdaemon
Expand Down Expand Up @@ -117,7 +117,7 @@ dfdaemon:
networkTopology:
enable: true
probe:
interval: 10s
interval: 15s

manager:
image: dragonflyoss/manager
Expand Down
4 changes: 2 additions & 2 deletions test/testdata/charts/config-concurent-back-source.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ seedPeer:
networkTopology:
enable: true
probe:
interval: 10s
interval: 15s

dfdaemon:
image: dragonflyoss/dfdaemon
Expand Down Expand Up @@ -125,7 +125,7 @@ dfdaemon:
networkTopology:
enable: true
probe:
interval: 10s
interval: 15s

manager:
image: dragonflyoss/manager
Expand Down
2 changes: 1 addition & 1 deletion test/testdata/charts/config-disable-seed-peer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ dfdaemon:
networkTopology:
enable: true
probe:
interval: 10s
interval: 15s

manager:
image: dragonflyoss/manager
Expand Down
4 changes: 2 additions & 2 deletions test/testdata/charts/config-grpc-tls-ipv6.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ seedPeer:
networkTopology:
enable: true
probe:
interval: 10s
interval: 15s
security:
autoIssueCert: true
tlsVerify: true
Expand Down Expand Up @@ -203,7 +203,7 @@ dfdaemon:
networkTopology:
enable: true
probe:
interval: 10s
interval: 15s
security:
autoIssueCert: true
tlsVerify: true
Expand Down
4 changes: 2 additions & 2 deletions test/testdata/charts/config-grpc-tls.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ seedPeer:
networkTopology:
enable: true
probe:
interval: 10s
interval: 15s
security:
autoIssueCert: true
tlsVerify: true
Expand Down Expand Up @@ -185,7 +185,7 @@ dfdaemon:
networkTopology:
enable: true
probe:
interval: 10s
interval: 15s
proxy:
defaultFilter: "Expires&Signature&ns"
security:
Expand Down
4 changes: 2 additions & 2 deletions test/testdata/charts/config-ipv6.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ seedPeer:
networkTopology:
enable: true
probe:
interval: 10s
interval: 15s

dfdaemon:
image: dragonflyoss/dfdaemon
Expand Down Expand Up @@ -123,7 +123,7 @@ dfdaemon:
networkTopology:
enable: true
probe:
interval: 10s
interval: 15s

manager:
image: dragonflyoss/manager
Expand Down
4 changes: 2 additions & 2 deletions test/testdata/charts/config-split-running-tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ seedPeer:
networkTopology:
enable: true
probe:
interval: 10s
interval: 15s

dfdaemon:
image: dragonflyoss/dfdaemon
Expand Down Expand Up @@ -118,7 +118,7 @@ dfdaemon:
networkTopology:
enable: true
probe:
interval: 10s
interval: 15s

manager:
image: dragonflyoss/manager
Expand Down
6 changes: 3 additions & 3 deletions test/testdata/charts/config-write-buffer-size.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ seedPeer:
writeBufferSize: 1Mi
download:
prefetch: true
networkTopology:
networkTopology:
enable: true
probe:
interval: 10s
interval: 15s

dfdaemon:
image: dragonflyoss/dfdaemon
Expand Down Expand Up @@ -121,7 +121,7 @@ dfdaemon:
networkTopology:
enable: true
probe:
interval: 10s
interval: 15s

manager:
image: dragonflyoss/manager
Expand Down
4 changes: 2 additions & 2 deletions test/testdata/charts/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ seedPeer:
networkTopology:
enable: true
probe:
interval: 10s
interval: 15s

dfdaemon:
image: dragonflyoss/dfdaemon
Expand Down Expand Up @@ -117,7 +117,7 @@ dfdaemon:
networkTopology:
enable: true
probe:
interval: 10s
interval: 15s

manager:
image: dragonflyoss/manager
Expand Down

0 comments on commit 9cf6a1b

Please sign in to comment.