micro/tunnel/reconnect_test.go

56 lines
929 B
Go
Raw Normal View History

// +build !race
package tunnel
import (
"sync"
"testing"
"time"
)
func TestReconnectTunnel(t *testing.T) {
2019-12-08 15:12:20 +03:00
// we manually override the tunnel.ReconnectTime value here
// this is so that we make the reconnects faster than the default 5s
ReconnectTime = 100 * time.Millisecond
// create a new tunnel client
tunA := NewTunnel(
2019-12-08 15:12:20 +03:00
Address("127.0.0.1:9098"),
Nodes("127.0.0.1:9099"),
)
// create a new tunnel server
tunB := NewTunnel(
2019-12-08 15:12:20 +03:00
Address("127.0.0.1:9099"),
)
// start tunnel
err := tunB.Connect()
if err != nil {
t.Fatal(err)
}
defer tunB.Close()
// start tunnel
err = tunA.Connect()
if err != nil {
t.Fatal(err)
}
defer tunA.Close()
wait := make(chan bool)
var wg sync.WaitGroup
wg.Add(1)
// start tunnel listener
go testBrokenTunAccept(t, tunB, wait, &wg)
wg.Add(1)
// start tunnel sender
2019-12-08 15:12:20 +03:00
go testBrokenTunSend(t, tunA, wait, &wg, ReconnectTime)
// wait until done
wg.Wait()
}