E2E Tests: Use inspect instead of actual data to avoid UDP flake
Do not test using an unreliable UDP connection Signed-off-by: Ygal Blum <ygal.blum@gmail.com>
This commit is contained in:
		
							parent
							
								
									67305cec97
								
							
						
					
					
						commit
						a02a10f3f3
					
				|  | @ -1,7 +1,6 @@ | ||||||
| package integration | package integration | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"bufio" |  | ||||||
| 	"bytes" | 	"bytes" | ||||||
| 	"context" | 	"context" | ||||||
| 	"encoding/base64" | 	"encoding/base64" | ||||||
|  | @ -1689,82 +1688,19 @@ func testHTTPServer(port string, shouldErr bool, expectedResponse string) { | ||||||
| 	Expect(string(body)).Should(Equal(expectedResponse)) | 	Expect(string(body)).Should(Equal(expectedResponse)) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func testEchoServer(connection net.Conn) { | func verifyPodPorts(podmanTest *PodmanTestIntegration, podName string, ports ...string) { | ||||||
| 	stringToSend := "hello world" | 	podInspect := podmanTest.Podman([]string{"pod", "inspect", podName, "--format", "{{.InfraContainerID}}"}) | ||||||
| 	var err error | 	podInspect.WaitWithDefaultTimeout() | ||||||
| 	var bytesSent int | 	Expect(podInspect).To(Exit(0)) | ||||||
|  | 	infraID := podInspect.OutputToString() | ||||||
| 
 | 
 | ||||||
| 	interval := 250 * time.Millisecond | 	inspect := podmanTest.Podman([]string{"inspect", "--format", "{{.NetworkSettings.Ports}}", infraID}) | ||||||
| 	for i := 0; i < 5; i++ { | 	inspect.WaitWithDefaultTimeout() | ||||||
| 		err = connection.SetDeadline(time.Now().Add(time.Second)) | 	Expect(inspect).To(Exit(0)) | ||||||
| 		Expect(err).To(BeNil()) | 
 | ||||||
| 		bytesSent, err = fmt.Fprint(connection, stringToSend) | 	for _, port := range ports { | ||||||
| 		if err == nil { | 		Expect(inspect.OutputToString()).Should(ContainSubstring(port)) | ||||||
| 			break |  | ||||||
| 	} | 	} | ||||||
| 		time.Sleep(interval) |  | ||||||
| 		interval *= 2 |  | ||||||
| 	} |  | ||||||
| 	Expect(err).To(BeNil()) |  | ||||||
| 	Expect(bytesSent).To(Equal(len(stringToSend))) |  | ||||||
| 
 |  | ||||||
| 	stringReceived := make([]byte, bytesSent) |  | ||||||
| 	var bytesRead int |  | ||||||
| 	interval = 250 * time.Millisecond |  | ||||||
| 	for i := 0; i < 5; i++ { |  | ||||||
| 		err = connection.SetDeadline(time.Now().Add(time.Second)) |  | ||||||
| 		Expect(err).To(BeNil()) |  | ||||||
| 		bytesRead, err = bufio.NewReader(connection).Read(stringReceived) |  | ||||||
| 		if err == nil { |  | ||||||
| 			break |  | ||||||
| 		} |  | ||||||
| 		time.Sleep(interval) |  | ||||||
| 		interval *= 2 |  | ||||||
| 	} |  | ||||||
| 	Expect(err).To(BeNil()) |  | ||||||
| 	Expect(bytesRead).To(Equal(bytesSent)) |  | ||||||
| 
 |  | ||||||
| 	Expect(stringToSend).To(Equal(string(stringReceived))) |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func testEchoServerUDP(address string) { |  | ||||||
| 	udpServer, err := net.ResolveUDPAddr("udp", address) |  | ||||||
| 	Expect(err).To(BeNil()) |  | ||||||
| 
 |  | ||||||
| 	interval := 250 * time.Millisecond |  | ||||||
| 	var conn *net.UDPConn |  | ||||||
| 	for i := 0; i < 6; i++ { |  | ||||||
| 		conn, err = net.DialUDP("udp", nil, udpServer) |  | ||||||
| 		if err == nil { |  | ||||||
| 			break |  | ||||||
| 		} |  | ||||||
| 		time.Sleep(interval) |  | ||||||
| 		interval *= 2 |  | ||||||
| 	} |  | ||||||
| 	Expect(err).To(BeNil()) |  | ||||||
| 	defer conn.Close() |  | ||||||
| 
 |  | ||||||
| 	testEchoServer(conn) |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func testEchoServerTCP(address string) { |  | ||||||
| 	tcpServer, err := net.ResolveTCPAddr("tcp", address) |  | ||||||
| 	Expect(err).To(BeNil()) |  | ||||||
| 
 |  | ||||||
| 	interval := 250 * time.Millisecond |  | ||||||
| 	var conn *net.TCPConn |  | ||||||
| 	for i := 0; i < 6; i++ { |  | ||||||
| 		conn, err = net.DialTCP("tcp", nil, tcpServer) |  | ||||||
| 		if err == nil { |  | ||||||
| 			break |  | ||||||
| 		} |  | ||||||
| 		time.Sleep(interval) |  | ||||||
| 		interval *= 2 |  | ||||||
| 	} |  | ||||||
| 	Expect(err).To(BeNil()) |  | ||||||
| 	defer conn.Close() |  | ||||||
| 
 |  | ||||||
| 	testEchoServer(conn) |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| var _ = Describe("Podman play kube", func() { | var _ = Describe("Podman play kube", func() { | ||||||
|  | @ -4974,8 +4910,7 @@ spec: | ||||||
| 		kube.WaitWithDefaultTimeout() | 		kube.WaitWithDefaultTimeout() | ||||||
| 		Expect(kube).Should(Exit(0)) | 		Expect(kube).Should(Exit(0)) | ||||||
| 
 | 
 | ||||||
| 		testEchoServerUDP(":19009") | 		verifyPodPorts(podmanTest, "network-echo", "19008/tcp:[{ 19010}]", "19008/udp:[{ 19009}]") | ||||||
| 		testEchoServerTCP(":19010") |  | ||||||
| 	}) | 	}) | ||||||
| 
 | 
 | ||||||
| 	It("podman play kube override with udp should keep tcp from YAML file", func() { | 	It("podman play kube override with udp should keep tcp from YAML file", func() { | ||||||
|  | @ -4986,7 +4921,6 @@ spec: | ||||||
| 		kube.WaitWithDefaultTimeout() | 		kube.WaitWithDefaultTimeout() | ||||||
| 		Expect(kube).Should(Exit(0)) | 		Expect(kube).Should(Exit(0)) | ||||||
| 
 | 
 | ||||||
| 		testEchoServerUDP(":19012") | 		verifyPodPorts(podmanTest, "network-echo", "19008/tcp:[{ 19011}]", "19008/udp:[{ 19012}]") | ||||||
| 		testEchoServerTCP(":19011") |  | ||||||
| 	}) | 	}) | ||||||
| }) | }) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue