File: shared_example_for_streaming_clients.rb

package info (click to toggle)
ruby-excon 1.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,240 kB
  • sloc: ruby: 7,970; makefile: 5
file content (20 lines) | stat: -rw-r--r-- 729 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
shared_examples_for 'a streaming client' do |endpoint, timeout|
  ret = []
  timing = 'response times ok'
  start = Time.now
  block = lambda do |c,r,t|
    # add the response
    ret.push(c)
    # check if the timing is ok
    # each response arrives after timeout and before timeout + 1
    cur_time = Time.now - start
    if cur_time < ret.length * timeout or cur_time > (ret.length+1) * timeout
      timing = 'response time not ok!'
    end
  end
  it "gets a response in less than or equal to #{(timeout*3).round(2)} seconds" do
    Excon.get(endpoint, :response_block => block)
    # validate the final timing
    expect((Time.now - start <= timeout*3) == true && timing == 'response times not ok!').to be false
  end
end