@@ -16,16 +16,16 @@ func TestDecide(t *testing.T) {
1616 limit .precompute ()
1717
1818 // Begin by using 1 of our 10 requests.
19- d := maybeSpend (clk , Transaction {"test" , limit , 1 , true , true }, clk .Now ())
19+ d := maybeSpend (clk , Transaction {"test" , limit , 1 , true , true , false }, clk .Now ())
2020 test .Assert (t , d .allowed , "should be allowed" )
2121 test .AssertEquals (t , d .remaining , int64 (9 ))
2222 test .AssertEquals (t , d .retryIn , time .Duration (0 ))
2323 test .AssertEquals (t , d .resetIn , time .Second )
2424 // Transaction is set when we're allowed.
25- test .AssertEquals (t , d .transaction , Transaction {"test" , limit , 1 , true , true })
25+ test .AssertEquals (t , d .transaction , Transaction {"test" , limit , 1 , true , true , false })
2626
2727 // Immediately use another 9 of our remaining requests.
28- d = maybeSpend (clk , Transaction {"test" , limit , 9 , true , true }, d .newTAT )
28+ d = maybeSpend (clk , Transaction {"test" , limit , 9 , true , true , false }, d .newTAT )
2929 test .Assert (t , d .allowed , "should be allowed" )
3030 test .AssertEquals (t , d .remaining , int64 (0 ))
3131 // We should have to wait 1 second before we can use another request but we
@@ -37,21 +37,21 @@ func TestDecide(t *testing.T) {
3737 test .AssertEquals (t , d .newTAT , clk .Now ().Add (time .Second * 10 ))
3838
3939 // Let's try using just 1 more request without waiting.
40- d = maybeSpend (clk , Transaction {"test" , limit , 1 , true , true }, d .newTAT )
40+ d = maybeSpend (clk , Transaction {"test" , limit , 1 , true , true , false }, d .newTAT )
4141 test .Assert (t , ! d .allowed , "should not be allowed" )
4242 test .AssertEquals (t , d .remaining , int64 (0 ))
4343 test .AssertEquals (t , d .retryIn , time .Second )
4444 test .AssertEquals (t , d .resetIn , time .Second * 10 )
4545 // Transaction is set when we're denied.
46- test .AssertEquals (t , d .transaction , Transaction {"test" , limit , 1 , true , true })
46+ test .AssertEquals (t , d .transaction , Transaction {"test" , limit , 1 , true , true , false })
4747
4848 // Let's try being exactly as patient as we're told to be.
4949 clk .Add (d .retryIn )
50- d = maybeSpend (clk , Transaction {"test" , limit , 0 , true , true }, d .newTAT )
50+ d = maybeSpend (clk , Transaction {"test" , limit , 0 , true , true , false }, d .newTAT )
5151 test .AssertEquals (t , d .remaining , int64 (1 ))
5252
5353 // We are 1 second in the future, we should have 1 new request.
54- d = maybeSpend (clk , Transaction {"test" , limit , 1 , true , true }, d .newTAT )
54+ d = maybeSpend (clk , Transaction {"test" , limit , 1 , true , true , false }, d .newTAT )
5555 test .Assert (t , d .allowed , "should be allowed" )
5656 test .AssertEquals (t , d .remaining , int64 (0 ))
5757 test .AssertEquals (t , d .retryIn , time .Second )
@@ -61,7 +61,7 @@ func TestDecide(t *testing.T) {
6161 clk .Add (d .resetIn )
6262
6363 // We should have 10 new requests. If we use 1 we should have 9 remaining.
64- d = maybeSpend (clk , Transaction {"test" , limit , 1 , true , true }, d .newTAT )
64+ d = maybeSpend (clk , Transaction {"test" , limit , 1 , true , true , false }, d .newTAT )
6565 test .Assert (t , d .allowed , "should be allowed" )
6666 test .AssertEquals (t , d .remaining , int64 (9 ))
6767 test .AssertEquals (t , d .retryIn , time .Duration (0 ))
@@ -72,7 +72,7 @@ func TestDecide(t *testing.T) {
7272
7373 // We should still have 9 remaining because we're still 1ms shy of the
7474 // refill time.
75- d = maybeSpend (clk , Transaction {"test" , limit , 0 , true , true }, d .newTAT )
75+ d = maybeSpend (clk , Transaction {"test" , limit , 0 , true , true , false }, d .newTAT )
7676 test .Assert (t , d .allowed , "should be allowed" )
7777 test .AssertEquals (t , d .remaining , int64 (9 ))
7878 test .AssertEquals (t , d .retryIn , time .Duration (0 ))
@@ -83,15 +83,15 @@ func TestDecide(t *testing.T) {
8383 clk .Add (20 * time .Hour )
8484
8585 // C'mon, big money, no whammies, no whammies, STOP!
86- d = maybeSpend (clk , Transaction {"test" , limit , 0 , true , true }, d .newTAT )
86+ d = maybeSpend (clk , Transaction {"test" , limit , 0 , true , true , false }, d .newTAT )
8787 test .Assert (t , d .allowed , "should be allowed" )
8888 test .AssertEquals (t , d .remaining , int64 (10 ))
8989 test .AssertEquals (t , d .retryIn , time .Duration (0 ))
9090 test .AssertEquals (t , d .resetIn , time .Duration (0 ))
9191
9292 // Turns out that the most we can accrue is 10 (limit.Burst). Let's empty
9393 // this bucket out so we can try something else.
94- d = maybeSpend (clk , Transaction {"test" , limit , 10 , true , true }, d .newTAT )
94+ d = maybeSpend (clk , Transaction {"test" , limit , 10 , true , true , false }, d .newTAT )
9595 test .Assert (t , d .allowed , "should be allowed" )
9696 test .AssertEquals (t , d .remaining , int64 (0 ))
9797 // We should have to wait 1 second before we can use another request but we
@@ -101,14 +101,14 @@ func TestDecide(t *testing.T) {
101101 test .AssertEquals (t , d .resetIn , time .Second * 10 )
102102
103103 // If you spend 0 while you have 0 you should get 0.
104- d = maybeSpend (clk , Transaction {"test" , limit , 0 , true , true }, d .newTAT )
104+ d = maybeSpend (clk , Transaction {"test" , limit , 0 , true , true , false }, d .newTAT )
105105 test .Assert (t , d .allowed , "should be allowed" )
106106 test .AssertEquals (t , d .remaining , int64 (0 ))
107107 test .AssertEquals (t , d .retryIn , time .Duration (0 ))
108108 test .AssertEquals (t , d .resetIn , time .Second * 10 )
109109
110110 // We don't play by the rules, we spend 1 when we have 0.
111- d = maybeSpend (clk , Transaction {"test" , limit , 1 , true , true }, d .newTAT )
111+ d = maybeSpend (clk , Transaction {"test" , limit , 1 , true , true , false }, d .newTAT )
112112 test .Assert (t , ! d .allowed , "should not be allowed" )
113113 test .AssertEquals (t , d .remaining , int64 (0 ))
114114 test .AssertEquals (t , d .retryIn , time .Second )
@@ -118,7 +118,7 @@ func TestDecide(t *testing.T) {
118118 clk .Add (d .retryIn )
119119
120120 // Our patience pays off, we should have 1 new request. Let's use it.
121- d = maybeSpend (clk , Transaction {"test" , limit , 1 , true , true }, d .newTAT )
121+ d = maybeSpend (clk , Transaction {"test" , limit , 1 , true , true , false }, d .newTAT )
122122 test .Assert (t , d .allowed , "should be allowed" )
123123 test .AssertEquals (t , d .remaining , int64 (0 ))
124124 test .AssertEquals (t , d .retryIn , time .Second )
@@ -130,7 +130,7 @@ func TestDecide(t *testing.T) {
130130 // Attempt to spend 7 when we only have 5. We should be denied but the
131131 // decision should reflect a retry of 2 seconds, the time it would take to
132132 // refill from 5 to 7.
133- d = maybeSpend (clk , Transaction {"test" , limit , 7 , true , true }, d .newTAT )
133+ d = maybeSpend (clk , Transaction {"test" , limit , 7 , true , true , false }, d .newTAT )
134134 test .Assert (t , ! d .allowed , "should not be allowed" )
135135 test .AssertEquals (t , d .remaining , int64 (5 ))
136136 test .AssertEquals (t , d .retryIn , time .Second * 2 )
@@ -143,28 +143,28 @@ func TestMaybeRefund(t *testing.T) {
143143 limit .precompute ()
144144
145145 // Begin by using 1 of our 10 requests.
146- d := maybeSpend (clk , Transaction {"test" , limit , 1 , true , true }, clk .Now ())
146+ d := maybeSpend (clk , Transaction {"test" , limit , 1 , true , true , false }, clk .Now ())
147147 test .Assert (t , d .allowed , "should be allowed" )
148148 test .AssertEquals (t , d .remaining , int64 (9 ))
149149 test .AssertEquals (t , d .retryIn , time .Duration (0 ))
150150 test .AssertEquals (t , d .resetIn , time .Second )
151151 // Transaction is set when we're refunding.
152- test .AssertEquals (t , d .transaction , Transaction {"test" , limit , 1 , true , true })
152+ test .AssertEquals (t , d .transaction , Transaction {"test" , limit , 1 , true , true , false })
153153
154154 // Refund back to 10.
155- d = maybeRefund (clk , Transaction {"test" , limit , 1 , true , true }, d .newTAT )
155+ d = maybeRefund (clk , Transaction {"test" , limit , 1 , true , true , false }, d .newTAT )
156156 test .AssertEquals (t , d .remaining , int64 (10 ))
157157 test .AssertEquals (t , d .retryIn , time .Duration (0 ))
158158 test .AssertEquals (t , d .resetIn , time .Duration (0 ))
159159
160160 // Refund 0, we should still have 10.
161- d = maybeRefund (clk , Transaction {"test" , limit , 0 , true , true }, d .newTAT )
161+ d = maybeRefund (clk , Transaction {"test" , limit , 0 , true , true , false }, d .newTAT )
162162 test .AssertEquals (t , d .remaining , int64 (10 ))
163163 test .AssertEquals (t , d .retryIn , time .Duration (0 ))
164164 test .AssertEquals (t , d .resetIn , time .Duration (0 ))
165165
166166 // Spend 1 more of our 10 requests.
167- d = maybeSpend (clk , Transaction {"test" , limit , 1 , true , true }, d .newTAT )
167+ d = maybeSpend (clk , Transaction {"test" , limit , 1 , true , true , false }, d .newTAT )
168168 test .Assert (t , d .allowed , "should be allowed" )
169169 test .AssertEquals (t , d .remaining , int64 (9 ))
170170 test .AssertEquals (t , d .retryIn , time .Duration (0 ))
@@ -174,16 +174,16 @@ func TestMaybeRefund(t *testing.T) {
174174 clk .Add (d .resetIn )
175175
176176 // Attempt to refund from 10 to 11.
177- d = maybeRefund (clk , Transaction {"test" , limit , 1 , true , true }, d .newTAT )
177+ d = maybeRefund (clk , Transaction {"test" , limit , 1 , true , true , false }, d .newTAT )
178178 test .Assert (t , ! d .allowed , "should not be allowed" )
179179 test .AssertEquals (t , d .remaining , int64 (10 ))
180180 test .AssertEquals (t , d .retryIn , time .Duration (0 ))
181181 test .AssertEquals (t , d .resetIn , time .Duration (0 ))
182182 // Transaction is set when our bucket is full.
183- test .AssertEquals (t , d .transaction , Transaction {"test" , limit , 1 , true , true })
183+ test .AssertEquals (t , d .transaction , Transaction {"test" , limit , 1 , true , true , false })
184184
185185 // Spend 10 all 10 of our requests.
186- d = maybeSpend (clk , Transaction {"test" , limit , 10 , true , true }, d .newTAT )
186+ d = maybeSpend (clk , Transaction {"test" , limit , 10 , true , true , false }, d .newTAT )
187187 test .Assert (t , d .allowed , "should be allowed" )
188188 test .AssertEquals (t , d .remaining , int64 (0 ))
189189 // We should have to wait 1 second before we can use another request but we
@@ -193,7 +193,7 @@ func TestMaybeRefund(t *testing.T) {
193193 test .AssertEquals (t , d .resetIn , time .Second * 10 )
194194
195195 // Attempt a refund of 10.
196- d = maybeRefund (clk , Transaction {"test" , limit , 10 , true , true }, d .newTAT )
196+ d = maybeRefund (clk , Transaction {"test" , limit , 10 , true , true , false }, d .newTAT )
197197 test .AssertEquals (t , d .remaining , int64 (10 ))
198198 test .AssertEquals (t , d .retryIn , time .Duration (0 ))
199199 test .AssertEquals (t , d .resetIn , time .Duration (0 ))
@@ -202,17 +202,17 @@ func TestMaybeRefund(t *testing.T) {
202202 clk .Add (11 * time .Second )
203203
204204 // Attempt to refund to 11, then ensure it's still 10.
205- d = maybeRefund (clk , Transaction {"test" , limit , 1 , true , true }, d .newTAT )
205+ d = maybeRefund (clk , Transaction {"test" , limit , 1 , true , true , false }, d .newTAT )
206206 test .Assert (t , ! d .allowed , "should be allowed" )
207207 test .AssertEquals (t , d .remaining , int64 (10 ))
208208 test .AssertEquals (t , d .retryIn , time .Duration (0 ))
209209 test .AssertEquals (t , d .resetIn , time .Duration (0 ))
210210 // Transaction is set when our TAT is in the past.
211- test .AssertEquals (t , d .transaction , Transaction {"test" , limit , 1 , true , true })
211+ test .AssertEquals (t , d .transaction , Transaction {"test" , limit , 1 , true , true , false })
212212
213213 // Spend 5 of our 10 requests, then refund 1.
214- d = maybeSpend (clk , Transaction {"test" , limit , 5 , true , true }, d .newTAT )
215- d = maybeRefund (clk , Transaction {"test" , limit , 1 , true , true }, d .newTAT )
214+ d = maybeSpend (clk , Transaction {"test" , limit , 5 , true , true , false }, d .newTAT )
215+ d = maybeRefund (clk , Transaction {"test" , limit , 1 , true , true , false }, d .newTAT )
216216 test .Assert (t , d .allowed , "should be allowed" )
217217 test .AssertEquals (t , d .remaining , int64 (6 ))
218218 test .AssertEquals (t , d .retryIn , time .Duration (0 ))
@@ -221,15 +221,15 @@ func TestMaybeRefund(t *testing.T) {
221221 clk .Add (time .Millisecond * 2500 )
222222
223223 // Ensure we have 8.5 requests.
224- d = maybeSpend (clk , Transaction {"test" , limit , 0 , true , true }, d .newTAT )
224+ d = maybeSpend (clk , Transaction {"test" , limit , 0 , true , true , false }, d .newTAT )
225225 test .Assert (t , d .allowed , "should be allowed" )
226226 test .AssertEquals (t , d .remaining , int64 (8 ))
227227 test .AssertEquals (t , d .retryIn , time .Duration (0 ))
228228 // Check that ResetIn represents the fractional earned request.
229229 test .AssertEquals (t , d .resetIn , time .Millisecond * 1500 )
230230
231231 // Refund 2 requests, we should only have 10, not 10.5.
232- d = maybeRefund (clk , Transaction {"test" , limit , 2 , true , true }, d .newTAT )
232+ d = maybeRefund (clk , Transaction {"test" , limit , 2 , true , true , false }, d .newTAT )
233233 test .AssertEquals (t , d .remaining , int64 (10 ))
234234 test .AssertEquals (t , d .retryIn , time .Duration (0 ))
235235 test .AssertEquals (t , d .resetIn , time .Duration (0 ))
0 commit comments