Skip to content

Commit

Permalink
test(action): add timeout to SSH server start
Browse files Browse the repository at this point in the history
Signed-off-by: AtomicFS <vojtech.vesely@9elements.com>
  • Loading branch information
AtomicFS committed Dec 14, 2024
1 parent 8e739ed commit 53e36e0
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion action/container/ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"os"
"testing"
"time"

"dagger.io/dagger"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -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)
Expand All @@ -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{
Expand Down

0 comments on commit 53e36e0

Please sign in to comment.