@@ -499,18 +499,15 @@ func TestConnDetach(t *testing.T) {
499
499
func TestParallelShortConnection (t * testing.T ) {
500
500
ln , err := createTestListener ("tcp" , ":12345" )
501
501
MustNil (t , err )
502
- defer ln .Close ()
503
-
504
502
var received int64
505
503
el , err := NewEventLoop (func (ctx context.Context , connection Connection ) error {
506
504
data , err := connection .Reader ().Next (connection .Reader ().Len ())
507
- if err != nil {
508
- return err
509
- }
505
+ Assert (t , err == nil || errors .Is (err , ErrEOF ))
510
506
atomic .AddInt64 (& received , int64 (len (data )))
511
- // t.Logf("conn[%s] received: %d, active: %v", connection.RemoteAddr(), len(data), connection.IsActive())
507
+ t .Logf ("conn[%s] received: %d, active: %v" , connection .RemoteAddr (), len (data ), connection .IsActive ())
512
508
return nil
513
509
})
510
+ defer el .Shutdown (context .Background ())
514
511
go func () {
515
512
el .Serve (ln )
516
513
}()
@@ -536,10 +533,11 @@ func TestParallelShortConnection(t *testing.T) {
536
533
}
537
534
wg .Wait ()
538
535
539
- for atomic . LoadInt64 ( & received ) < int64 ( totalSize ) {
540
- t . Logf ( "received: %d, except: %d" , atomic .LoadInt64 (& received ), totalSize )
536
+ start := time . Now ()
537
+ for atomic .LoadInt64 (& received ) < int64 ( totalSize ) && time . Now (). Sub ( start ) < time . Second {
541
538
time .Sleep (time .Millisecond * 100 )
542
539
}
540
+ Equal (t , atomic .LoadInt64 (& received ), int64 (totalSize ))
543
541
}
544
542
545
543
func TestConnectionServerClose (t * testing.T ) {
@@ -643,8 +641,6 @@ func TestConnectionServerClose(t *testing.T) {
643
641
func TestConnectionDailTimeoutAndClose (t * testing.T ) {
644
642
ln , err := createTestListener ("tcp" , ":12345" )
645
643
MustNil (t , err )
646
- defer ln .Close ()
647
-
648
644
el , err := NewEventLoop (
649
645
func (ctx context.Context , connection Connection ) error {
650
646
_ , err = connection .Reader ().Next (connection .Reader ().Len ())
@@ -668,7 +664,7 @@ func TestConnectionDailTimeoutAndClose(t *testing.T) {
668
664
go func () {
669
665
defer wg .Done ()
670
666
conn , err := DialConnection ("tcp" , ":12345" , time .Nanosecond )
671
- Assert (t , err == nil || strings .Contains (err .Error (), "i/o timeout" ))
667
+ Assert (t , err == nil || strings .Contains (err .Error (), "i/o timeout" ), err )
672
668
_ = conn
673
669
}()
674
670
}
0 commit comments