@@ -12,6 +12,7 @@ import (
12
12
"math/rand"
13
13
"runtime"
14
14
"strconv"
15
+ "strings"
15
16
"sync"
16
17
"time"
17
18
@@ -83,23 +84,27 @@ func main() {
83
84
84
85
type query struct {
85
86
status * int
87
+ wait time.Duration
86
88
}
87
89
88
90
func (q * query ) String () string {
89
91
if q == nil {
90
92
return ""
91
93
}
92
94
93
- var s string
95
+ var args [] string
94
96
95
97
if q .status != nil {
96
- if s != "" {
97
- s += "&"
98
- }
99
- s += fmt .Sprintf ("status=%v" , * q .status )
98
+ s := fmt .Sprintf ("status=%v" , * q .status )
99
+ args = append (args , s )
100
+ }
101
+
102
+ if q .wait != 0 {
103
+ s := fmt .Sprintf ("wait=%v" , q .wait .Milliseconds ())
104
+ args = append (args , s )
100
105
}
101
106
102
- return "?" + s
107
+ return "?" + strings . Join ( args , "&" )
103
108
}
104
109
105
110
func getTestReq (method string , q * query , body io.Reader ) * fsthttp.Request {
@@ -240,7 +245,7 @@ func testBeforeSendAddHeader(ctx context.Context) error {
240
245
}
241
246
242
247
func testRequestCollapse (ctx context.Context ) error {
243
- r := getTestReq ("" , nil , nil )
248
+ r := getTestReq ("" , & query { wait : 1 * time . Second } , nil )
244
249
245
250
var beforeSendCount int
246
251
var mu sync.Mutex
@@ -265,13 +270,15 @@ func testRequestCollapse(ctx context.Context) error {
265
270
<- ch
266
271
var err error
267
272
resp , err = r .Send (ctx , backend )
273
+ time .Sleep (10 * time .Millisecond )
268
274
errch <- err
269
275
}()
270
276
271
277
go func () {
272
278
<- ch
273
279
var err error
274
280
resp2 , err = r2 .Send (ctx , backend )
281
+ time .Sleep (20 * time .Millisecond )
275
282
errch <- err
276
283
}()
277
284
0 commit comments