Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions .github/workflows/func-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ env:
jobs:
prepare:
name: Prepare
runs-on: ubuntu-24.04
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v7
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:

test:
name: Test
runs-on: ubuntu-24.04
runs-on: ubuntu-latest
needs: [ prepare ]
strategy:
matrix:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ permissions:
jobs:
golangci:
name: lint
runs-on: ubuntu-24.04
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v7
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/jepsen-cluster-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ env:
jobs:
test:
name: Test
runs-on: ubuntu-24.04
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v7
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/jepsen-sentinel-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ env:
jobs:
test:
name: Test
runs-on: ubuntu-24.04
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v7
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env:
jobs:
unittest:
name: all_unittests
runs-on: ubuntu-24.04
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v7
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ unittests:
go test ./cmd/... ./tests/testutil/matchers/

valkey/src/valkey-server:
docker run --rm -v ${CURDIR}:/app -w /app ubuntu:noble /app/valkey_patches/build.sh
docker run --rm -v ${CURDIR}:/app -w /app ubuntu:resolute /app/valkey_patches/build.sh

test: base_image valkey/src/valkey-server cmd/rdsync/rdsync recreate_logs
rm -rf ./tests/images/valkey/rdsync && cp cmd/rdsync/rdsync ./tests/images/valkey/rdsync
Expand Down
2 changes: 1 addition & 1 deletion tests/images/base/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:noble
FROM ubuntu:resolute
ENV container=docker
ENV DEBIAN_FRONTEND=noninteractive
COPY . /var/lib/dist/base
Expand Down
2 changes: 1 addition & 1 deletion tests/images/base/generate_certs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Jl8tzMujbHNHhw+OQAQOPHi6EUPs/H37euj3G7oBaVUwXJq3Tbwg95W5Jih+CgTB
Sbe6eYpR/j/SYGwbS6/DbHi3IjvblN+2pSPI05JvXMhLC/lAeqcdVJAgTvw=
-----END RSA PRIVATE KEY-----" > /etc/zk-ssl/ca.key

openssl genrsa -out /etc/zk-ssl/server.key -passout pass:testpassword123 4096
openssl genrsa -out /etc/zk-ssl/server.key -passout pass:testpassword123 2048
openssl req -new -key /etc/zk-ssl/server.key -out /etc/zk-ssl/server.csr -passin pass:testpassword123 -subj "/C=RU/ST=Test/L=Test/O=Test/OU=Test/CN=${FQDN}"
echo "[SAN]
subjectAltName = @alt_names
Expand Down
2 changes: 1 addition & 1 deletion tests/images/base/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ln -sf /usr/sbin/iptables-legacy /usr/sbin/iptables

mkdir -p /run/sshd
cp /var/lib/dist/base/sshd_config /etc/ssh/sshd_config
mkdir /root/.ssh
mkdir -p /root/.ssh
chmod 0700 /root/.ssh
yes | ssh-keygen -t rsa -N '' -f /root/.ssh/id_rsa
cp /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys
Expand Down
2 changes: 1 addition & 1 deletion tests/images/valkey/setup_cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ supervisorctl start valkey
if [ "${MASTER}" != "" ]
then
valkey-cli -e -a functestpassword -p 6379 config set offline no
master_addr=$(host ${MASTER} | awk '{print $NF}')
master_addr=$(host ${MASTER} | awk '/has address/ {print $NF; exit}')
valkey-cli -e -a functestpassword -p 6379 cluster meet ${master_addr} 6379
master_id=$(valkey-cli -e -a functestpassword -h ${master_addr} -p 6379 cluster myid)
tries=0
Expand Down
2 changes: 1 addition & 1 deletion tests/images/valkey/setup_sentinel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ MASTER=${1}
if [ "${MASTER}" != "" ]
then
valkey-cli -e -a functestpassword -p 6379 config set offline no
master_addr=$(host ${MASTER} | awk '{print $NF}')
master_addr=$(host ${MASTER} | awk '/has address/ {print $NF; exit}')
valkey-cli -e -a functestpassword -p 6379 replicaof ${master_addr} 6379
valkey-cli -e -a functestpassword -p 6379 config rewrite
tries=0
Expand Down
62 changes: 45 additions & 17 deletions tests/rdsync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,18 @@ func newTestContext() (*testContext, error) {
}

func (tctx *testContext) saveLogs(scenario string) error {
var retVal error
for _, service := range tctx.composer.Services() {
logdir := filepath.Join("logs", scenario, service)
if err := os.MkdirAll(logdir, 0755); err != nil {
return err
}
if containerLogs, err := tctx.composer.GetLogs(service); err == nil {
_ = os.WriteFile(filepath.Join(logdir, "docker.log"), []byte(containerLogs), 0644)
} else {
log.Printf("failed to save docker logs of %s: %v", service, err)
retVal = err
}
var logsToSave map[string]string
switch {
case strings.HasPrefix(service, valkeyName):
Expand All @@ -97,29 +108,28 @@ func (tctx *testContext) saveLogs(scenario string) error {
default:
continue
}
logdir := filepath.Join("logs", scenario, service)
err := os.MkdirAll(logdir, 0755)
if err != nil {
return err
}
for remotePath, localPath := range logsToSave {
remoteFile, err := tctx.composer.GetFile(service, remotePath)
if err != nil {
return err
log.Printf("failed to fetch %s from %s: %v", remotePath, service, err)
continue
}
defer func() { _ = remoteFile.Close() }()
localFile, err := os.OpenFile(filepath.Join(logdir, localPath), os.O_RDWR|os.O_CREATE, 0644)
if err != nil {
return err
_ = remoteFile.Close()
log.Printf("failed to open local file for %s: %v", localPath, err)
continue
}
defer func() { _ = localFile.Close() }()
_, err = io.Copy(localFile, remoteFile)
_ = remoteFile.Close()
_ = localFile.Close()
if err != nil {
return err
log.Printf("failed to copy %s from %s: %v", remotePath, service, err)
retVal = err
}
}
}
return nil
return retVal
}

func (tctx *testContext) templateStep(step *godog.Step) error {
Expand Down Expand Up @@ -449,18 +459,27 @@ func (tctx *testContext) stepClusteredShardIsUpAndRunning() error {
if err != nil {
return err
}
_, _, err = tctx.composer.RunCommand("valkey1", "setup_cluster.sh", 1*time.Minute)
retcode, out, err := tctx.composer.RunCommand("valkey1", "setup_cluster.sh", 5*time.Minute)
if err != nil {
return err
}
_, _, err = tctx.composer.RunCommand("valkey2", "setup_cluster.sh valkey1", 1*time.Minute)
if retcode != 0 {
return fmt.Errorf("setup_cluster.sh failed on valkey1: %s", out)
}
retcode, out, err = tctx.composer.RunCommand("valkey2", "setup_cluster.sh valkey1", 5*time.Minute)
if err != nil {
return err
}
_, _, err = tctx.composer.RunCommand("valkey3", "setup_cluster.sh valkey1", 1*time.Minute)
if retcode != 0 {
return fmt.Errorf("setup_cluster.sh failed on valkey2: %s", out)
}
retcode, out, err = tctx.composer.RunCommand("valkey3", "setup_cluster.sh valkey1", 5*time.Minute)
if err != nil {
return err
}
if retcode != 0 {
return fmt.Errorf("setup_cluster.sh failed on valkey3: %s", out)
}

// check valkey nodes
for _, service := range tctx.composer.Services() {
Expand All @@ -484,18 +503,27 @@ func (tctx *testContext) stepSentinelShardIsUpAndRunning() error {
if err != nil {
return err
}
_, _, err = tctx.composer.RunCommand("valkey1", "setup_sentinel.sh", 1*time.Minute)
retcode, out, err := tctx.composer.RunCommand("valkey1", "setup_sentinel.sh", 5*time.Minute)
if err != nil {
return err
}
_, _, err = tctx.composer.RunCommand("valkey2", "setup_sentinel.sh valkey1", 1*time.Minute)
if retcode != 0 {
return fmt.Errorf("setup_sentinel.sh failed on valkey1: %s", out)
}
retcode, out, err = tctx.composer.RunCommand("valkey2", "setup_sentinel.sh valkey1", 5*time.Minute)
if err != nil {
return err
}
_, _, err = tctx.composer.RunCommand("valkey3", "setup_sentinel.sh valkey1", 1*time.Minute)
if retcode != 0 {
return fmt.Errorf("setup_sentinel.sh failed on valkey2: %s", out)
}
retcode, out, err = tctx.composer.RunCommand("valkey3", "setup_sentinel.sh valkey1", 5*time.Minute)
if err != nil {
return err
}
if retcode != 0 {
return fmt.Errorf("setup_sentinel.sh failed on valkey3: %s", out)
}
// check valkey nodes
for _, service := range tctx.composer.Services() {
if strings.HasPrefix(service, valkeyName) {
Expand Down
40 changes: 40 additions & 0 deletions tests/testutil/docker_composer.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ type Composer interface {
RunAsyncCommand(service, cmd string) error
// Returns content of the file from container by path
GetFile(service, path string) (io.ReadCloser, error)
// Returns container stdout/stderr (docker logs) for given service
GetLogs(service string) (string, error)
}

// DockerComposer is a Composer implementation based on docker and docker-compose
Expand Down Expand Up @@ -467,6 +469,44 @@ func (dc *DockerComposer) UnBlockHostConnections(service, host string) error {
return nil
}

// GetLogs returns container stdout/stderr for given service
func (dc *DockerComposer) GetLogs(service string) (string, error) {
cont, ok := dc.containers[service]
if !ok {
return "", fmt.Errorf("no such service: %s", service)
}
logsResult, err := dc.api.ContainerLogs(context.Background(), cont.ID, client.ContainerLogsOptions{
ShowStdout: true,
ShowStderr: true,
})
if err != nil {
return "", err
}
defer logsResult.Close()
logs, err := io.ReadAll(logsResult)
if err != nil {
return "", err
}
return demuxDockerLogs(logs), nil
}

func demuxDockerLogs(logs []byte) string {
var out strings.Builder
for len(logs) > 0 {
if len(logs) < 8 {
out.Write(logs)
break
}
payloadLen := int(logs[4])<<24 | int(logs[5])<<16 | int(logs[6])<<8 | int(logs[7])
if 8+payloadLen > len(logs) {
payloadLen = len(logs) - 8
}
out.Write(logs[8 : 8+payloadLen])
logs = logs[8+payloadLen:]
}
return out.String()
}

func newUntarReaderCloser(reader io.ReadCloser) (io.ReadCloser, error) {
tarReader := tar.NewReader(reader)
_, err := tarReader.Next()
Expand Down
4 changes: 2 additions & 2 deletions valkey_patches/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -xe

apt update
DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt -y install build-essential git
DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt -y install build-essential git libssl-dev
cd /app
git clone https://github.com/valkey-io/valkey.git
cd valkey
Expand All @@ -14,4 +14,4 @@ do
git apply "${i}"
done

make -j
make BUILD_TLS=yes -j
Loading