Navigation Menu

Skip to content

Commit

Permalink
Support "Nmessages" type parameter for subscribe-until directive
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Apr 14, 2015
1 parent e587250 commit c6c87df
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
21 changes: 15 additions & 6 deletions lib/drntest/directive.rb
Expand Up @@ -69,21 +69,30 @@ class DisableValidationDirective < Directive
end

class SubscribeUntil < Directive
attr_reader :timeout_seconds
attr_reader :max_messages, :timeout_seconds

DEFAULT_TIMEOUT_SECONDS = 1

ONE_MINUTE_IN_SECONDS = 60
ONE_HOUR_IN_SECONDS = ONE_MINUTE_IN_SECONDS * 60

def initialize(timeout)
if timeout =~ /\A(\d+\.?|\.\d+|\d+\.\d+)s(?:ec(?:onds?)?)?\z/
def initialize(parameters)
@max_messages = nil
@timeout_seconds = nil

parameters.each do |parameter|
if parameter =~ /\A(\d+)(?:messages|msg)?\z/
@max_messages = $1.to_i
elsif parameter =~ /\A(\d+\.?|\.\d+|\d+\.\d+)s(?:ec(?:onds?)?)?\z/
@timeout_seconds = $1.to_f
elsif timeout =~ /\A(\d+\.?|\.\d+|\d+\.\d+)m(?:inutes?)?\z/
elsif parameter =~ /\A(\d+\.?|\.\d+|\d+\.\d+)m(?:inutes?)?\z/
@timeout_seconds = $1.to_f * ONE_MINUTE_IN_SECONDS
elsif timeout =~ /\A(\d+\.?|\.\d+|\d+\.\d+)h(?:ours?)?\z/
elsif parameter =~ /\A(\d+\.?|\.\d+|\d+\.\d+)h(?:ours?)?\z/
@timeout_seconds = $1.to_f * ONE_HOUR_IN_SECONDS
else
end
end

if @max_messages.nil? and @timeout_seconds.nil?
@timeout_seconds = DEFAULT_TIMEOUT_SECONDS
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/drntest/test-executor.rb
Expand Up @@ -111,6 +111,7 @@ def execute_directive(directive)
when SubscribeUntil
@subscribe = true
@timeout_seconds = directive.timeout_seconds
@max_messages = directive.max_messages
end
end

Expand All @@ -122,7 +123,8 @@ def execute_request(request)
if @logging
responses = []
if @subscribe
options[:timeout_seconds] = @timeout_seconds
options[:subscription_timeout] = @timeout_seconds
options[:max_messages] = @max_messages
request_process = @client.subscribe(request, options) do |raw_response|
responses << clean_response(request, raw_response)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/drntest/test-loader.rb
Expand Up @@ -100,7 +100,7 @@ def parse_directive(type, options)
when :disable_validation
DisableValidationDirective.new
when :subscribe_until
SubscribeUntil.new(options.first)
SubscribeUntil.new(options)
else
UnknownDirective.new(type, options)
end
Expand Down

0 comments on commit c6c87df

Please sign in to comment.