From ebe01a5aef6e9f5aa9e35e0c843bb4de5d107cdc Mon Sep 17 00:00:00 2001 From: Andrew Keesler Date: Fri, 19 Mar 2021 09:59:24 -0400 Subject: [PATCH] test/integration: catch early 'kubectl attach' return Signed-off-by: Andrew Keesler --- .../concierge_impersonation_proxy_test.go | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/test/integration/concierge_impersonation_proxy_test.go b/test/integration/concierge_impersonation_proxy_test.go index f2b6bb12..adda98f0 100644 --- a/test/integration/concierge_impersonation_proxy_test.go +++ b/test/integration/concierge_impersonation_proxy_test.go @@ -599,6 +599,11 @@ func TestImpersonationProxy(t *testing.T) { //nolint:gocyclo // yeah, it's compl // start but don't wait for the attach command err = attachCmd.Start() require.NoError(t, err) + attachExitCh := make(chan struct{}) + go func() { + assert.NoError(t, attachCmd.Wait()) + close(attachExitCh) + }() // write to stdin on the attach process _, err = attachStdin.Write([]byte(echoString + "\n")) @@ -611,8 +616,7 @@ func TestImpersonationProxy(t *testing.T) { //nolint:gocyclo // yeah, it's compl // close stdin and attach process should exit err = attachStdin.Close() require.NoError(t, err) - err = attachCmd.Wait() - require.NoError(t, err) + requireClose(t, attachExitCh, time.Second*20) }) t.Run("websocket client", func(t *testing.T) { @@ -1183,3 +1187,16 @@ func isServiceUnavailableViaSquidError(err error, proxyServiceEndpoint string) ( return true, "" } + +func requireClose(t *testing.T, c chan struct{}, timeout time.Duration) { + t.Helper() + timer := time.NewTimer(timeout) + select { + case <-c: + if !timer.Stop() { + <-timer.C + } + case <-timer.C: + require.FailNow(t, "failed to receive from channel within "+timeout.String()) + } +}