Skip to content

Commit 8817386

Browse files
suxb201claude
andcommitted
feat: add macOS local test support and fix cluster test robustness
1. Fix build.sh to use GO_LDFLAGS instead of LDFLAGS to avoid conflicts with Homebrew's LDFLAGS environment variable (e.g., from flex package) 2. Add test_local.sh for easy local testing on macOS/Linux - Automatically detects Redis version from PATH - Runs tests without modules flag (suitable for Homebrew Redis) 3. Improve cluster test robustness in tests/helpers/cluster.py - Add _wait_cluster_ready() method that verifies writes work on all slots - This prevents CLUSTERDOWN errors caused by cluster gossip not fully propagating before tests start writing Usage: ./test_local.sh # Run all tests ./test_local.sh cases/rdb.py # Run specific test file Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent cf2ffd8 commit 8817386

3 files changed

Lines changed: 64 additions & 3 deletions

File tree

build.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ if git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
1515
else
1616
COMMIT=${COMMIT:-"unknown"}
1717
fi
18-
LDFLAGS=${LDFLAGS:-"-X main.Version=${VERSION} -X main.GitCommit=${COMMIT}"}
18+
# Use GO_LDFLAGS to avoid conflict with system LDFLAGS (e.g., from Homebrew)
19+
GO_LDFLAGS="-X main.Version=${VERSION} -X main.GitCommit=${COMMIT}"
1920

2021
dist() {
2122
echo "try build GOOS=$1 GOARCH=$2"
2223
export GOOS=$1
2324
export GOARCH=$2
2425
export CGO_ENABLED=0
25-
go build -v -trimpath -ldflags "${LDFLAGS}" -o "$BIN_DIR/redis-shake" "./cmd/redis-shake"
26+
go build -v -trimpath -ldflags "${GO_LDFLAGS}" -o "$BIN_DIR/redis-shake" "./cmd/redis-shake"
2627
unset GOOS
2728
unset GOARCH
2829
echo "build success GOOS=$1 GOARCH=$2"
@@ -43,5 +44,5 @@ fi
4344

4445
# build the current platform
4546
echo "try build for current platform"
46-
go build -v -trimpath -ldflags "${LDFLAGS}" -o "$BIN_DIR/redis-shake" "./cmd/redis-shake"
47+
go build -v -trimpath -ldflags "${GO_LDFLAGS}" -o "$BIN_DIR/redis-shake" "./cmd/redis-shake"
4748
echo "build success"

test_local.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
# Local test script for macOS/Linux
3+
# Usage: ./test_local.sh [file_or_dir] [pybbt_args...]
4+
# Examples:
5+
# ./test_local.sh # Run all tests
6+
# ./test_local.sh cases/rdb.py # Run specific test file
7+
8+
set -e
9+
10+
echo "=== Building redis-shake ==="
11+
sh build.sh
12+
13+
echo ""
14+
echo "=== Running unit tests ==="
15+
go test ./... -v
16+
17+
echo ""
18+
echo "=== Running black box tests ==="
19+
cd tests/
20+
21+
# Check if redis-server is available
22+
if ! command -v redis-server &> /dev/null; then
23+
echo "Error: redis-server not found in PATH"
24+
echo "Install with: brew install redis (macOS) or apt install redis (Linux)"
25+
exit 1
26+
fi
27+
28+
# Show Redis version
29+
REDIS_VERSION=$(redis-server --version 2>&1 | head -1)
30+
echo "Redis server: $REDIS_VERSION"
31+
32+
# Run tests without modules flag (suitable for Homebrew/system Redis)
33+
# Default to running all cases if no argument provided
34+
TEST_TARGET="${1:-cases}"
35+
shift 2>/dev/null || true
36+
37+
pybbt "$TEST_TARGET" --verbose "$@"

tests/helpers/cluster.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import time
2+
13
import pybbt as p
24
import redis
35
from redis.cluster import ClusterNode
@@ -20,9 +22,30 @@ def __init__(self):
2022
ClusterNode(self.nodes[1].host, self.nodes[1].port)
2123
], require_full_coverage=True)
2224
p.ASSERT_EQ_TIMEOUT(lambda: self.client.cluster_info()["cluster_state"], "ok", 10)
25+
26+
# Wait for all nodes to be connected and cluster is truly ready
27+
self._wait_cluster_ready()
28+
2329
p.log(f"cluster started at {self.nodes[0].get_address()}")
2430
p.log(self.client.cluster_nodes())
2531

32+
def _wait_cluster_ready(self, timeout=10):
33+
"""Wait for cluster to be fully ready by verifying writes work on all slots."""
34+
start = time.time()
35+
test_key = 0
36+
while time.time() - start < timeout:
37+
try:
38+
# Try to write to keys that map to different slots
39+
# Key "key0" maps to slot 5798 (node 0), "key8192" maps to slot 12103 (node 1)
40+
self.client.set("__cluster_ready_test_0__", "ok")
41+
self.client.set("__cluster_ready_test_8192__", "ok")
42+
self.client.delete("__cluster_ready_test_0__", "__cluster_ready_test_8192__")
43+
return # Success - cluster is ready
44+
except Exception as e:
45+
p.log(f"Cluster not ready yet: {e}")
46+
time.sleep(0.1)
47+
raise TimeoutError(f"Cluster not ready after {timeout} seconds")
48+
2649
def do(self, *args):
2750
try:
2851
ret = self.client.execute_command(*args)

0 commit comments

Comments
 (0)