MCPcopy
hub / github.com/moby/moby / TestUDPWriteError

Function TestUDPWriteError

cmd/docker-proxy/network_proxy_linux_test.go:401–442  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

399}
400
401func TestUDPWriteError(t *testing.T) {
402 frontendAddr := &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 0}
403 // Hopefully, this port will be free: */
404 backendAddr := &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: hopefullyFreePort}
405 listener, frontendAddr := udpListener(t, "udp4", frontendAddr)
406 config := ProxyConfig{
407 Proto: "udp",
408 HostIP: frontendAddr.IP,
409 HostPort: frontendAddr.Port,
410 ContainerIP: backendAddr.IP,
411 ContainerPort: backendAddr.Port,
412 ListenSock: listener,
413 }
414 proxy, err := newProxy(config)
415 if err != nil {
416 t.Fatal(err)
417 }
418 defer proxy.Close()
419 go proxy.Run()
420 client, err := net.Dial("udp", frontendAddr.String())
421 if err != nil {
422 t.Fatalf("Can't connect to the proxy: %v", err)
423 }
424 defer client.Close()
425 // Make sure the proxy doesn't stop when there is no actual backend:
426 client.Write(testBuf)
427 client.Write(testBuf)
428 backend := NewEchoServer(t, "udp", backendAddr.String(), EchoServerOptions{})
429 defer backend.Close()
430 backend.Run()
431 client.SetDeadline(time.Now().Add(10 * time.Second))
432 if _, err = client.Write(testBuf); err != nil {
433 t.Fatal(err)
434 }
435 recvBuf := make([]byte, testBufSize)
436 if _, err = client.Read(recvBuf); err != nil {
437 t.Fatal(err)
438 }
439 if !bytes.Equal(testBuf, recvBuf) {
440 t.Fatal(fmt.Errorf("Expected [%v] but got [%v]", testBuf, recvBuf))
441 }
442}
443
444func TestSCTP4ProxyNoListener(t *testing.T) {
445 backend := NewEchoServer(t, "sctp", "127.0.0.1:0", EchoServerOptions{})

Callers

nothing calls this directly

Calls 11

CloseMethod · 0.95
RunMethod · 0.95
udpListenerFunction · 0.85
newProxyFunction · 0.85
NewEchoServerFunction · 0.85
EqualMethod · 0.80
ErrorfMethod · 0.80
StringMethod · 0.65
AddMethod · 0.65
WriteMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…