Created
March 14, 2022 11:11
-
-
Save miry/d4475803080fc18a5cd5c5a405524fbb to your computer and use it in GitHub Desktop.
Revisions
-
miry created this gist
Mar 14, 2022 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,62 @@ require 'socket' require 'timeout' require "toxiproxy" hostname = 'toxiproxy' port = 16379 # Setup Toxiproxy.host = "http://#{hostname}:8474" Toxiproxy.populate([{ name: "redis", listen: ":#{port}", upstream: "redis:6379", }]) Toxiproxy.each do |proxy| p proxy end puts "## Test connect to redis" s = TCPSocket.open(hostname, port) s.puts "info" Timeout::timeout(2) do puts ">>> Start reading" while line = s.gets puts line.chop end rescue => e puts e p e end rescue "" s.close puts ">>> Finish reading" puts "## Test when redis is down" Toxiproxy[/redis/].down do Toxiproxy.each do |proxy| p proxy end s = TCPSocket.open(hostname, port) s.puts "info" Timeout::timeout(2) do puts ">>> Start reading" while line = s.gets puts line.chop end rescue => e puts e p e end rescue "" s.close puts ">>> Finish reading" end This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ # docker-compose.yml version: "3.9" services: redis: image: redis:6.2 ports: - "6379:6379" expose: - "6379" networks: example: aliases: - redis toxiproxy: image: ghcr.io/shopify/toxiproxy:2.4.0 networks: example: aliases: - toxiproxy expose: - "8474" - "16379" ports: - "8474:8474" - "16379:16379" app: image: ruby:3.1 networks: example: aliases: - app depends_on: - redis - toxiproxy volumes: - ./client.rb:/client.rb command: - bash - -c - | gem install toxiproxy ruby client.rb networks: example: {}