-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
215 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Test Sentinel | ||
|
||
on: [push, pull_request] | ||
|
||
permissions: | ||
contents: read | ||
|
||
env: | ||
CONSOLE_OUTPUT: XTerm | ||
|
||
jobs: | ||
test: | ||
name: ${{matrix.ruby}} on ${{matrix.os}} | ||
runs-on: ${{matrix.os}}-latest | ||
continue-on-error: ${{matrix.experimental}} | ||
|
||
strategy: | ||
matrix: | ||
os: | ||
- ubuntu | ||
|
||
ruby: | ||
- "3.1" | ||
- "3.2" | ||
- "3.3" | ||
|
||
experimental: [false] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Install Docker Compose | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y docker-compose | ||
- name: Run tests | ||
timeout-minutes: 10 | ||
env: | ||
RUBY_VERSION: ${{matrix.ruby}} | ||
run: docker-compose -f sentinel/docker-compose.yaml up tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
services: | ||
redis-master: | ||
image: redis | ||
redis-slave: | ||
image: redis | ||
command: redis-server --slaveof redis-master 6379 | ||
depends_on: | ||
- redis-master | ||
redis-sentinel: | ||
image: redis | ||
command: redis-sentinel /etc/redis/sentinel.conf | ||
volumes: | ||
- ./sentinel.conf:/etc/redis/sentinel.conf | ||
depends_on: | ||
- redis-master | ||
- redis-slave | ||
tests: | ||
image: ruby:${RUBY_VERSION:-latest} | ||
volumes: | ||
- ../:/code | ||
command: bash -c "cd /code && bundle install && bundle exec sus sentinel/test" | ||
depends_on: | ||
- redis-master | ||
- redis-slave | ||
- redis-sentinel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Sentinel Testing | ||
|
||
To test sentinels, you need to set up master, slave and sentinel instances. | ||
|
||
## Setup | ||
|
||
``` bash | ||
$ docker-compose -f config/sentinel/docker-compose.yaml up -d | ||
[+] Running 3/3 | ||
✔ Container sentinel-redis-master-1 Running 0.0s | ||
✔ Container sentinel-redis-slave-1 Running 0.0s | ||
✔ Container sentinel-redis-sentinel-1 Started 0.2s | ||
``` | ||
|
||
## Test | ||
|
||
``` bash | ||
$ ASYNC_REDIS_MASTER=redis://redis-master:6379 ASYNC_REDIS_SLAVE=redis://redis-slave:6379 ASYNC_REDIS_SENTINEL=redis://redis-sentinel:26379 bundle exec sus | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
port 26379 | ||
sentinel resolve-hostnames yes | ||
sentinel monitor mymaster redis-master 6379 1 | ||
sentinel down-after-milliseconds mymaster 1000 | ||
sentinel failover-timeout mymaster 1000 | ||
sentinel parallel-syncs mymaster 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
# Released under the MIT License. | ||
# Copyright, 2018-2024, by Samuel Williams. | ||
# Copyright, 2018, by Huba Nagy. | ||
# Copyright, 2019, by David Ortiz. | ||
|
||
require 'async/clock' | ||
require 'async/redis/sentinel_client' | ||
require 'sus/fixtures/async' | ||
|
||
describe Async::Redis::SentinelClient do | ||
include Sus::Fixtures::Async::ReactorContext | ||
|
||
let(:master_host) {"redis://redis-master:6379"} | ||
let(:slave_host) {"redis://redis-slave:6379"} | ||
let(:sentinel_host) {"redis://redis-sentinel:26379"} | ||
|
||
let(:sentinels) {[ | ||
Async::Redis::Endpoint.parse(sentinel_host) | ||
]} | ||
|
||
let(:client) {subject.new(sentinels)} | ||
let(:slave_client) {subject.new(sentinels, role: :slave)} | ||
|
||
it "should resolve master address" do | ||
unless master_host and slave_host and sentinel_host | ||
skip("No sentinel host provided.") | ||
end | ||
|
||
client.set("key", "value") | ||
|
||
expect(slave_client.get("key")).to be == "value" | ||
end | ||
end |