blob: 8d1c81dc3b8e117864dabe1ba1d496a9ac3ee226 (
plain)
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
|
require "timeout"
module ServerUtils
def open_server_connection(scheme = :https)
io = StringIO.new
@_con = (scheme == :https ? HTTPSConnection : HTTPConnection).new(io)
@_con << Connection::CLIENT_CONNECTION_PREFACE
@_con << Frame.new(type: :settings, stream_id: 0).assemble
if block_given?
yield @_con
else
@_con
end
end
def open_new_stream(arg1 = nil, **kwargs)
if arg1.is_a?(Connection)
con = arg1
else
con = open_server_connection
end
@_stream = con.instance_eval {
new_stream((con.streams.keys.last||0/2)*2+1, **kwargs)
}
if block_given?
yield @_stream
else
@_stream
end
end
def sent_frames(con = nil)
resp = (con || @_con).sock.string.dup.force_encoding(Encoding::BINARY)
frames = []
while f = Frame.parse!(resp)
frames << f
end
frames
end
def capture_frames(con = nil, &blk)
io = (con || @_con).sock
pos = io.string.bytesize
blk.call
resp = io.string.byteslice(pos, io.string.bytesize - pos).force_encoding(Encoding::BINARY)
frames = []
while f = Frame.parse!(resp)
frames << f
end
frames
end
def capture_frame(con = nil, &blk)
frames = capture_frames(con, &blk)
assert_equal(1, frames.size, "Supplied block sent no frames or more than 1 frame")
frames.first
end
end
class Minitest::Test
include ServerUtils
end
|