File tree Expand file tree Collapse file tree 2 files changed +36
-4
lines changed Expand file tree Collapse file tree 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) {
264264 err = c1 .Close (websocket .StatusNormalClosure , "" )
265265 assert .Success (t , err )
266266 })
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+ })
267298}
268299
269300func 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
5959 }
6060 if o .HTTPClient == nil {
6161 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 )
6465
65- newClient := * opts .HTTPClient
66+ newClient := * o .HTTPClient
6667 newClient .Timeout = 0
67- opts .HTTPClient = & newClient
68+ o .HTTPClient = & newClient
6869 }
6970 if o .HTTPHeader == nil {
7071 o .HTTPHeader = http.Header {}
You can’t perform that action at this time.
0 commit comments