@@ -10,6 +10,7 @@ import (
1010 mux "github.com/cbeuw/Cloak/internal/multiplex"
1111 "github.com/cbeuw/Cloak/internal/server"
1212 "github.com/cbeuw/connutil"
13+ "github.com/stretchr/testify/assert"
1314 "io"
1415 "io/ioutil"
1516 "math/rand"
@@ -356,17 +357,9 @@ func TestTCPSingleplex(t *testing.T) {
356357
357358 proxyConn1 .Close ()
358359
359- retries := 0
360- retry:
361- time .Sleep (delayBeforeTestingConnClose )
362- if user .NumSession () != 1 {
363- retries ++
364- if retries > connCloseRetries {
365- t .Error ("first session was not closed on connection close" )
366- } else {
367- goto retry
368- }
369- }
360+ assert .Eventually (t , func () bool {
361+ return user .NumSession () == 1
362+ }, time .Second , 10 * time .Millisecond , "first session was not closed on connection close" )
370363
371364 // conn2 should still work
372365 runEchoTest (t , []net.Conn {proxyConn2 }, 65536 )
@@ -479,17 +472,10 @@ func TestClosingStreamsFromProxy(t *testing.T) {
479472 serverConn , _ := proxyFromCkServerL .Accept ()
480473 serverConn .Close ()
481474
482- retries := 0
483- retry:
484- time .Sleep (delayBeforeTestingConnClose )
485- if _ , err := clientConn .Read (make ([]byte , 16 )); err == nil {
486- retries ++
487- if retries > connCloseRetries {
488- t .Errorf ("closing stream on server side is not reflected to the client: %v" , err )
489- } else {
490- goto retry
491- }
492- }
475+ assert .Eventually (t , func () bool {
476+ _ , err := clientConn .Read (make ([]byte , 16 ))
477+ return err != nil
478+ }, time .Second , 10 * time .Millisecond , "closing stream on server side is not reflected to the client" )
493479 })
494480
495481 t .Run ("closing from client" , func (t * testing.T ) {
@@ -499,17 +485,10 @@ func TestClosingStreamsFromProxy(t *testing.T) {
499485 serverConn , _ := proxyFromCkServerL .Accept ()
500486 clientConn .Close ()
501487
502- retries := 0
503- retry:
504- time .Sleep (delayBeforeTestingConnClose )
505- if _ , err := serverConn .Read (make ([]byte , 16 )); err == nil {
506- retries ++
507- if retries > 3 {
508- t .Errorf ("closing stream on client side is not reflected to the server: %v" , err )
509- } else {
510- goto retry
511- }
512- }
488+ assert .Eventually (t , func () bool {
489+ _ , err := serverConn .Read (make ([]byte , 16 ))
490+ return err != nil
491+ }, time .Second , 10 * time .Millisecond , "closing stream on client side is not reflected to the server" )
513492 })
514493
515494 t .Run ("send then close" , func (t * testing.T ) {
0 commit comments