diff options
Diffstat (limited to 'test/plum/test_flow_control.rb')
-rw-r--r-- | test/plum/test_flow_control.rb | 70 |
1 files changed, 21 insertions, 49 deletions
diff --git a/test/plum/test_flow_control.rb b/test/plum/test_flow_control.rb index 316361c..38958b7 100644 --- a/test/plum/test_flow_control.rb +++ b/test/plum/test_flow_control.rb @@ -32,9 +32,7 @@ class FlowControlTest < Minitest::Test def test_flow_control_window_update_zero open_new_stream { |stream| assert_stream_error(:protocol_error) { - stream.receive_frame Frame.new(type: :window_update, - stream_id: stream.id, - payload: "".push_uint32(0)) + stream.receive_frame Frame::WindowUpdate.new(stream.id, 0) } } end @@ -42,9 +40,9 @@ class FlowControlTest < Minitest::Test def test_flow_control_window_update_frame_size open_new_stream { |stream| assert_connection_error(:frame_size_error) { - stream.receive_frame Frame.new(type: :window_update, - stream_id: stream.id, - payload: "".push_uint16(0)) + stream.receive_frame Frame.craft(type: :window_update, + stream_id: stream.id, + payload: "".push_uint16(0)) } } end @@ -52,18 +50,11 @@ class FlowControlTest < Minitest::Test def test_flow_control_dont_send_data_exceeding_send_window open_new_stream { |stream| con = stream.connection - con << Frame.new(type: :settings, - stream_id: 0, - payload: "".push_uint16(Frame::SETTINGS_TYPE[:initial_window_size]) - .push_uint32(4*2+1)).assemble + con << Frame::Settings.new(initial_window_size: 4 * 2 + 1).assemble # only extend stream window size - con << Frame.new(type: :window_update, - stream_id: stream.id, - payload: "".push_uint32(100)).assemble + con << Frame::WindowUpdate.new(stream.id, 100).assemble 10.times { |i| - stream.send Frame.new(type: :data, - stream_id: stream.id, - payload: "".push_uint32(i)) + stream.send Frame::Data.new(stream.id, "".push_uint32(i)) } last = sent_frames.last @@ -74,23 +65,14 @@ class FlowControlTest < Minitest::Test def test_flow_control_dont_send_data_upto_updated_send_window open_new_stream { |stream| con = stream.connection - con << Frame.new(type: :settings, - stream_id: 0, - payload: "".push_uint16(Frame::SETTINGS_TYPE[:initial_window_size]) - .push_uint32(4*2+1)).assemble + con << Frame::Settings.new(initial_window_size: 4 * 2 + 1).assemble 10.times { |i| - stream.send Frame.new(type: :data, - stream_id: stream.id, - payload: "".push_uint32(i)) + stream.send Frame::Data.new(stream.id, "".push_uint32(i)) } # only extend stream window size - con << Frame.new(type: :window_update, - stream_id: stream.id, - payload: "".push_uint32(100)).assemble + con << Frame::WindowUpdate.new(stream.id, 100).assemble # and extend connection window size - con << Frame.new(type: :window_update, - stream_id: 0, - payload: "".push_uint32(4*2+1)).assemble + con << Frame::WindowUpdate.new(0, 4 * 2 + 1).assemble last = sent_frames.last assert_equal(3, last.payload.uint32) @@ -100,24 +82,14 @@ class FlowControlTest < Minitest::Test def test_flow_control_update_send_initial_window_size open_new_stream { |stream| con = stream.connection - con << Frame.new(type: :settings, - stream_id: 0, - payload: "".push_uint16(Frame::SETTINGS_TYPE[:initial_window_size]) - .push_uint32(4*2+1)).assemble + con << Frame::Settings.new(initial_window_size: 4 * 2 + 1).assemble 10.times { |i| - stream.send Frame.new(type: :data, - stream_id: stream.id, - payload: "".push_uint32(i)) + stream.send Frame::Data.new(stream.id, "".push_uint32(i)) } # only extend stream window size - con << Frame.new(type: :window_update, - stream_id: stream.id, - payload: "".push_uint32(100)).assemble + con << Frame::WindowUpdate.new(stream.id, 100).assemble # and update initial window size - con << Frame.new(type: :settings, - stream_id: 0, - payload: "".push_uint16(Frame::SETTINGS_TYPE[:initial_window_size]) - .push_uint32(4*4+1)).assemble + con << Frame::Settings.new(initial_window_size: 4 * 4 + 1).assemble last = sent_frames.reverse.find { |f| f.type == :data } assert_equal(3, last.payload.uint32) @@ -135,17 +107,17 @@ class FlowControlTest < Minitest::Test prepare.call { |con, stream| con.window_update(500) # extend only connection - con << Frame.headers(stream.id, "", end_headers: true).assemble + con << Frame::Headers.new(stream.id, "", end_headers: true).assemble assert_stream_error(:flow_control_error) { - con << Frame.data(stream.id, "\x00" * 30, end_stream: true).assemble + con << Frame::Data.new(stream.id, "\x00" * 30, end_stream: true).assemble } } prepare.call { |con, stream| stream.window_update(500) # extend only stream - con << Frame.headers(stream.id, "", end_headers: true).assemble + con << Frame::Headers.new(stream.id, "", end_headers: true).assemble assert_connection_error(:flow_control_error) { - con << Frame.data(stream.id, "\x00" * 30, end_stream: true).assemble + con << Frame::Data.new(stream.id, "\x00" * 30, end_stream: true).assemble } } end @@ -155,8 +127,8 @@ class FlowControlTest < Minitest::Test con = stream.connection con.settings(initial_window_size: 24) stream.window_update(1) - con << Frame.headers(stream.id, "", end_headers: true).assemble - con << Frame.data(stream.id, "\x00" * 20, end_stream: true).assemble + con << Frame::Headers.new(stream.id, "", end_headers: true).assemble + con << Frame::Data.new(stream.id, "\x00" * 20, end_stream: true).assemble assert_equal(4, con.recv_remaining_window) assert_equal(5, stream.recv_remaining_window) con.settings(initial_window_size: 60) |