avoid race condition when matching logger output
MODIFY
features/step_definitions/redis_auto_failover_steps.rb
features/step_definitions/redis_auto_failover_steps.rb
@@ -126,17 +126,20 @@ end
Then /^a system notification for "([^\"]*)" not being available should be sent$/ do |redis_name|
text = "Redis master '#{TestDaemons::Redis[redis_name].ip_with_port}' not available"
- assert_match /#{text}/, File.readlines(system_notification_log_path).last
+ lines = File.readlines(system_notification_log_path)
+ assert_match /#{text}/, lines[-2..-1].join(' ')
end
Then /^a system notification for switching from "([^\"]*)" to "([^\"]*)" should be sent$/ do |old_redis_master_name, new_redis_master_name|
text = "Setting redis master to '#{TestDaemons::Redis[new_redis_master_name].ip_with_port}' (was '#{TestDaemons::Redis[old_redis_master_name].ip_with_port}')"
- assert_match /#{Regexp.escape(text)}/, File.read(system_notification_log_path)
+ lines = File.readlines(system_notification_log_path)
+ assert_match /#{Regexp.escape(text)}/, lines.last
end
Then /^a system notification for no slave available to become new master should be sent$/ do
text = "Redis master could not be switched, no slave available to become new master"
- assert_match /#{text}/, File.readlines(system_notification_log_path).last
+ lines = File.readlines(system_notification_log_path)
+ assert_match /#{text}/, lines.last
end
Then /^the redis configuration server should answer http requests$/ do

MODIFY
features/support/system_notification_logger
features/support/system_notification_logger
@@ -9,7 +9,7 @@ require File.expand_path("../../lib/beetle", File.dirname(__FILE__))
tmp_path = File.expand_path("../../tmp", File.dirname(__FILE__))
system_notification_log_file_path = "#{tmp_path}/system_notifications.log"
-DEBUG = true
+DEBUG = false
Daemons.run_proc("system_notification_logger", :log_output => true, :dir_mode => :normal, :dir => tmp_path) do
Beetle.config.servers = "127.0.0.1:5672" # rabbitmq
@@ -34,11 +34,11 @@ Daemons.run_proc("system_notification_logger", :log_output => true, :dir_mode =>
end
ws.onclose do
puts "server closed connection" if DEBUG && !@interrupted
- EM.add_timer(1){ EM.stop_event_loop }
+ EM.add_timer(0){ EM.stop_event_loop }
end
ws.onmessage do |text|
puts "writing message to #{system_notification_log_file_path}: #{text}"
- log_file << text
+ log_file << (text + "\n")
end
puts "Started system notification logger"
trap("INT") { shutdown(ws) }

avoid race condition when matching logger output