File tree 2 files changed +36
-4
lines changed
2 files changed +36
-4
lines changed Original file line number Diff line number Diff line change @@ -264,6 +264,37 @@ func TestConn(t *testing.T) {
264
264
err = c1 .Close (websocket .StatusNormalClosure , "" )
265
265
assert .Success (t , err )
266
266
})
267
+
268
+ t .Run ("HTTPClient.Timeout" , func (t * testing.T ) {
269
+ tt , c1 , c2 := newConnTest (t , & websocket.DialOptions {
270
+ HTTPClient : & http.Client {Timeout : time .Second * 5 },
271
+ }, nil )
272
+
273
+ tt .goEchoLoop (c2 )
274
+
275
+ c1 .SetReadLimit (1 << 30 )
276
+
277
+ exp := xrand .String (xrand .Int (131072 ))
278
+
279
+ werr := xsync .Go (func () error {
280
+ return wsjson .Write (tt .ctx , c1 , exp )
281
+ })
282
+
283
+ var act interface {}
284
+ err := wsjson .Read (tt .ctx , c1 , & act )
285
+ assert .Success (t , err )
286
+ assert .Equal (t , "read msg" , exp , act )
287
+
288
+ select {
289
+ case err := <- werr :
290
+ assert .Success (t , err )
291
+ case <- tt .ctx .Done ():
292
+ t .Fatal (tt .ctx .Err ())
293
+ }
294
+
295
+ err = c1 .Close (websocket .StatusNormalClosure , "" )
296
+ assert .Success (t , err )
297
+ })
267
298
}
268
299
269
300
func TestWasm (t * testing.T ) {
Original file line number Diff line number Diff line change @@ -59,12 +59,13 @@ func (opts *DialOptions) cloneWithDefaults(ctx context.Context) (context.Context
59
59
}
60
60
if o .HTTPClient == nil {
61
61
o .HTTPClient = http .DefaultClient
62
- } else if opts .HTTPClient .Timeout > 0 {
63
- ctx , cancel = context .WithTimeout (ctx , opts .HTTPClient .Timeout )
62
+ }
63
+ if o .HTTPClient .Timeout > 0 {
64
+ ctx , cancel = context .WithTimeout (ctx , o .HTTPClient .Timeout )
64
65
65
- newClient := * opts .HTTPClient
66
+ newClient := * o .HTTPClient
66
67
newClient .Timeout = 0
67
- opts .HTTPClient = & newClient
68
+ o .HTTPClient = & newClient
68
69
}
69
70
if o .HTTPHeader == nil {
70
71
o .HTTPHeader = http.Header {}
You can’t perform that action at this time.
0 commit comments