Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RE tests #2847

Merged
merged 11 commits into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .github/workflows/test-redis-enterprise.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: RE Tests

on:
push:
branches: [master, v9]
pull_request:
branches: [master, v9]

permissions:
contents: read

jobs:
build:
name: build
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
go-version: [1.21.x]
re-build: ["100.0.1-64402"]
# go-version: [1.19.x, 1.20.x, 1.21.x]

steps:
- name: Clone Redis EE docker repository
run: |
git clone https://github.com/RedisLabs/redis-ee-docker.git redis-ee
- name: Install Docker-compose
run: |
DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
mkdir -p $DOCKER_CONFIG/cli-plugins
curl -SL https://github.com/docker/compose/releases/download/v2.23.3/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose
- name: Build cluster
env:
IMAGE: "redislabs/redis-internal:${{ matrix.re-build }}"
RE_USERNAME: test@test.com
RE_PASS: 12345
RE_CLUSTER_NAME: test
OSS_CLUSTER: false
DB_PORT: 6379
DOCKER_ACCESS_TOKEN: ${{ secrets.DOCKER_ACCESS_TOKEN }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
run: |
cd redis-ee/
./build.sh

- name: Checkout repository
uses: actions/checkout@v3

- name: Set up ${{ matrix.go-version }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v4

- name: Test
env:
RE_CLUSTER: "1"
run: |
go test \
--ginkgo.skip-file="ring_test.go" \
--ginkgo.skip-file="sentinel_test.go" \
--ginkgo.skip-file="osscluster_test.go" \
--ginkgo.skip-file="pubsub_test.go" \
--ginkgo.label-filter='!NonRedisEnterprise'
6 changes: 3 additions & 3 deletions commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ var _ = Describe("Commands", func() {
Expect(configSet.Val()).To(Equal("OK"))
})

It("should ConfigRewrite", func() {
It("should ConfigRewrite", Label("NonRedisEnterprise"), func() {
configRewrite := client.ConfigRewrite(ctx)
Expect(configRewrite.Err()).NotTo(HaveOccurred())
Expect(configRewrite.Val()).To(Equal("OK"))
Expand Down Expand Up @@ -393,7 +393,7 @@ var _ = Describe("Commands", func() {
Expect(tm).To(BeTemporally("~", time.Now(), 3*time.Second))
})

It("should Command", func() {
It("should Command", Label("NonRedisEnterprise"), func() {
cmds, err := client.Command(ctx).Result()
Expect(err).NotTo(HaveOccurred())
Expect(len(cmds)).To(BeNumerically("~", 240, 25))
Expand Down Expand Up @@ -2027,7 +2027,7 @@ var _ = Describe("Commands", func() {
Expect(dryRun.Val()).To(Equal("OK"))
})

It("should fail module loadex", func() {
It("should fail module loadex", Label("NonRedisEnterprise"), func() {
dryRun := client.ModuleLoadex(ctx, &redis.ModuleLoadexConfig{
Path: "/path/to/non-existent-library.so",
Conf: map[string]interface{}{
Expand Down
81 changes: 55 additions & 26 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strconv"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -64,6 +65,8 @@ var cluster = &clusterScenario{
clients: make(map[string]*redis.Client, 6),
}

var RECluster = false

func registerProcess(port string, p *redisProcess) {
if processes == nil {
processes = make(map[string]*redisProcess)
Expand All @@ -78,47 +81,56 @@ var _ = BeforeSuite(func() {
redisAddr = ":" + redisPort
}
var err error
RECluster, _ = strconv.ParseBool(os.Getenv("RE_CLUSTER"))

if !RECluster {

redisMain, err = startRedis(redisPort)
Expect(err).NotTo(HaveOccurred())
redisMain, err = startRedis(redisPort)
Expect(err).NotTo(HaveOccurred())

ringShard1, err = startRedis(ringShard1Port)
Expect(err).NotTo(HaveOccurred())
ringShard1, err = startRedis(ringShard1Port)
Expect(err).NotTo(HaveOccurred())

ringShard2, err = startRedis(ringShard2Port)
Expect(err).NotTo(HaveOccurred())
ringShard2, err = startRedis(ringShard2Port)
Expect(err).NotTo(HaveOccurred())

ringShard3, err = startRedis(ringShard3Port)
Expect(err).NotTo(HaveOccurred())
ringShard3, err = startRedis(ringShard3Port)
Expect(err).NotTo(HaveOccurred())

sentinelMaster, err = startRedis(sentinelMasterPort)
Expect(err).NotTo(HaveOccurred())
sentinelMaster, err = startRedis(sentinelMasterPort)
Expect(err).NotTo(HaveOccurred())

sentinel1, err = startSentinel(sentinelPort1, sentinelName, sentinelMasterPort)
Expect(err).NotTo(HaveOccurred())
sentinel1, err = startSentinel(sentinelPort1, sentinelName, sentinelMasterPort)
Expect(err).NotTo(HaveOccurred())

sentinel2, err = startSentinel(sentinelPort2, sentinelName, sentinelMasterPort)
Expect(err).NotTo(HaveOccurred())
sentinel2, err = startSentinel(sentinelPort2, sentinelName, sentinelMasterPort)
Expect(err).NotTo(HaveOccurred())

sentinel3, err = startSentinel(sentinelPort3, sentinelName, sentinelMasterPort)
Expect(err).NotTo(HaveOccurred())
sentinel3, err = startSentinel(sentinelPort3, sentinelName, sentinelMasterPort)
Expect(err).NotTo(HaveOccurred())

sentinelSlave1, err = startRedis(
sentinelSlave1Port, "--slaveof", "127.0.0.1", sentinelMasterPort)
Expect(err).NotTo(HaveOccurred())
sentinelSlave1, err = startRedis(
sentinelSlave1Port, "--slaveof", "127.0.0.1", sentinelMasterPort)
Expect(err).NotTo(HaveOccurred())

sentinelSlave2, err = startRedis(
sentinelSlave2Port, "--slaveof", "127.0.0.1", sentinelMasterPort)
Expect(err).NotTo(HaveOccurred())
sentinelSlave2, err = startRedis(
sentinelSlave2Port, "--slaveof", "127.0.0.1", sentinelMasterPort)
Expect(err).NotTo(HaveOccurred())

Expect(startCluster(ctx, cluster)).NotTo(HaveOccurred())
Expect(startCluster(ctx, cluster)).NotTo(HaveOccurred())
} else {
redisPort = rediStackPort
redisAddr = rediStackAddr
}
})

var _ = AfterSuite(func() {
Expect(cluster.Close()).NotTo(HaveOccurred())
if !RECluster {
Expect(cluster.Close()).NotTo(HaveOccurred())

for _, p := range processes {
Expect(p.Close()).NotTo(HaveOccurred())
for _, p := range processes {
Expect(p.Close()).NotTo(HaveOccurred())
}
}
processes = nil
})
Expand All @@ -131,6 +143,23 @@ func TestGinkgoSuite(t *testing.T) {
//------------------------------------------------------------------------------

func redisOptions() *redis.Options {
if RECluster {
return &redis.Options{
Addr: redisAddr,
DB: 0,

DialTimeout: 10 * time.Second,
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
ContextTimeoutEnabled: true,

MaxRetries: -1,
PoolSize: 10,

PoolTimeout: 30 * time.Second,
ConnMaxIdleTime: time.Minute,
}
}
return &redis.Options{
Addr: redisAddr,
DB: 15,
Expand Down
8 changes: 6 additions & 2 deletions race_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ var _ = Describe("races", func() {

n, err := client.Get(ctx, "db").Int64()
Expect(err).NotTo(HaveOccurred())
Expect(n).To(Equal(int64(1)))
if RECluster {
Expect(n).To(Equal(int64(0)))
} else {
Expect(n).To(Equal(int64(1)))
}
})

It("should select DB with read timeout", func() {
Expand Down Expand Up @@ -243,7 +247,7 @@ var _ = Describe("races", func() {
})
})

var _ = Describe("cluster races", func() {
var _ = Describe("cluster races", Label("NonRedisEnterprise"), func() {
var client *redis.ClusterClient
var C, N int

Expand Down
6 changes: 5 additions & 1 deletion redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ var _ = Describe("Client", func() {
})

It("should Stringer", func() {
Expect(client.String()).To(Equal(fmt.Sprintf("Redis<:%s db:15>", redisPort)))
if RECluster {
Expect(client.String()).To(Equal(fmt.Sprintf("Redis<:%s db:0>", redisPort)))
} else {
Expect(client.String()).To(Equal(fmt.Sprintf("Redis<:%s db:15>", redisPort)))
}
})

It("supports context", func() {
Expand Down
2 changes: 1 addition & 1 deletion universal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var _ = Describe("UniversalClient", func() {
Expect(client.Ping(ctx).Err()).NotTo(HaveOccurred())
})

It("should connect to clusters", func() {
It("should connect to clusters", Label("NonRedisEnterprise"), func() {
client = redis.NewUniversalClient(&redis.UniversalOptions{
Addrs: cluster.addrs(),
})
Expand Down
Loading