Class: Blitz::Curl::Rush

Inherits:
Object
  • Object
show all
Defined in:
lib/blitz/curl/rush.rb

Overview

Use this to run a rush (a load test) against your app. The return values include the entire timeline containing the average duration, the concurrency, the bytes sent/received, etc.

Defined Under Namespace

Classes: Point, Result, Step

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Rush

:nodoc:



128
129
130
# File 'lib/blitz/curl/rush.rb', line 128

def initialize args # :nodoc:
    @args = args
end

Instance Attribute Details

#argsObject (readonly)

:nodoc:



126
127
128
# File 'lib/blitz/curl/rush.rb', line 126

def args
  @args
end

#job_idObject (readonly)

:nodoc:



124
125
126
# File 'lib/blitz/curl/rush.rb', line 124

def job_id
  @job_id
end

#regionObject (readonly)

:nodoc:



125
126
127
# File 'lib/blitz/curl/rush.rb', line 125

def region
  @region
end

Instance Method Details

#abort!Object

:nodoc:



174
175
176
# File 'lib/blitz/curl/rush.rb', line 174

def abort! # :nodoc:
    Command::API.client.abort_job job_id rescue nil
end

#execute(&block) ⇒ Object

Primary method for running a rush. The args is very similar to what the Sprint.execute method accepts, except this should also contain the pattern. If a block is given, it’s invoked periodically with the partial results of the run (to report progress, perhaps)

result = Blitz::Curl.parse('-r california -p 10-50:30 www.example.com').execute do |partial|
    pp [ partial.region, partial.timeline.last.hits ]
end

You can easily export the result to JSON, XML or compute the various rates, etc.



108
109
110
111
# File 'lib/blitz/curl/rush.rb', line 108

def execute &block # |result|
    queue
    result &block
end

#queueObject

:nodoc:

Raises:



113
114
115
116
117
118
119
120
121
122
# File 'lib/blitz/curl/rush.rb', line 113

def queue # :nodoc:
    if not args.member? 'pattern' and not args.member? :pattern
        raise ArgumentError, 'missing pattern'
    end

    res = Command::API.client.curl_execute args
    raise Error.new(res) if res['error']
    @job_id = res['job_id']
    @region = res['region']
end

#result(&block) ⇒ Object

:nodoc:



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/blitz/curl/rush.rb', line 132

def result &block # :nodoc:
    last = nil
    while true
        sleep 2.0

        job = Command::API.client.job_status job_id
        if job['error']
            raise Error
        end
        
        result = job['result']
        next if job['status'] == 'queued'
        next if job['status'] == 'running' and not result

        raise Error if not result

        error = result['error']
        if error
            if error == 'dns'
                raise Error::DNS.new(result)
            elsif error == 'authorize'
                raise Error::Authorize.new(result)
            elsif error == 'parse'
                raise Error::Parse.new(result)
            else
                raise Error
            end
        end
        
        last = Result.new(job)
        continue = yield last rescue false
        if continue == false
            abort!
            break
        end
        
        break if job['status'] == 'completed'
    end
    
    return last
end