@@ -56,38 +56,25 @@ func TestSSEClient_Connect(t *testing.T) {
56
56
57
57
func TestSSEClient_Reconnect (t * testing.T ) {
58
58
port , _ := utils .GetAvailablePort ()
59
+ t .Log ("use port" , port )
59
60
eventType := DefaultEventType
60
- ctx , cancel := context .WithCancel (context .Background ())
61
- hub := NewHub (WithContext (ctx , cancel ))
62
- go runSSEServer2 (ctx , port , hub )
63
61
64
62
client := NewClient (fmt .Sprintf ("http://localhost:%d/events" , port ), WithClientReconnectTimeInterval (time .Millisecond * 100 ))
65
63
client .OnEvent (eventType , func (event * Event ) {
66
64
t .Log ("on event" , event )
67
65
})
68
66
err := client .Connect ()
69
67
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 )
74
69
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 ))
86
73
defer hub .Close ()
87
- _ = client . Connect ( )
74
+ go runSSEServer ( port , hub )
88
75
89
76
// wait for client to reconnect
90
- time .Sleep (2 * time .Second )
77
+ time .Sleep (3 * time .Second )
91
78
92
79
// expected connect is true
93
80
assert .True (t , client .GetConnectStatus (), "Client should be connected again" )
0 commit comments