Skip to content

Commit

Permalink
Cucumber tests use HTTP instead of RPC via Beetle
Browse files Browse the repository at this point in the history
  • Loading branch information
JHK authored and skaes committed Feb 21, 2024
1 parent ec8c22c commit f12fd4d
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 14 deletions.
16 changes: 2 additions & 14 deletions features/step_definitions/redis_auto_failover_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,8 @@
Beetle.config.servers = "127.0.0.1:5672" # rabbitmq
Beetle.config.logger.level = Logger::INFO
redis_master = TestDaemons::Redis[redis_name].ip_with_port
response = nil
expected_response = ['OK', redis_master]
10.times do |i|
client = Beetle::Client.new.configure :auto_delete => true do |config|
config.queue(:echo, :lazy => true, :dead_lettering => true)
config.message(:echo)
end
t1 = Time.now
response = client.rpc(:echo, 'echo')
t2 = Time.now
break if expected_response == response
puts "OK,#{redis_master} != #{response.join(',')} after #{t2-t1}, attempt #{i+1}"
end
assert_equal expected_response, response
response = `curl -s 127.0.0.1:10254/redis_master`.chomp
assert_equal redis_master, response
end

Then /^a system notification for "([^\"]*)" not being available should be sent$/ do |redis_name|
Expand Down
61 changes: 61 additions & 0 deletions features/support/beetle_handler
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,64 @@ require "optparse"
require 'json'
require File.expand_path("../../lib/beetle", File.dirname(__FILE__))

module BeetleStatusServer
def self.setup(beetle_client)
@@beetle_client = beetle_client
end

def receive_data(data)
begin
verb, uri, _ = data&.split(/[\r\n]+/)&.first&.split(' ', 3)
return reply(405, 'Only GET is supported') if verb != 'GET'

path = URI.parse(uri).path
route(path)
rescue => e
warn e.to_s
reply(400, e.to_s)
ensure
close_connection_after_writing
end
end

private

def route(path)
case path
when '/_system/alive' then render_alive
when '/redis_master' then render_redis_master
else reply(404, 'Not Found')
end
end

def reply(code, body)
reply_text = <<~EOF.chomp
HTTP/1.1 #{code}
Content-Type: text/plain
Content-Length: #{body.bytesize}
#{body}
EOF
send_data reply_text
end

def render_alive
reply(200, 'ALIVE')
end

def render_redis_master
redis_master = nil
begin
redis_master = @@beetle_client.deduplication_store.redis.server
rescue
master_file_content = File.read(Beetle.config.redis_server)
"no redis master: exception: #{$!.class}(#{$!}), master_file: '#{master_file_content}'"
end
reply(200, redis_master)
end
end


tmp_path = File.expand_path("../../tmp", File.dirname(__FILE__))

Daemons.run_proc("beetle_handler", :log_output => true, :dir_mode => :normal, :dir => tmp_path) do
Expand Down Expand Up @@ -44,5 +102,8 @@ Daemons.run_proc("beetle_handler", :log_output => true, :dir_mode => :normal, :d
end
client.listen do
puts "Started beetle handler for system: #{Beetle.config.system_name}"

BeetleStatusServer.setup(client)
EM.start_server '0.0.0.0', 10254, BeetleStatusServer
end
end

0 comments on commit f12fd4d

Please sign in to comment.