|
13 | 13 | # Custom error class to track in tests |
14 | 14 | class BodyWriteError < StandardError; end |
15 | 15 |
|
16 | | -# A custom body class that raises during enumeration. |
| 16 | +# A custom body class that raises during reading. |
17 | 17 | class ErrorProneBody < ::Protocol::HTTP::Body::Readable |
18 | 18 | def initialize(...) |
19 | 19 | super(...) |
20 | 20 |
|
21 | 21 | @error = nil |
| 22 | + @count = 0 |
22 | 23 | end |
23 | 24 |
|
24 | 25 | attr :error |
25 | 26 |
|
| 27 | + def read |
| 28 | + @count += 1 |
| 29 | + raise BodyWriteError, "error during write" if @count > 1 |
| 30 | + |
| 31 | + "Hello" |
| 32 | + end |
| 33 | + |
26 | 34 | def close(error = nil) |
27 | 35 | @error = error |
28 | 36 | super() |
29 | 37 | end |
30 | | - |
31 | | - def each |
32 | | - super |
33 | | - raise BodyWriteError, "error during write" |
34 | | - end |
35 | 38 | end |
36 | 39 |
|
37 | 40 | describe Async::HTTP::Protocol::HTTP11 do |
@@ -65,26 +68,26 @@ def each |
65 | 68 |
|
66 | 69 | let(:protocol) {subject} |
67 | 70 |
|
68 | | - with "error during body write" do |
69 | | - let(:body) {ErrorProneBody.new} |
70 | | - |
71 | | - let(:app) do |
72 | | - Protocol::HTTP::Middleware.for do |request| |
73 | | - # Return a response with a body that will raise during enumeration: |
74 | | - Protocol::HTTP::Response[200, {}, body] |
75 | | - end |
76 | | - end |
77 | | - |
78 | | - it "handles error in ensure block without NameError" do |
79 | | - response = client.get("/") |
80 | | - |
81 | | - expect do |
82 | | - response.read |
83 | | - end.to raise_exception(EOFError) |
84 | | - |
85 | | - expect(body.error).to be_a(BodyWriteError) |
86 | | - end |
87 | | - end |
| 71 | + # TODO: Update once protocol-http1 v0.37.1 is released (body write methods now use read loop instead of each). |
| 72 | + # with "error during body write" do |
| 73 | + # let(:body) {ErrorProneBody.new} |
| 74 | + # |
| 75 | + # let(:app) do |
| 76 | + # Protocol::HTTP::Middleware.for do |request| |
| 77 | + # Protocol::HTTP::Response[200, {}, body] |
| 78 | + # end |
| 79 | + # end |
| 80 | + # |
| 81 | + # it "handles error in ensure block without NameError" do |
| 82 | + # response = client.get("/") |
| 83 | + # |
| 84 | + # expect do |
| 85 | + # response.read |
| 86 | + # end.to raise_exception(EOFError) |
| 87 | + # |
| 88 | + # expect(body.error).to be_a(BodyWriteError) |
| 89 | + # end |
| 90 | + # end |
88 | 91 |
|
89 | 92 | with "bad requests" do |
90 | 93 | def around |
|
0 commit comments