Выпуск WDTT Plus v18
This commit is contained in:
1 parent
abf0a0f130
commit
b3935b947a
101 files changed
+16512
-1477
No files matched your search
@@ -89,3 +89,108 @@ func TestShortDNSErrorLimitsLongText(t *testing.T) {
|
||||
t.Fatalf("short error too long: %d", len(got))
|
||||
}
|
||||
}
|
||||
|
||||
func TestParsePeerEndpointAcceptsIPv4AndHostname(t *testing.T) {
|
||||
literal, err := parsePeerEndpoint("192.0.2.7:443")
|
||||
if err != nil || literal.Literal == nil || literal.Port != 443 {
|
||||
t.Fatalf("literal = %+v, err = %v", literal, err)
|
||||
}
|
||||
hostname, err := parsePeerEndpoint("example.com:51820")
|
||||
if err != nil || hostname.Literal != nil || hostname.Host != "example.com" || hostname.Port != 51820 {
|
||||
t.Fatalf("hostname = %+v, err = %v", hostname, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParsePeerEndpointRejectsPermanentConfigurationErrors(t *testing.T) {
|
||||
for _, value := range []string{"example.com", "example.com:0", "[2001:db8::1]:443", ":443"} {
|
||||
if _, err := parsePeerEndpoint(value); err == nil {
|
||||
t.Fatalf("parsePeerEndpoint(%q) succeeded", value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolvePeerUDPAddrFallsBackToAnotherResolverAndRequiresIPv4(t *testing.T) {
|
||||
endpoint, err := parsePeerEndpoint("example.com:51820")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
attempts := 0
|
||||
peer, err := resolvePeerUDPAddrOnceWithLookups(
|
||||
context.Background(),
|
||||
endpoint,
|
||||
[]peerIPLookup{
|
||||
func(context.Context, string) ([]net.IPAddr, error) {
|
||||
attempts++
|
||||
return nil, context.DeadlineExceeded
|
||||
},
|
||||
func(context.Context, string) ([]net.IPAddr, error) {
|
||||
attempts++
|
||||
return []net.IPAddr{{IP: net.ParseIP("2001:db8::1")}}, nil
|
||||
},
|
||||
func(context.Context, string) ([]net.IPAddr, error) {
|
||||
attempts++
|
||||
return []net.IPAddr{{IP: net.ParseIP("192.0.2.9")}}, nil
|
||||
},
|
||||
},
|
||||
)
|
||||
if err != nil || peer.String() != "192.0.2.9:51820" || attempts != 3 {
|
||||
t.Fatalf("peer = %v, attempts = %d, err = %v", peer, attempts, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWaitForPeerUDPAddrSurvivesTransientDNSFailure(t *testing.T) {
|
||||
endpoint, err := parsePeerEndpoint("example.com:51820")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
resolveAttempts := 0
|
||||
waits := 0
|
||||
warnings := 0
|
||||
peer, failures, err := waitForPeerUDPAddrWith(
|
||||
context.Background(),
|
||||
endpoint,
|
||||
func(context.Context, peerEndpoint) (*net.UDPAddr, error) {
|
||||
resolveAttempts++
|
||||
if resolveAttempts < 3 {
|
||||
return nil, errors.New("temporary DNS outage")
|
||||
}
|
||||
return &net.UDPAddr{IP: net.ParseIP("192.0.2.10"), Port: 51820}, nil
|
||||
},
|
||||
func(context.Context, time.Duration) error {
|
||||
waits++
|
||||
return nil
|
||||
},
|
||||
func(int, error) { warnings++ },
|
||||
)
|
||||
if err != nil || peer.String() != "192.0.2.10:51820" || failures != 2 {
|
||||
t.Fatalf("peer = %v, failures = %d, err = %v", peer, failures, err)
|
||||
}
|
||||
if resolveAttempts != 3 || waits != 2 || warnings != 2 {
|
||||
t.Fatalf("resolve=%d waits=%d warnings=%d", resolveAttempts, waits, warnings)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWaitForPeerUDPAddrStopsWhenContextIsCancelled(t *testing.T) {
|
||||
endpoint, err := parsePeerEndpoint("example.com:51820")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
resolveAttempts := 0
|
||||
_, _, err = waitForPeerUDPAddrWith(
|
||||
ctx,
|
||||
endpoint,
|
||||
func(context.Context, peerEndpoint) (*net.UDPAddr, error) {
|
||||
resolveAttempts++
|
||||
return nil, errors.New("temporary DNS outage")
|
||||
},
|
||||
func(context.Context, time.Duration) error {
|
||||
cancel()
|
||||
return context.Canceled
|
||||
},
|
||||
nil,
|
||||
)
|
||||
if !errors.Is(err, context.Canceled) || resolveAttempts != 1 {
|
||||
t.Fatalf("attempts = %d, err = %v", resolveAttempts, err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user