@@ -31,7 +31,7 @@ type connHandler struct {
31
31
type clientEvents struct {
32
32
* BuiltinEventEngine
33
33
tester * testing.T
34
- svr * testClientServer
34
+ svr * testClient
35
35
packetLen int
36
36
}
37
37
@@ -87,117 +87,219 @@ func (ev *clientEvents) OnShutdown(e Engine) {
87
87
assert .EqualValuesf (ev .tester , fd , - 1 , "expected -1, but got: %d" , fd )
88
88
}
89
89
90
- func TestServeWithGnetClient (t * testing.T ) {
90
+ func TestClient (t * testing.T ) {
91
91
// start an engine
92
92
// connect 10 clients
93
93
// each client will pipe random data for 1-3 seconds.
94
94
// the writes to the engine will be random sizes. 0KB - 1MB.
95
95
// the engine will echo back the data.
96
96
// waits for graceful connection closing.
97
- t .Run ("poll" , func (t * testing.T ) {
97
+ t .Run ("poll-LT " , func (t * testing.T ) {
98
98
t .Run ("tcp" , func (t * testing.T ) {
99
99
t .Run ("1-loop" , func (t * testing.T ) {
100
- testServeWithGnetClient (t , "tcp" , ":9991" , false , false , false , false , 10 , RoundRobin )
100
+ runClient (t , "tcp" , ":9991" , false , false , false , false , 10 , RoundRobin )
101
101
})
102
102
t .Run ("N-loop" , func (t * testing.T ) {
103
- testServeWithGnetClient (t , "tcp" , ":9992" , false , false , true , false , 10 , LeastConnections )
103
+ runClient (t , "tcp" , ":9992" , false , false , true , false , 10 , LeastConnections )
104
104
})
105
105
})
106
106
t .Run ("tcp-async" , func (t * testing.T ) {
107
107
t .Run ("1-loop" , func (t * testing.T ) {
108
- testServeWithGnetClient (t , "tcp" , ":9991" , false , false , false , true , 10 , RoundRobin )
108
+ runClient (t , "tcp" , ":9991" , false , false , false , true , 10 , RoundRobin )
109
109
})
110
110
t .Run ("N-loop" , func (t * testing.T ) {
111
- testServeWithGnetClient (t , "tcp" , ":9992" , false , false , true , true , 10 , LeastConnections )
111
+ runClient (t , "tcp" , ":9992" , false , false , true , true , 10 , LeastConnections )
112
112
})
113
113
})
114
114
t .Run ("udp" , func (t * testing.T ) {
115
115
t .Run ("1-loop" , func (t * testing.T ) {
116
- testServeWithGnetClient (t , "udp" , ":9991" , false , false , false , false , 10 , RoundRobin )
116
+ runClient (t , "udp" , ":9991" , false , false , false , false , 10 , RoundRobin )
117
117
})
118
118
t .Run ("N-loop" , func (t * testing.T ) {
119
- testServeWithGnetClient (t , "udp" , ":9992" , false , false , true , false , 10 , LeastConnections )
119
+ runClient (t , "udp" , ":9992" , false , false , true , false , 10 , LeastConnections )
120
120
})
121
121
})
122
122
t .Run ("udp-async" , func (t * testing.T ) {
123
123
t .Run ("1-loop" , func (t * testing.T ) {
124
- testServeWithGnetClient (t , "udp" , ":9991" , false , false , false , true , 10 , RoundRobin )
124
+ runClient (t , "udp" , ":9991" , false , false , false , true , 10 , RoundRobin )
125
125
})
126
126
t .Run ("N-loop" , func (t * testing.T ) {
127
- testServeWithGnetClient (t , "udp" , ":9992" , false , false , true , true , 10 , LeastConnections )
127
+ runClient (t , "udp" , ":9992" , false , false , true , true , 10 , LeastConnections )
128
128
})
129
129
})
130
130
t .Run ("unix" , func (t * testing.T ) {
131
131
t .Run ("1-loop" , func (t * testing.T ) {
132
- testServeWithGnetClient (t , "unix" , "gnet1.sock" , false , false , false , false , 10 , RoundRobin )
132
+ runClient (t , "unix" , "gnet1.sock" , false , false , false , false , 10 , RoundRobin )
133
133
})
134
134
t .Run ("N-loop" , func (t * testing.T ) {
135
- testServeWithGnetClient (t , "unix" , "gnet2.sock" , false , false , true , false , 10 , SourceAddrHash )
135
+ runClient (t , "unix" , "gnet2.sock" , false , false , true , false , 10 , SourceAddrHash )
136
136
})
137
137
})
138
138
t .Run ("unix-async" , func (t * testing.T ) {
139
139
t .Run ("1-loop" , func (t * testing.T ) {
140
- testServeWithGnetClient (t , "unix" , "gnet1.sock" , false , false , false , true , 10 , RoundRobin )
140
+ runClient (t , "unix" , "gnet1.sock" , false , false , false , true , 10 , RoundRobin )
141
141
})
142
142
t .Run ("N-loop" , func (t * testing.T ) {
143
- testServeWithGnetClient (t , "unix" , "gnet2.sock" , false , false , true , true , 10 , SourceAddrHash )
143
+ runClient (t , "unix" , "gnet2.sock" , false , false , true , true , 10 , SourceAddrHash )
144
144
})
145
145
})
146
146
})
147
147
148
- t .Run ("poll-reuseport " , func (t * testing.T ) {
148
+ t .Run ("poll-ET " , func (t * testing.T ) {
149
149
t .Run ("tcp" , func (t * testing.T ) {
150
150
t .Run ("1-loop" , func (t * testing.T ) {
151
- testServeWithGnetClient (t , "tcp" , ":9991" , true , true , false , false , 10 , RoundRobin )
151
+ runClient (t , "tcp" , ":9991" , true , false , false , false , 10 , RoundRobin )
152
152
})
153
153
t .Run ("N-loop" , func (t * testing.T ) {
154
- testServeWithGnetClient (t , "tcp" , ":9992" , true , true , true , false , 10 , LeastConnections )
154
+ runClient (t , "tcp" , ":9992" , true , false , true , false , 10 , LeastConnections )
155
155
})
156
156
})
157
157
t .Run ("tcp-async" , func (t * testing.T ) {
158
158
t .Run ("1-loop" , func (t * testing.T ) {
159
- testServeWithGnetClient (t , "tcp" , ":9991" , true , true , false , true , 10 , RoundRobin )
159
+ runClient (t , "tcp" , ":9991" , true , false , false , true , 10 , RoundRobin )
160
160
})
161
161
t .Run ("N-loop" , func (t * testing.T ) {
162
- testServeWithGnetClient (t , "tcp" , ":9992" , true , true , true , false , 10 , LeastConnections )
162
+ runClient (t , "tcp" , ":9992" , true , false , true , true , 10 , LeastConnections )
163
163
})
164
164
})
165
165
t .Run ("udp" , func (t * testing.T ) {
166
166
t .Run ("1-loop" , func (t * testing.T ) {
167
- testServeWithGnetClient (t , "udp" , ":9991" , true , true , false , false , 10 , RoundRobin )
167
+ runClient (t , "udp" , ":9991" , true , false , false , false , 10 , RoundRobin )
168
168
})
169
169
t .Run ("N-loop" , func (t * testing.T ) {
170
- testServeWithGnetClient (t , "udp" , ":9992" , true , true , true , false , 10 , LeastConnections )
170
+ runClient (t , "udp" , ":9992" , true , false , true , false , 10 , LeastConnections )
171
171
})
172
172
})
173
173
t .Run ("udp-async" , func (t * testing.T ) {
174
174
t .Run ("1-loop" , func (t * testing.T ) {
175
- testServeWithGnetClient (t , "udp" , ":9991" , true , true , false , false , 10 , RoundRobin )
175
+ runClient (t , "udp" , ":9991" , true , false , false , true , 10 , RoundRobin )
176
176
})
177
177
t .Run ("N-loop" , func (t * testing.T ) {
178
- testServeWithGnetClient (t , "udp" , ":9992" , true , true , true , true , 10 , LeastConnections )
178
+ runClient (t , "udp" , ":9992" , true , false , true , true , 10 , LeastConnections )
179
179
})
180
180
})
181
181
t .Run ("unix" , func (t * testing.T ) {
182
182
t .Run ("1-loop" , func (t * testing.T ) {
183
- testServeWithGnetClient (t , "unix" , "gnet1.sock" , true , true , false , false , 10 , RoundRobin )
183
+ runClient (t , "unix" , "gnet1.sock" , true , false , false , false , 10 , RoundRobin )
184
184
})
185
185
t .Run ("N-loop" , func (t * testing.T ) {
186
- testServeWithGnetClient (t , "unix" , "gnet2.sock" , true , true , true , false , 10 , LeastConnections )
186
+ runClient (t , "unix" , "gnet2.sock" , true , false , true , false , 10 , SourceAddrHash )
187
187
})
188
188
})
189
189
t .Run ("unix-async" , func (t * testing.T ) {
190
190
t .Run ("1-loop" , func (t * testing.T ) {
191
- testServeWithGnetClient (t , "unix" , "gnet1.sock" , true , true , false , true , 10 , RoundRobin )
191
+ runClient (t , "unix" , "gnet1.sock" , true , false , false , true , 10 , RoundRobin )
192
192
})
193
193
t .Run ("N-loop" , func (t * testing.T ) {
194
- testServeWithGnetClient (t , "unix" , "gnet2.sock" , true , true , true , true , 10 , LeastConnections )
194
+ runClient (t , "unix" , "gnet2.sock" , true , false , true , true , 10 , SourceAddrHash )
195
+ })
196
+ })
197
+ })
198
+
199
+ t .Run ("poll-LT-reuseport" , func (t * testing.T ) {
200
+ t .Run ("tcp" , func (t * testing.T ) {
201
+ t .Run ("1-loop" , func (t * testing.T ) {
202
+ runClient (t , "tcp" , ":9991" , false , true , false , false , 10 , RoundRobin )
203
+ })
204
+ t .Run ("N-loop" , func (t * testing.T ) {
205
+ runClient (t , "tcp" , ":9992" , false , true , true , false , 10 , LeastConnections )
206
+ })
207
+ })
208
+ t .Run ("tcp-async" , func (t * testing.T ) {
209
+ t .Run ("1-loop" , func (t * testing.T ) {
210
+ runClient (t , "tcp" , ":9991" , false , true , false , true , 10 , RoundRobin )
211
+ })
212
+ t .Run ("N-loop" , func (t * testing.T ) {
213
+ runClient (t , "tcp" , ":9992" , false , true , true , false , 10 , LeastConnections )
214
+ })
215
+ })
216
+ t .Run ("udp" , func (t * testing.T ) {
217
+ t .Run ("1-loop" , func (t * testing.T ) {
218
+ runClient (t , "udp" , ":9991" , false , true , false , false , 10 , RoundRobin )
219
+ })
220
+ t .Run ("N-loop" , func (t * testing.T ) {
221
+ runClient (t , "udp" , ":9992" , false , true , true , false , 10 , LeastConnections )
222
+ })
223
+ })
224
+ t .Run ("udp-async" , func (t * testing.T ) {
225
+ t .Run ("1-loop" , func (t * testing.T ) {
226
+ runClient (t , "udp" , ":9991" , false , true , false , false , 10 , RoundRobin )
227
+ })
228
+ t .Run ("N-loop" , func (t * testing.T ) {
229
+ runClient (t , "udp" , ":9992" , false , true , true , true , 10 , LeastConnections )
230
+ })
231
+ })
232
+ t .Run ("unix" , func (t * testing.T ) {
233
+ t .Run ("1-loop" , func (t * testing.T ) {
234
+ runClient (t , "unix" , "gnet1.sock" , false , true , false , false , 10 , RoundRobin )
235
+ })
236
+ t .Run ("N-loop" , func (t * testing.T ) {
237
+ runClient (t , "unix" , "gnet2.sock" , false , true , true , false , 10 , LeastConnections )
238
+ })
239
+ })
240
+ t .Run ("unix-async" , func (t * testing.T ) {
241
+ t .Run ("1-loop" , func (t * testing.T ) {
242
+ runClient (t , "unix" , "gnet1.sock" , false , true , false , true , 10 , RoundRobin )
243
+ })
244
+ t .Run ("N-loop" , func (t * testing.T ) {
245
+ runClient (t , "unix" , "gnet2.sock" , false , true , true , true , 10 , LeastConnections )
246
+ })
247
+ })
248
+ })
249
+
250
+ t .Run ("poll-ET-reuseport" , func (t * testing.T ) {
251
+ t .Run ("tcp" , func (t * testing.T ) {
252
+ t .Run ("1-loop" , func (t * testing.T ) {
253
+ runClient (t , "tcp" , ":9991" , true , true , false , false , 10 , RoundRobin )
254
+ })
255
+ t .Run ("N-loop" , func (t * testing.T ) {
256
+ runClient (t , "tcp" , ":9992" , true , true , true , false , 10 , LeastConnections )
257
+ })
258
+ })
259
+ t .Run ("tcp-async" , func (t * testing.T ) {
260
+ t .Run ("1-loop" , func (t * testing.T ) {
261
+ runClient (t , "tcp" , ":9991" , true , true , false , true , 10 , RoundRobin )
262
+ })
263
+ t .Run ("N-loop" , func (t * testing.T ) {
264
+ runClient (t , "tcp" , ":9992" , true , true , true , false , 10 , LeastConnections )
265
+ })
266
+ })
267
+ t .Run ("udp" , func (t * testing.T ) {
268
+ t .Run ("1-loop" , func (t * testing.T ) {
269
+ runClient (t , "udp" , ":9991" , true , true , false , false , 10 , RoundRobin )
270
+ })
271
+ t .Run ("N-loop" , func (t * testing.T ) {
272
+ runClient (t , "udp" , ":9992" , true , true , true , false , 10 , LeastConnections )
273
+ })
274
+ })
275
+ t .Run ("udp-async" , func (t * testing.T ) {
276
+ t .Run ("1-loop" , func (t * testing.T ) {
277
+ runClient (t , "udp" , ":9991" , true , true , false , false , 10 , RoundRobin )
278
+ })
279
+ t .Run ("N-loop" , func (t * testing.T ) {
280
+ runClient (t , "udp" , ":9992" , true , true , true , true , 10 , LeastConnections )
281
+ })
282
+ })
283
+ t .Run ("unix" , func (t * testing.T ) {
284
+ t .Run ("1-loop" , func (t * testing.T ) {
285
+ runClient (t , "unix" , "gnet1.sock" , true , true , false , false , 10 , RoundRobin )
286
+ })
287
+ t .Run ("N-loop" , func (t * testing.T ) {
288
+ runClient (t , "unix" , "gnet2.sock" , true , true , true , false , 10 , LeastConnections )
289
+ })
290
+ })
291
+ t .Run ("unix-async" , func (t * testing.T ) {
292
+ t .Run ("1-loop" , func (t * testing.T ) {
293
+ runClient (t , "unix" , "gnet1.sock" , true , true , false , true , 10 , RoundRobin )
294
+ })
295
+ t .Run ("N-loop" , func (t * testing.T ) {
296
+ runClient (t , "unix" , "gnet2.sock" , true , true , true , true , 10 , LeastConnections )
195
297
})
196
298
})
197
299
})
198
300
}
199
301
200
- type testClientServer struct {
302
+ type testClient struct {
201
303
* BuiltinEventEngine
202
304
client * Client
203
305
tester * testing.T
@@ -215,20 +317,20 @@ type testClientServer struct {
215
317
udpReadHeader int32
216
318
}
217
319
218
- func (s * testClientServer ) OnBoot (eng Engine ) (action Action ) {
320
+ func (s * testClient ) OnBoot (eng Engine ) (action Action ) {
219
321
s .eng = eng
220
322
return
221
323
}
222
324
223
- func (s * testClientServer ) OnOpen (c Conn ) (out []byte , action Action ) {
325
+ func (s * testClient ) OnOpen (c Conn ) (out []byte , action Action ) {
224
326
c .SetContext (& sync.Once {})
225
327
atomic .AddInt32 (& s .connected , 1 )
226
328
require .NotNil (s .tester , c .LocalAddr (), "nil local addr" )
227
329
require .NotNil (s .tester , c .RemoteAddr (), "nil remote addr" )
228
330
return
229
331
}
230
332
231
- func (s * testClientServer ) OnClose (c Conn , err error ) (action Action ) {
333
+ func (s * testClient ) OnClose (c Conn , err error ) (action Action ) {
232
334
if err != nil {
233
335
logging .Debugf ("error occurred on closed, %v\n " , err )
234
336
}
@@ -246,13 +348,13 @@ func (s *testClientServer) OnClose(c Conn, err error) (action Action) {
246
348
return
247
349
}
248
350
249
- func (s * testClientServer ) OnShutdown (Engine ) {
351
+ func (s * testClient ) OnShutdown (Engine ) {
250
352
if s .network == "udp" {
251
353
require .EqualValues (s .tester , int32 (s .nclients ), atomic .LoadInt32 (& s .udpReadHeader ))
252
354
}
253
355
}
254
356
255
- func (s * testClientServer ) OnTraffic (c Conn ) (action Action ) {
357
+ func (s * testClient ) OnTraffic (c Conn ) (action Action ) {
256
358
readHeader := func () {
257
359
ping := make ([]byte , len (pingMsg ))
258
360
n , err := io .ReadFull (c , ping )
@@ -302,7 +404,7 @@ func (s *testClientServer) OnTraffic(c Conn) (action Action) {
302
404
return
303
405
}
304
406
305
- func (s * testClientServer ) OnTick () (delay time.Duration , action Action ) {
407
+ func (s * testClient ) OnTick () (delay time.Duration , action Action ) {
306
408
delay = time .Second / 5
307
409
if atomic .CompareAndSwapInt32 (& s .started , 0 , 1 ) {
308
410
for i := 0 ; i < s .nclients ; i ++ {
@@ -321,8 +423,8 @@ func (s *testClientServer) OnTick() (delay time.Duration, action Action) {
321
423
return
322
424
}
323
425
324
- func testServeWithGnetClient (t * testing.T , network , addr string , reuseport , reuseaddr , multicore , async bool , nclients int , lb LoadBalancing ) {
325
- ts := & testClientServer {
426
+ func runClient (t * testing.T , network , addr string , et , reuseport , multicore , async bool , nclients int , lb LoadBalancing ) {
427
+ ts := & testClient {
326
428
tester : t ,
327
429
network : network ,
328
430
addr : addr ,
@@ -347,10 +449,10 @@ func testServeWithGnetClient(t *testing.T, network, addr string, reuseport, reus
347
449
348
450
err = Run (ts ,
349
451
network + "://" + addr ,
452
+ WithEdgeTriggeredIO (et ),
350
453
WithLockOSThread (async ),
351
454
WithMulticore (multicore ),
352
455
WithReusePort (reuseport ),
353
- WithReuseAddr (reuseaddr ),
354
456
WithTicker (true ),
355
457
WithTCPKeepAlive (time .Minute * 1 ),
356
458
WithTCPNoDelay (TCPDelay ),
0 commit comments