Skip to content

Commit

Permalink
chore(refactor): simplify API of TCPEchoResponds and tlsEchoResponds (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
programmer04 authored Oct 17, 2023
1 parent a460cd9 commit 5a52b84
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 131 deletions.
5 changes: 2 additions & 3 deletions test/e2e/helpers_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,11 @@ func verifyTCPRoute(ctx context.Context, t *testing.T, env environments.Environm

t.Logf("waiting for route from TCPRoute to be operational at %s:%d", proxyIP, tcpListenerPort)
require.Eventually(t, func() bool {
ok, err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyIP, tcpListenerPort), "tcpecho-tcproute")
if err != nil {
if err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyIP, tcpListenerPort), "tcpecho-tcproute"); err != nil {
t.Logf("failed to connect to %s:%d, error %v", proxyIP, tcpListenerPort, err)
return false
}
return ok
return true
}, ingressWait, 5*time.Second,
)
}
8 changes: 3 additions & 5 deletions test/integration/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ func TestTCPRouteExample(t *testing.T) {

t.Log("verifying that TCPRoute becomes routable")
require.Eventually(t, func() bool {
responds, err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), "tcproute-example-manifest")
return err == nil && responds
return test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), "tcproute-example-manifest") == nil
}, ingressWait, waitTick)
}

Expand All @@ -200,9 +199,8 @@ func TestTLSRouteExample(t *testing.T) {

t.Log("verifying that TLSRoute becomes routable")
require.Eventually(t, func() bool {
responded, err := tlsEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTLSServicePort),
"tlsroute-example-manifest", "tlsroute.kong.example", "tlsroute.kong.example", true)
return err == nil && responded
return tlsEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTLSServicePort),
"tlsroute-example-manifest", "tlsroute.kong.example", "tlsroute.kong.example", true) == nil
}, ingressWait, waitTick)
}

Expand Down
76 changes: 30 additions & 46 deletions test/integration/tcproute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ func TestTCPRouteEssentials(t *testing.T) {

t.Log("verifying that the tcpecho is responding properly")
require.Eventually(t, func() bool {
responded, err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1)
return err == nil && responded == true
return test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1) == nil
}, ingressWait, waitTick)

t.Log("removing the parentrefs from the TCPRoute")
Expand All @@ -184,14 +183,14 @@ func TestTCPRouteEssentials(t *testing.T) {
t.Log("verifying that the tcpecho is no longer responding")
defer func() {
if t.Failed() {
responded, err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1)
t.Logf("no longer responding check failure state: responded=%v, eof=%v, reset=%v, err=%v", responded,
err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1)
t.Logf("no longer responding check failure state: eof=%v, reset=%v, err=%v",
errors.Is(err, io.EOF), errors.Is(err, syscall.ECONNRESET), err)
}
}()
require.Eventually(t, func() bool {
responded, err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1)
return responded == false && (errors.Is(err, io.EOF) || errors.Is(err, syscall.ECONNRESET))
err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1)
return errors.Is(err, io.EOF) || errors.Is(err, syscall.ECONNRESET)
}, ingressWait, waitTick)

t.Log("putting the parentRefs back")
Expand All @@ -209,8 +208,7 @@ func TestTCPRouteEssentials(t *testing.T) {

t.Log("verifying that putting the parentRefs back results in the routes becoming available again")
require.Eventually(t, func() bool {
responded, err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1)
return err == nil && responded == true
return test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1) == nil
}, ingressWait, waitTick)

t.Log("deleting the GatewayClass")
Expand All @@ -222,8 +220,8 @@ func TestTCPRouteEssentials(t *testing.T) {

t.Log("verifying that the data-plane configuration from the TCPRoute gets dropped with the GatewayClass now removed")
require.Eventually(t, func() bool {
responded, err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1)
return responded == false && (errors.Is(err, io.EOF) || errors.Is(err, syscall.ECONNRESET))
err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1)
return errors.Is(err, io.EOF) || errors.Is(err, syscall.ECONNRESET)
}, ingressWait, waitTick)

t.Log("putting the GatewayClass back")
Expand All @@ -236,8 +234,7 @@ func TestTCPRouteEssentials(t *testing.T) {

t.Log("verifying that creating the GatewayClass again triggers reconciliation of TCPRoutes and the route becomes available again")
require.Eventually(t, func() bool {
responded, err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1)
return err == nil && responded == true
return test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1) == nil
}, ingressWait, waitTick)

t.Log("deleting the Gateway")
Expand All @@ -249,8 +246,8 @@ func TestTCPRouteEssentials(t *testing.T) {

t.Log("verifying that the data-plane configuration from the TCPRoute gets dropped with the Gateway now removed")
require.Eventually(t, func() bool {
responded, err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1)
return responded == false && (errors.Is(err, io.EOF) || errors.Is(err, syscall.ECONNRESET))
err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1)
return errors.Is(err, io.EOF) || errors.Is(err, syscall.ECONNRESET)
}, ingressWait, waitTick)

t.Log("putting the Gateway back")
Expand All @@ -270,8 +267,7 @@ func TestTCPRouteEssentials(t *testing.T) {

t.Log("verifying that creating the Gateway again triggers reconciliation of TCPRoutes and the route becomes available again")
require.Eventually(t, func() bool {
responded, err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1)
return err == nil && responded == true
return test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1) == nil
}, ingressWait, waitTick)

t.Log("deleting both GatewayClass and Gateway rapidly")
Expand All @@ -284,8 +280,8 @@ func TestTCPRouteEssentials(t *testing.T) {

t.Log("verifying that the data-plane configuration from the TCPRoute does not get orphaned with the GatewayClass and Gateway gone")
require.Eventually(t, func() bool {
responded, err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1)
return responded == false && (errors.Is(err, io.EOF) || errors.Is(err, syscall.ECONNRESET))
err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1)
return errors.Is(err, io.EOF) || errors.Is(err, syscall.ECONNRESET)
}, ingressWait, waitTick)

t.Log("putting the GatewayClass back")
Expand All @@ -309,8 +305,7 @@ func TestTCPRouteEssentials(t *testing.T) {

t.Log("verifying that creating the Gateway again triggers reconciliation of TCPRoutes and the route becomes available again")
require.Eventually(t, func() bool {
responded, err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1)
return err == nil && responded == true
return test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1) == nil
}, ingressWait, waitTick)

t.Log("adding an additional backendRef to the TCPRoute")
Expand Down Expand Up @@ -339,20 +334,16 @@ func TestTCPRouteEssentials(t *testing.T) {

t.Log("verifying that the TCPRoute is now load-balanced between two services")
require.Eventually(t, func() bool {
responded, err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1)
return err == nil && responded == true
return test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1) == nil
}, ingressWait, waitTick)
require.Eventually(t, func() bool {
responded, err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID2)
return err == nil && responded == true
return test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID2) == nil
}, ingressWait, waitTick)
require.Eventually(t, func() bool {
responded, err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1)
return err == nil && responded == true
return test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1) == nil
}, ingressWait, waitTick)
require.Eventually(t, func() bool {
responded, err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID2)
return err == nil && responded == true
return test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID2) == nil
}, ingressWait, waitTick)

t.Log("deleting both GatewayClass and Gateway rapidly")
Expand All @@ -365,8 +356,8 @@ func TestTCPRouteEssentials(t *testing.T) {

t.Log("verifying that the data-plane configuration from the TCPRoute does not get orphaned with the GatewayClass and Gateway gone")
require.Eventually(t, func() bool {
responded, err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1)
return responded == false && (errors.Is(err, io.EOF) || errors.Is(err, syscall.ECONNRESET))
err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1)
return errors.Is(err, io.EOF) || errors.Is(err, syscall.ECONNRESET)
}, ingressWait, waitTick)

t.Log("testing port matching")
Expand All @@ -386,8 +377,7 @@ func TestTCPRouteEssentials(t *testing.T) {

t.Log("verifying that the TCPRoute responds before specifying a port not existent in Gateway")
require.Eventually(t, func() bool {
responded, err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1)
return err == nil && responded == true
return test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1) == nil
}, ingressWait, waitTick)

t.Log("setting the port in ParentRef which does not have a matching listener in Gateway")
Expand All @@ -404,8 +394,8 @@ func TestTCPRouteEssentials(t *testing.T) {

t.Log("verifying that the TCPRoute does not respond after specifying a port not existent in Gateway")
require.Eventually(t, func() bool {
responded, err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1)
return responded == false && (errors.Is(err, io.EOF) || errors.Is(err, syscall.ECONNRESET))
err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1)
return errors.Is(err, io.EOF) || errors.Is(err, syscall.ECONNRESET)
}, ingressWait, waitTick)
}

Expand Down Expand Up @@ -543,12 +533,10 @@ func TestTCPRouteReferenceGrant(t *testing.T) {

t.Log("verifying that only the local tcpecho is responding without a ReferenceGrant")
require.Eventually(t, func() bool {
responded, err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1)
return err == nil && responded == true
return test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1) == nil
}, ingressWait*2, waitTick)
require.Never(t, func() bool {
responded, err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID2)
return err == nil && responded == true
return test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID2) == nil
}, time.Second*10, time.Second)

t.Logf("creating a ReferenceGrant that permits tcproute access from %s to services in %s", ns.Name, otherNs.Name)
Expand Down Expand Up @@ -589,12 +577,10 @@ func TestTCPRouteReferenceGrant(t *testing.T) {

t.Log("verifying that requests reach both the local and remote namespace echo instances")
require.Eventually(t, func() bool {
responded, err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1)
return err == nil && responded == true
return test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID1) == nil
}, ingressWait, waitTick)
require.Eventually(t, func() bool {
responded, err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID2)
return err == nil && responded == true
return test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID2) == nil
}, ingressWait, waitTick)

t.Logf("testing specific name references")
Expand All @@ -609,8 +595,7 @@ func TestTCPRouteReferenceGrant(t *testing.T) {
require.NoError(t, err)

require.Eventually(t, func() bool {
responded, err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID2)
return err == nil && responded == true
return test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID2) == nil
}, ingressWait*2, waitTick)

t.Logf("testing incorrect name does not match")
Expand All @@ -620,7 +605,6 @@ func TestTCPRouteReferenceGrant(t *testing.T) {
require.NoError(t, err)

require.Eventually(t, func() bool {
responded, err := test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID2)
return err != nil && responded == false
return test.TCPEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), testUUID2) != nil
}, ingressWait, waitTick)
}
Loading

0 comments on commit 5a52b84

Please sign in to comment.