@@ -499,18 +499,15 @@ func TestConnDetach(t *testing.T) {
499499func TestParallelShortConnection (t * testing.T ) {
500500 ln , err := createTestListener ("tcp" , ":12345" )
501501 MustNil (t , err )
502- defer ln .Close ()
503-
504502 var received int64
505503 el , err := NewEventLoop (func (ctx context.Context , connection Connection ) error {
506504 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 ))
510506 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 ())
512508 return nil
513509 })
510+ defer el .Shutdown (context .Background ())
514511 go func () {
515512 el .Serve (ln )
516513 }()
@@ -536,10 +533,11 @@ func TestParallelShortConnection(t *testing.T) {
536533 }
537534 wg .Wait ()
538535
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 {
541538 time .Sleep (time .Millisecond * 100 )
542539 }
540+ Equal (t , atomic .LoadInt64 (& received ), int64 (totalSize ))
543541}
544542
545543func TestConnectionServerClose (t * testing.T ) {
@@ -643,8 +641,6 @@ func TestConnectionServerClose(t *testing.T) {
643641func TestConnectionDailTimeoutAndClose (t * testing.T ) {
644642 ln , err := createTestListener ("tcp" , ":12345" )
645643 MustNil (t , err )
646- defer ln .Close ()
647-
648644 el , err := NewEventLoop (
649645 func (ctx context.Context , connection Connection ) error {
650646 _ , err = connection .Reader ().Next (connection .Reader ().Len ())
@@ -668,7 +664,7 @@ func TestConnectionDailTimeoutAndClose(t *testing.T) {
668664 go func () {
669665 defer wg .Done ()
670666 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 )
672668 _ = conn
673669 }()
674670 }
0 commit comments