Skip to content

Commit 9b1c6b8

Browse files
committed
Update tests.
1 parent d04e3dc commit 9b1c6b8

File tree

2 files changed

+39
-29
lines changed

2 files changed

+39
-29
lines changed

test/async/http/protocol/streaming.rb renamed to test/protocol/http/body/stream.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@
130130
end
131131
end
132132

133-
[Async::HTTP::Protocol::HTTP1].each do |protocol|
134-
describe protocol do
133+
[Async::HTTP::Protocol::HTTP1, Async::HTTP::Protocol::HTTP2].each do |protocol|
134+
describe protocol, unique: protocol.name do
135135
include Sus::Fixtures::Async::HTTP::ServerContext
136136

137137
let(:protocol) {subject}

test/async/http/protocol/closable.rb renamed to test/protocol/http/body/streamable.rb

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,55 +10,56 @@
1010
AnEchoServer = Sus::Shared("an echo server") do
1111
let(:app) do
1212
::Protocol::HTTP::Middleware.for do |request|
13-
body = ::Protocol::HTTP::Body::Streamable.response(request) do |stream|
14-
# $stderr.puts "Server stream: #{stream.inspect}"
15-
13+
streamable = ::Protocol::HTTP::Body::Streamable.response(request) do |stream|
14+
Console.debug(self, "Echoing chunks...")
1615
while chunk = stream.readpartial(1024)
17-
# $stderr.puts "Server reading chunk: #{chunk.inspect}"
16+
Console.debug(self, "Reading chunk:", chunk: chunk)
1817
stream.write(chunk)
1918
end
2019
rescue EOFError
20+
Console.debug(self, "EOF.")
2121
# Ignore.
2222
ensure
23-
# $stderr.puts "Server closing stream."
23+
Console.debug(self, "Closing stream.")
2424
stream.close
2525
end
2626

27-
::Protocol::HTTP::Response[200, {}, body]
27+
::Protocol::HTTP::Response[200, {}, streamable]
2828
end
2929
end
3030

3131
it "should echo the request body" do
3232
chunks = ["Hello,", "World!"]
3333
response_chunks = Queue.new
3434

35-
body = ::Protocol::HTTP::Body::Streamable.request do |stream|
36-
# $stderr.puts "Client stream: #{stream.inspect}"
37-
35+
output = ::Protocol::HTTP::Body::Writable.new
36+
response = client.post("/", body: output)
37+
stream = ::Protocol::HTTP::Body::Stream.new(response.body, output)
38+
39+
begin
40+
Console.debug(self, "Echoing chunks...")
3841
chunks.each do |chunk|
39-
# $stderr.puts "Client writing chunk: #{chunk.inspect}"
42+
Console.debug(self, "Writing chunk:", chunk: chunk)
4043
stream.write(chunk)
4144
end
4245

43-
# $stderr.puts "Client closing write."
46+
Console.debug(self, "Closing write.")
4447
stream.close_write
4548

46-
# $stderr.puts "Client reading chunks..."
49+
Console.debug(self, "Reading chunks...")
4750
while chunk = stream.readpartial(1024)
48-
# $stderr.puts "Client reading chunk: #{chunk.inspect}"
51+
Console.debug(self, "Reading chunk:", chunk: chunk)
4952
response_chunks << chunk
5053
end
5154
rescue EOFError
55+
Console.debug(self, "EOF.")
5256
# Ignore.
5357
ensure
54-
# $stderr.puts "Client closing stream."
58+
Console.debug(self, "Closing stream.")
5559
stream.close
5660
response_chunks.close
5761
end
5862

59-
response = client.post("/", body: body)
60-
body.stream(response.body)
61-
6263
chunks.each do |chunk|
6364
expect(response_chunks.pop).to be == chunk
6465
end
@@ -71,54 +72,63 @@
7172

7273
let(:app) do
7374
::Protocol::HTTP::Middleware.for do |request|
74-
body = ::Protocol::HTTP::Body::Streamable.response(request) do |stream|
75+
streamable = ::Protocol::HTTP::Body::Streamable.response(request) do |stream|
76+
Console.debug(self, "Echoing chunks...")
7577
chunks.each do |chunk|
7678
stream.write(chunk)
7779
end
7880

81+
Console.debug(self, "Closing write.")
7982
stream.close_write
8083

84+
Console.debug(self, "Reading chunks...")
8185
while chunk = stream.readpartial(1024)
86+
Console.debug(self, "Reading chunk:", chunk: chunk)
8287
response_chunks << chunk
8388
end
8489
rescue EOFError
90+
Console.debug(self, "EOF.")
8591
# Ignore.
8692
ensure
87-
# $stderr.puts "Server closing stream."
93+
Console.debug(self, "Closing stream.")
8894
stream.close
8995
end
9096

91-
::Protocol::HTTP::Response[200, {}, body]
97+
::Protocol::HTTP::Response[200, {}, streamable]
9298
end
9399
end
94100

95101
it "should echo the response body" do
96-
body = ::Protocol::HTTP::Body::Streamable.request do |stream|
102+
output = ::Protocol::HTTP::Body::Writable.new
103+
response = client.post("/", body: output)
104+
stream = ::Protocol::HTTP::Body::Stream.new(response.body, output)
105+
106+
begin
107+
Console.debug(self, "Echoing chunks...")
97108
while chunk = stream.readpartial(1024)
98109
stream.write(chunk)
99110
end
100111
rescue EOFError
112+
Console.debug(self, "EOF.")
101113
# Ignore.
102114
ensure
115+
Console.debug(self, "Closing stream.")
103116
stream.close
104117
end
105118

106-
response = client.post("/", body: body)
107-
body.stream(response.body)
108-
109119
chunks.each do |chunk|
110120
expect(response_chunks.pop).to be == chunk
111121
end
112122
end
113123
end
114124

115-
[Async::HTTP::Protocol::HTTP1].each do |protocol|
116-
describe protocol do
125+
[Async::HTTP::Protocol::HTTP1, Async::HTTP::Protocol::HTTP2].each do |protocol|
126+
describe protocol, unique: protocol.name do
117127
include Sus::Fixtures::Async::HTTP::ServerContext
118128

119129
let(:protocol) {subject}
120130

121131
it_behaves_like AnEchoServer
122-
# it_behaves_like AnEchoClient
132+
it_behaves_like AnEchoClient
123133
end
124134
end

0 commit comments

Comments
 (0)