@@ -56,38 +56,25 @@ func TestSSEClient_Connect(t *testing.T) {
5656
5757func TestSSEClient_Reconnect (t * testing.T ) {
5858 port , _ := utils .GetAvailablePort ()
59+ t .Log ("use port" , port )
5960 eventType := DefaultEventType
60- ctx , cancel := context .WithCancel (context .Background ())
61- hub := NewHub (WithContext (ctx , cancel ))
62- go runSSEServer2 (ctx , port , hub )
6361
6462 client := NewClient (fmt .Sprintf ("http://localhost:%d/events" , port ), WithClientReconnectTimeInterval (time .Millisecond * 100 ))
6563 client .OnEvent (eventType , func (event * Event ) {
6664 t .Log ("on event" , event )
6765 })
6866 err := client .Connect ()
6967 assert .NoError (t , err )
70- time .Sleep (200 * time .Millisecond )
71-
72- // expected connect is true
73- assert .True (t , client .GetConnectStatus (), "Client should be connected" )
68+ time .Sleep (300 * time .Millisecond )
7469
75- // close sse server
76- hub .Close ()
77-
78- time .Sleep (time .Millisecond * 300 )
79- // expected connect is false
80- assert .False (t , client .GetConnectStatus (), "Client should be disconnected" )
81-
82- // run sse server again
83- ctx , cancel = context .WithCancel (context .Background ())
84- hub = NewHub (WithContext (ctx , cancel ))
85- go runSSEServer2 (ctx , port , hub )
70+ // run sse server
71+ ctx , cancel := context .WithCancel (context .Background ())
72+ hub := NewHub (WithContext (ctx , cancel ))
8673 defer hub .Close ()
87- _ = client . Connect ( )
74+ go runSSEServer ( port , hub )
8875
8976 // wait for client to reconnect
90- time .Sleep (2 * time .Second )
77+ time .Sleep (3 * time .Second )
9178
9279 // expected connect is true
9380 assert .True (t , client .GetConnectStatus (), "Client should be connected again" )
0 commit comments