Updating server dependancies. (#7816)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
7304a61ef5
Коммит
1329aa51b6
148
vendor/github.com/miekg/dns/server_test.go
сгенерированный
поставляемый
148
vendor/github.com/miekg/dns/server_test.go
сгенерированный
поставляемый
@@ -147,7 +147,7 @@ func TestServing(t *testing.T) {
|
||||
defer HandleRemove("miek.nl.")
|
||||
defer HandleRemove("example.com.")
|
||||
|
||||
s, addrstr, err := RunLocalUDPServer("127.0.0.1:0")
|
||||
s, addrstr, err := RunLocalUDPServer(":0")
|
||||
if err != nil {
|
||||
t.Fatalf("unable to run test server: %v", err)
|
||||
}
|
||||
@@ -202,7 +202,7 @@ func TestServingTLS(t *testing.T) {
|
||||
Certificates: []tls.Certificate{cert},
|
||||
}
|
||||
|
||||
s, addrstr, err := RunLocalTLSServer("127.0.0.1:0", &config)
|
||||
s, addrstr, err := RunLocalTLSServer(":0", &config)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to run test server: %v", err)
|
||||
}
|
||||
@@ -247,13 +247,77 @@ func TestServingTLS(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestServingListenAndServe(t *testing.T) {
|
||||
HandleFunc("example.com.", AnotherHelloServer)
|
||||
defer HandleRemove("example.com.")
|
||||
|
||||
waitLock := sync.Mutex{}
|
||||
server := &Server{Addr: ":0", Net: "udp", ReadTimeout: time.Hour, WriteTimeout: time.Hour, NotifyStartedFunc: waitLock.Unlock}
|
||||
waitLock.Lock()
|
||||
|
||||
go func() {
|
||||
server.ListenAndServe()
|
||||
}()
|
||||
waitLock.Lock()
|
||||
|
||||
c, m := new(Client), new(Msg)
|
||||
m.SetQuestion("example.com.", TypeTXT)
|
||||
addr := server.PacketConn.LocalAddr().String() // Get address via the PacketConn that gets set.
|
||||
r, _, err := c.Exchange(m, addr)
|
||||
if err != nil {
|
||||
t.Fatal("failed to exchange example.com", err)
|
||||
}
|
||||
txt := r.Extra[0].(*TXT).Txt[0]
|
||||
if txt != "Hello example" {
|
||||
t.Error("unexpected result for example.com", txt, "!= Hello example")
|
||||
}
|
||||
server.Shutdown()
|
||||
}
|
||||
|
||||
func TestServingListenAndServeTLS(t *testing.T) {
|
||||
HandleFunc("example.com.", AnotherHelloServer)
|
||||
defer HandleRemove("example.com.")
|
||||
|
||||
cert, err := tls.X509KeyPair(CertPEMBlock, KeyPEMBlock)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to build certificate: %v", err)
|
||||
}
|
||||
|
||||
config := &tls.Config{
|
||||
Certificates: []tls.Certificate{cert},
|
||||
}
|
||||
|
||||
waitLock := sync.Mutex{}
|
||||
server := &Server{Addr: ":0", Net: "tcp", TLSConfig: config, ReadTimeout: time.Hour, WriteTimeout: time.Hour, NotifyStartedFunc: waitLock.Unlock}
|
||||
waitLock.Lock()
|
||||
|
||||
go func() {
|
||||
server.ListenAndServe()
|
||||
}()
|
||||
waitLock.Lock()
|
||||
|
||||
c, m := new(Client), new(Msg)
|
||||
c.Net = "tcp"
|
||||
m.SetQuestion("example.com.", TypeTXT)
|
||||
addr := server.Listener.Addr().String() // Get address via the Listener that gets set.
|
||||
r, _, err := c.Exchange(m, addr)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
txt := r.Extra[0].(*TXT).Txt[0]
|
||||
if txt != "Hello example" {
|
||||
t.Error("unexpected result for example.com", txt, "!= Hello example")
|
||||
}
|
||||
server.Shutdown()
|
||||
}
|
||||
|
||||
func BenchmarkServe(b *testing.B) {
|
||||
b.StopTimer()
|
||||
HandleFunc("miek.nl.", HelloServer)
|
||||
defer HandleRemove("miek.nl.")
|
||||
a := runtime.GOMAXPROCS(4)
|
||||
|
||||
s, addrstr, err := RunLocalUDPServer("127.0.0.1:0")
|
||||
s, addrstr, err := RunLocalUDPServer(":0")
|
||||
if err != nil {
|
||||
b.Fatalf("unable to run test server: %v", err)
|
||||
}
|
||||
@@ -306,7 +370,7 @@ func BenchmarkServeCompress(b *testing.B) {
|
||||
HandleFunc("miek.nl.", HelloServerCompress)
|
||||
defer HandleRemove("miek.nl.")
|
||||
a := runtime.GOMAXPROCS(4)
|
||||
s, addrstr, err := RunLocalUDPServer("127.0.0.1:0")
|
||||
s, addrstr, err := RunLocalUDPServer(":0")
|
||||
if err != nil {
|
||||
b.Fatalf("unable to run test server: %v", err)
|
||||
}
|
||||
@@ -407,7 +471,7 @@ func TestServingLargeResponses(t *testing.T) {
|
||||
HandleFunc("example.", HelloServerLargeResponse)
|
||||
defer HandleRemove("example.")
|
||||
|
||||
s, addrstr, err := RunLocalUDPServer("127.0.0.1:0")
|
||||
s, addrstr, err := RunLocalUDPServer(":0")
|
||||
if err != nil {
|
||||
t.Fatalf("unable to run test server: %v", err)
|
||||
}
|
||||
@@ -447,7 +511,7 @@ func TestServingResponse(t *testing.T) {
|
||||
t.Skip("skipping test in short mode.")
|
||||
}
|
||||
HandleFunc("miek.nl.", HelloServer)
|
||||
s, addrstr, err := RunLocalUDPServer("127.0.0.1:0")
|
||||
s, addrstr, err := RunLocalUDPServer(":0")
|
||||
if err != nil {
|
||||
t.Fatalf("unable to run test server: %v", err)
|
||||
}
|
||||
@@ -467,7 +531,7 @@ func TestServingResponse(t *testing.T) {
|
||||
}
|
||||
|
||||
s.Shutdown()
|
||||
s, addrstr, err = RunLocalUDPServerUnsafe("127.0.0.1:0")
|
||||
s, addrstr, err = RunLocalUDPServerUnsafe(":0")
|
||||
if err != nil {
|
||||
t.Fatalf("unable to run test server: %v", err)
|
||||
}
|
||||
@@ -481,7 +545,7 @@ func TestServingResponse(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestShutdownTCP(t *testing.T) {
|
||||
s, _, err := RunLocalTCPServer("127.0.0.1:0")
|
||||
s, _, err := RunLocalTCPServer(":0")
|
||||
if err != nil {
|
||||
t.Fatalf("unable to run test server: %v", err)
|
||||
}
|
||||
@@ -501,7 +565,7 @@ func TestShutdownTLS(t *testing.T) {
|
||||
Certificates: []tls.Certificate{cert},
|
||||
}
|
||||
|
||||
s, _, err := RunLocalTLSServer("127.0.0.1:0", &config)
|
||||
s, _, err := RunLocalTLSServer(":0", &config)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to run test server: %v", err)
|
||||
}
|
||||
@@ -529,7 +593,7 @@ func (t *trigger) Get() bool {
|
||||
|
||||
func TestHandlerCloseTCP(t *testing.T) {
|
||||
|
||||
ln, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
ln, err := net.Listen("tcp", ":0")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -553,7 +617,7 @@ func TestHandlerCloseTCP(t *testing.T) {
|
||||
exchange:
|
||||
_, _, err := c.Exchange(m, addr)
|
||||
if err != nil && err != io.EOF {
|
||||
t.Logf("exchange failed: %s\n", err)
|
||||
t.Errorf("exchange failed: %s\n", err)
|
||||
if tries == 3 {
|
||||
return
|
||||
}
|
||||
@@ -569,7 +633,7 @@ func TestHandlerCloseTCP(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestShutdownUDP(t *testing.T) {
|
||||
s, _, fin, err := RunLocalUDPServerWithFinChan("127.0.0.1:0")
|
||||
s, _, fin, err := RunLocalUDPServerWithFinChan(":0")
|
||||
if err != nil {
|
||||
t.Fatalf("unable to run test server: %v", err)
|
||||
}
|
||||
@@ -580,7 +644,23 @@ func TestShutdownUDP(t *testing.T) {
|
||||
select {
|
||||
case <-fin:
|
||||
case <-time.After(2 * time.Second):
|
||||
t.Error("Could not shutdown test UDP server. Gave up waiting")
|
||||
t.Error("could not shutdown test UDP server. Gave up waiting")
|
||||
}
|
||||
}
|
||||
|
||||
func TestServerStartStopRace(t *testing.T) {
|
||||
for i := 0; i < 10; i++ {
|
||||
var err error
|
||||
s := &Server{}
|
||||
s, _, _, err = RunLocalUDPServerWithFinChan(":0")
|
||||
if err != nil {
|
||||
t.Fatalf("Could not start server: %s", err)
|
||||
}
|
||||
go func() {
|
||||
if err := s.Shutdown(); err != nil {
|
||||
t.Fatalf("Could not stop server: %s", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -600,7 +680,7 @@ func ExampleDecorateWriter() {
|
||||
})
|
||||
|
||||
// simple UDP server
|
||||
pc, err := net.ListenPacket("udp", "127.0.0.1:0")
|
||||
pc, err := net.ListenPacket("udp", ":0")
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
@@ -687,43 +767,3 @@ zDCJkckCgYEAndqM5KXGk5xYo+MAA1paZcbTUXwaWwjLU+XSRSSoyBEi5xMtfvUb
|
||||
kFsxKCqxAnBVGEWAvVZAiiTOxleQFjz5RnL0BQp9Lg2cQe+dvuUmIAA=
|
||||
-----END RSA PRIVATE KEY-----`)
|
||||
)
|
||||
|
||||
func testShutdownBindPort(t *testing.T, protocol string, port string) {
|
||||
handler := NewServeMux()
|
||||
handler.HandleFunc(".", func(w ResponseWriter, r *Msg) {})
|
||||
startedCh := make(chan struct{})
|
||||
s := &Server{
|
||||
Addr: net.JoinHostPort("127.0.0.1", port),
|
||||
Net: protocol,
|
||||
Handler: handler,
|
||||
NotifyStartedFunc: func() {
|
||||
startedCh <- struct{}{}
|
||||
},
|
||||
}
|
||||
go func() {
|
||||
if err := s.ListenAndServe(); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}()
|
||||
<-startedCh
|
||||
t.Logf("DNS server is started on: %s", s.Addr)
|
||||
if err := s.Shutdown(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
go func() {
|
||||
if err := s.ListenAndServe(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}()
|
||||
<-startedCh
|
||||
t.Logf("DNS server is started on: %s", s.Addr)
|
||||
}
|
||||
|
||||
func TestShutdownBindPortUDP(t *testing.T) {
|
||||
testShutdownBindPort(t, "udp", "1153")
|
||||
}
|
||||
|
||||
func TestShutdownBindPortTCP(t *testing.T) {
|
||||
testShutdownBindPort(t, "tcp", "1154")
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user