Skip to content

Commit

Permalink
update example utils to use randomized cluster nodes
Browse files Browse the repository at this point in the history
Signed-off-by: jbrinkman <[email protected]>
  • Loading branch information
jbrinkman committed Feb 21, 2025
1 parent 794049e commit 0b3b79f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
6 changes: 3 additions & 3 deletions go/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,17 @@ stop-redis-cluster:
var-test:
@OUTPUT=$$(python3 ../utils/cluster_manager.py start --cluster-mode); \
GLIDE_CLUSTER_NODES=$$(echo "$$OUTPUT" | grep 'CLUSTER_NODES=' | cut -d'=' -f2); \
echo "=================================================="; \
echo $$GLIDE_CLUSTER_NODES

# example tests - skip complete IT suite (including MT)
example-test:
mkdir -p reports
set -o pipefail; \
../utils/cluster_manager.py start -p 6379 -r 0
../utils/cluster_manager.py start --cluster-mode -p 7001 7002 7003 7004 7005 7006
@OUTPUT=$$(python3 ../utils/cluster_manager.py start --cluster-mode); \
GLIDE_CLUSTER_NODES=$$(echo "$$OUTPUT" | grep 'CLUSTER_NODES=' | cut -d'=' -f2); \
LD_LIBRARY_PATH=$(shell find . -name libglide_rs.a|grep -w release|tail -1|xargs dirname|xargs readlink -f):${LD_LIBRARY_PATH} \
go test -v -race ./api -skip Test $(if $(test-filter), -run $(test-filter)) -standalonenode 127.0.0.1:6379 -clusternodes 127.0.0.1:7006,127.0.0.1:7004,127.0.0.1:7001,127.0.0.1:7002,127.0.0.1:7003,127.0.0.1:7005 \
go test -v ./api -skip Test $(if $(test-filter), -run $(test-filter)) -clusternodes $$GLIDE_CLUSTER_NODES \
| tee >(go tool test2json -t -p github.com/valkey-io/valkey-glide/go/api \
| go-test-report -o reports/example-tests.html -t example-test > /dev/null)

Expand Down
23 changes: 21 additions & 2 deletions go/api/example_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ package api
import (
"flag"
"fmt"
"strconv"
"strings"
"sync"
)

var clusterNodes = flag.String("clusternodes", "", "AddressNodes for running Valkey/Redis cluster nodes")
var standaloneNode = flag.String("standalonenode", "", "Address for running Valkey/Redis standalone node")

var clusterClient *GlideClusterClient
var clusterOnce sync.Once
Expand Down Expand Up @@ -51,8 +52,9 @@ func getExampleGlideClient() *GlideClient {

func getExampleGlideClusterClient() *GlideClusterClient {
clusterOnce.Do(func() {
addresses := parseHosts(*clusterNodes)
config := NewGlideClusterClientConfiguration().
WithAddress(&NodeAddress{Host: "localhost", Port: 7001}).
WithAddress(&addresses[0]).
WithRequestTimeout(5000)

client, err := NewGlideClusterClient(config)
Expand All @@ -71,3 +73,20 @@ func getExampleGlideClusterClient() *GlideClusterClient {

return clusterClient
}

func parseHosts(addresses string) []NodeAddress {
var result []NodeAddress

addressList := strings.Split(addresses, ",")
for _, address := range addressList {
parts := strings.Split(address, ":")
port, err := strconv.Atoi(parts[1])
if err != nil {
fmt.Printf("Failed to parse port from string %s: %s", parts[1], err.Error())
continue
}

result = append(result, NodeAddress{Host: parts[0], Port: port})
}
return result
}

0 comments on commit 0b3b79f

Please sign in to comment.