61 lines
2.0 KiB
Go
61 lines
2.0 KiB
Go
|
|
package notify
|
||
|
|
|
||
|
|
import (
|
||
|
|
"net"
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestServerResolveOutboundTransportNilLogical(t *testing.T) {
|
||
|
|
server := NewServer().(*ServerCommon)
|
||
|
|
|
||
|
|
if route := server.resolveOutboundRoute(nil); route.logical != nil || route.transport != nil {
|
||
|
|
t.Fatalf("nil logical route mismatch: %+v", route)
|
||
|
|
}
|
||
|
|
if transport := server.resolveOutboundTransport(nil); transport != nil {
|
||
|
|
t.Fatalf("resolveOutboundTransport(nil) = %+v, want nil", transport)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestServerResolveOutboundTransportUsesCurrentGeneration(t *testing.T) {
|
||
|
|
server := NewServer().(*ServerCommon)
|
||
|
|
|
||
|
|
firstLeft, firstRight := net.Pipe()
|
||
|
|
defer firstRight.Close()
|
||
|
|
logical := server.bootstrapAcceptedLogical("outbound-route", nil, firstLeft)
|
||
|
|
if logical == nil {
|
||
|
|
t.Fatal("bootstrapAcceptedLogical should return logical")
|
||
|
|
}
|
||
|
|
|
||
|
|
first := server.resolveOutboundTransport(logical)
|
||
|
|
if first == nil {
|
||
|
|
t.Fatal("initial outbound transport should exist")
|
||
|
|
}
|
||
|
|
if !first.IsCurrent() {
|
||
|
|
t.Fatal("initial outbound transport should be current")
|
||
|
|
}
|
||
|
|
|
||
|
|
secondLeft, secondRight := net.Pipe()
|
||
|
|
defer secondLeft.Close()
|
||
|
|
defer secondRight.Close()
|
||
|
|
if err := server.attachAcceptedLogicalTransport(logical, secondLeft.RemoteAddr(), secondLeft); err != nil {
|
||
|
|
t.Fatalf("attachAcceptedLogicalTransport failed: %v", err)
|
||
|
|
}
|
||
|
|
|
||
|
|
second := server.resolveOutboundTransport(logical)
|
||
|
|
if second == nil {
|
||
|
|
t.Fatal("resolved outbound transport after reattach should exist")
|
||
|
|
}
|
||
|
|
if !second.IsCurrent() {
|
||
|
|
t.Fatal("resolved outbound transport after reattach should be current")
|
||
|
|
}
|
||
|
|
if got, want := second.TransportGeneration(), logical.clientConnTransportGenerationSnapshot(); got != want {
|
||
|
|
t.Fatalf("resolved outbound generation = %d, want %d", got, want)
|
||
|
|
}
|
||
|
|
if first.TransportGeneration() == second.TransportGeneration() {
|
||
|
|
t.Fatalf("outbound generation should change after reattach: first=%d second=%d", first.TransportGeneration(), second.TransportGeneration())
|
||
|
|
}
|
||
|
|
if first.IsCurrent() {
|
||
|
|
t.Fatal("first outbound transport should become stale after reattach")
|
||
|
|
}
|
||
|
|
}
|