@@ -109,7 +109,6 @@ defmodule HPAXTest do
109
109
110
110
property "encode/3 prepends dynamic resizes at the start of a block" do
111
111
enc_table = HPAX . new ( 20_000 )
112
- # Start with a non-empty decode table
113
112
dec_table = HPAX . new ( 20_000 )
114
113
115
114
# Put a record in both to prime the pump. The table sizes should match
@@ -120,14 +119,45 @@ defmodule HPAXTest do
120
119
assert enc_table . max_table_size == 20_000
121
120
assert dec_table . max_table_size == 20_000
122
121
123
- # Encode a record after resizing the table. We expect a dynamic resize to be
124
- # encoded and the for two table sizes to be identical after decoding
122
+ # Scenario 1: Simulate the decoder growing the table via settings
123
+
124
+ # First, the decoder resizes its table to some maximum size
125
+ dec_table = HPAX . resize ( dec_table , 40_000 )
126
+
127
+ # It then communicates that size to the encoder, who chooses a smaller size
128
+ enc_table = HPAX . resize ( enc_table , 30_000 )
129
+
130
+ # Now, encode a header
131
+ { encoded , enc_table } = HPAX . encode ( [ { :store , "lame" , "LAME" } ] , enc_table )
132
+ encoded = IO . iodata_to_binary ( encoded )
133
+
134
+ # Ensure that we encoded a resize on the wire
135
+ assert << 0b001 :: 3 , rest :: bitstring >> = encoded
136
+ assert { :ok , 30_000 , _rest } = HPAX.Types . decode_integer ( rest , 5 )
137
+
138
+ # Finally, ensure that the decoder makes proper sense of this encoding and that it resizes
139
+ # back down to the size chosen by the encoder
140
+ assert { :ok , _decoded , dec_table } = HPAX . decode ( encoded , dec_table )
141
+ assert dec_table . size == enc_table . size
142
+ assert enc_table . max_table_size == 30_000
143
+ assert dec_table . max_table_size == 30_000
144
+
145
+ # Scenario 2: Simulate the decoder shrinking the table ia settings
146
+
147
+ # First, the decoder resizes its table to some maximum size
148
+ dec_table = HPAX . resize ( dec_table , 10_000 )
149
+
150
+ # It then communicates that size to the encoder, who chooses a smaller size
125
151
enc_table = HPAX . resize ( enc_table , 0 )
152
+
153
+ # It then changes its mind and goes back up to a size still smaller than the decoder's choice
126
154
enc_table = HPAX . resize ( enc_table , 1234 )
155
+
156
+ # Now, encode a header
127
157
{ encoded , enc_table } = HPAX . encode ( [ { :store , "lame" , "LAME" } ] , enc_table )
128
158
encoded = IO . iodata_to_binary ( encoded )
129
159
130
- # Ensure that we see two resizes in order
160
+ # Ensure that we encoded two resizes in order on the wire
131
161
assert << 0b001 :: 3 , rest :: bitstring >> = encoded
132
162
assert { :ok , 0 , rest } = HPAX.Types . decode_integer ( rest , 5 )
133
163
assert << 0b001 :: 3 , rest :: bitstring >> = rest
0 commit comments