summaryrefslogtreecommitdiff
path: root/lib/vendor/excon/spec/support/shared_examples/shared_example_for_streaming_clients.rb
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2017-01-02 18:59:07 +0100
committerJacob Vosmaer <jacob@gitlab.com>2017-01-02 18:59:07 +0100
commitd03e022b8816fd4193ff7a0a34e35573e8114e7f (patch)
tree1896a5c90f0eb99ecaa5fc09304cee7174657943 /lib/vendor/excon/spec/support/shared_examples/shared_example_for_streaming_clients.rb
parent3fe9cea03a6384fd8f57f10e172c134ed5c0552d (diff)
downloadgitlab-shell-d03e022b8816fd4193ff7a0a34e35573e8114e7f.tar.gz
WIP Use excon for HTTP requestshttp-excon
Diffstat (limited to 'lib/vendor/excon/spec/support/shared_examples/shared_example_for_streaming_clients.rb')
-rw-r--r--lib/vendor/excon/spec/support/shared_examples/shared_example_for_streaming_clients.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/vendor/excon/spec/support/shared_examples/shared_example_for_streaming_clients.rb b/lib/vendor/excon/spec/support/shared_examples/shared_example_for_streaming_clients.rb
new file mode 100644
index 0000000..15a9f05
--- /dev/null
+++ b/lib/vendor/excon/spec/support/shared_examples/shared_example_for_streaming_clients.rb
@@ -0,0 +1,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