Skip to content

Commit d1404eb

Browse files
authored
Merge pull request #167 from fastly/dgryski/httpcache-test-improvements
httpcache test improvements
2 parents d4c6571 + a1ba3f3 commit d1404eb

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

integration_tests/httpcache/main.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"math/rand"
1313
"runtime"
1414
"strconv"
15+
"strings"
1516
"sync"
1617
"time"
1718

@@ -83,23 +84,27 @@ func main() {
8384

8485
type query struct {
8586
status *int
87+
wait time.Duration
8688
}
8789

8890
func (q *query) String() string {
8991
if q == nil {
9092
return ""
9193
}
9294

93-
var s string
95+
var args []string
9496

9597
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)
100105
}
101106

102-
return "?" + s
107+
return "?" + strings.Join(args, "&")
103108
}
104109

105110
func getTestReq(method string, q *query, body io.Reader) *fsthttp.Request {
@@ -240,7 +245,7 @@ func testBeforeSendAddHeader(ctx context.Context) error {
240245
}
241246

242247
func testRequestCollapse(ctx context.Context) error {
243-
r := getTestReq("", nil, nil)
248+
r := getTestReq("", &query{wait: 1 * time.Second}, nil)
244249

245250
var beforeSendCount int
246251
var mu sync.Mutex
@@ -265,13 +270,15 @@ func testRequestCollapse(ctx context.Context) error {
265270
<-ch
266271
var err error
267272
resp, err = r.Send(ctx, backend)
273+
time.Sleep(10 * time.Millisecond)
268274
errch <- err
269275
}()
270276

271277
go func() {
272278
<-ch
273279
var err error
274280
resp2, err = r2.Send(ctx, backend)
281+
time.Sleep(20 * time.Millisecond)
275282
errch <- err
276283
}()
277284

0 commit comments

Comments
 (0)