File: window.rb

package info (click to toggle)
ruby-protocol-http2 0.23.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 472 kB
  • sloc: ruby: 3,627; makefile: 4
file content (84 lines) | stat: -rw-r--r-- 2,073 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# frozen_string_literal: true

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

require "protocol/http2/connection_context"
require "json"

describe Protocol::HTTP2::Window do
	let(:window) {subject.new}
	
	with "#consume" do
		it "can consume available capacity" do
			expect(window).not.to be(:full?)
			expect(window).to be(:available?)
			
			expect(window.consume(100)).to be == 100
			expect(window).not.to be(:full?)
			
			window.consume(window.available)
			expect(window).to be(:full?)
			expect(window).not.to be(:available?)
		end
	end
	
	with "#capacity=" do
		it "fails if assignment to capacity causes the window to exceed the maximum flow control window size" do
			expect do
				window.capacity = Protocol::HTTP2::MAXIMUM_ALLOWED_WINDOW_SIZE + 1
			end.to raise_exception(Protocol::HTTP2::FlowControlError)
		end
	end
	
	with "#inspect" do
		it "can generate a string representation" do
			expect(window.inspect).to be =~ /available=65535 used=0 capacity=65535/
		end
	end
end

describe Protocol::HTTP2::LocalWindow do
	let(:window) {subject.new}
	
	with "#consume" do
		it "can consume available capacity" do
			window.consume(100)
			expect(window.wanted).to be == 100
		end
	end
	
	with "desired window size" do
		let(:window) {subject.new(desired: 200)}
		
		it "can consume available capacity" do
			window.consume(window.available)
			expect(window.wanted).to be == 200
		end
		
		it "is not limited if the half the desired capacity is available" do
			expect(window).not.to be(:limited?)
			
			# Consume the entire window:
			window.consume(window.available)
			
			expect(window).to be(:limited?)
			
			# Expand the window by at least half the desired capacity:
			window.expand(window.desired / 2)
			
			expect(window).not.to be(:limited?)
		end
	end
	
	with "#limited?" do
		it "becomes limited after half the capacity is consumed" do
			expect(window).not.to be(:limited?)
			
			# Consume a little more than half:
			window.consume(window.capacity / 2 + 2)
			
			expect(window).to be(:limited?)
		end
	end
end