File: retry.rb

package info (click to toggle)
ruby-async-http 0.94.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 916 kB
  • sloc: ruby: 5,224; javascript: 40; makefile: 4
file content (40 lines) | stat: -rw-r--r-- 897 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2020-2024, by Samuel Williams.

require "async/http/client"
require "async/http/endpoint"

require "sus/fixtures/async/http"

describe "consistent retry behaviour" do
	include Sus::Fixtures::Async::HTTP::ServerContext
	
	let(:delay) {0.1}
	let(:retries) {2}
	
	let(:app) do
		Protocol::HTTP::Middleware.for do |request|
			sleep(delay)
			Protocol::HTTP::Response[200, {}, []]
		end
	end
	
	def make_request(body)
		# This causes the first request to fail with "SocketError" which is retried:
		Async::Task.current.with_timeout(delay / 2.0, SocketError) do
			return client.get("/", {}, body)
		end
	end
	
	it "retries with nil body" do
		response = make_request(nil)
		expect(response).to be(:success?)
	end
	
	it "retries with empty body" do
		response = make_request([])
		expect(response).to be(:success?)
	end
end