From 1f7308f3f326896c507aa8c6a2701d7c28636922 Mon Sep 17 00:00:00 2001 From: AtomicFS Date: Sat, 14 Dec 2024 12:25:05 +0100 Subject: [PATCH] test(action): add timeout to SSH server start Signed-off-by: AtomicFS --- action/container/ssh_test.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/action/container/ssh_test.go b/action/container/ssh_test.go index c09ffdc3..6512faa0 100644 --- a/action/container/ssh_test.go +++ b/action/container/ssh_test.go @@ -9,6 +9,7 @@ import ( "fmt" "os" "testing" + "time" "dagger.io/dagger" "github.com/stretchr/testify/assert" @@ -101,6 +102,13 @@ func TestOpenSSH(t *testing.T) { myContainer, err := Setup(ctx, client, &tc.opts, "") assert.NoError(t, err) + // Set timeout for opening the SSH server + timeout := make(chan bool, 5) + go func() { + time.Sleep(1 * time.Second) + timeout <- true + }() + // Open the SSH go func() { err := OpenSSH(ctx, client, myContainer, tc.opts.WorkdirContainer, tc.optsSSH) @@ -110,7 +118,13 @@ func TestOpenSSH(t *testing.T) { assert.NoError(t, err) }() // Wait until SSH server is ready - <-tc.optsSSH.TunnelReady + select { + case <-tc.optsSSH.TunnelReady: + // the SSH tunnel is ready + case <-timeout: + // the SSH tunnel is not ready yet, and has timed out + t.Fatal("Opening SSH server has taken too long") + } // Connect with client config := &ssh.ClientConfig{