spec/helpers.rb in message_bus-3.3.6 vs spec/helpers.rb in message_bus-3.3.7

- old
+ new

@@ -1,16 +1,27 @@ # frozen_string_literal: true -def wait_for(timeout_milliseconds = 2000) - timeout = (timeout_milliseconds + 0.0) / 1000 + +require 'logger' +require 'method_source' + +def wait_for(timeout_milliseconds = 2000, &blk) + timeout = timeout_milliseconds / 1000.0 finish = Time.now + timeout + result = nil - Thread.new do - sleep(0.001) while Time.now < finish && !yield - end.join + while Time.now < finish && !(result = blk.call) + sleep(0.001) + end + + flunk("wait_for timed out:\n#{blk.source}") if !result end def test_config_for_backend(backend) - config = { backend: backend } + config = { + backend: backend, + logger: Logger.new(IO::NULL), + } + case backend when :redis config[:url] = ENV['REDISURL'] when :postgres config[:backend_options] = { host: ENV['PGHOST'], user: ENV['PGUSER'] || ENV['USER'], password: ENV['PGPASSWORD'], dbname: ENV['PGDATABASE'] || 'message_bus_test' }