Skip to content

Commit

Permalink
tests: rework the e2e test for compatibility with 800
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Di Maio <[email protected]>
  • Loading branch information
89luca89 committed Nov 16, 2023
1 parent d6f1636 commit dd7380b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 11 deletions.
4 changes: 1 addition & 3 deletions e2e/framework/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,7 @@ func (f *Framework) DevpodPortTest(ctx context.Context, port string, workspace s
// First run to trigger the first forwarding
_, _, err := f.ExecCommandCapture(ctx, []string{
"ssh",
"--forward-ports", port,
"--command",
"nc -nlp " + port, workspace,
"--forward-ports", port, workspace,
})
return err
}
68 changes: 60 additions & 8 deletions e2e/tests/ssh/ssh.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package ssh

import (
"bufio"
"context"
"fmt"
"math/rand"
"net"
"os"
"os/exec"
"strconv"
Expand Down Expand Up @@ -109,18 +111,68 @@ var _ = DevPodDescribe("devpod ssh test suite", func() {
devpodSSHDeadline := time.Now().Add(20 * time.Second)
devpodSSHCtx, cancelSSH := context.WithDeadline(context.Background(), devpodSSHDeadline)
defer cancelSSH()
// start ssh with netcat server in background

fmt.Println("Starting pong service")
// start a ping/pong service on the port
cmd := exec.CommandContext(ctx, f.DevpodBinDir+"/"+f.DevpodBinName,
[]string{
"ssh", tempDir, "--command",
"sh -c \"while true; do echo PONG | nc -n -lk -p " + strconv.Itoa(port) + "; done\"",
}...,
)
err = cmd.Start()
framework.ExpectNoError(err)

fmt.Println("Forwarding port", port)
// start ssh with port forwarding in background
go func() {
_ = f.DevpodPortTest(devpodSSHCtx, strconv.Itoa(port), tempDir)
}()

// wait 5s just to be sure the netcat server has time to start
time.Sleep(time.Second * 5)

err = exec.Command("nc", "-zv", "localhost", strconv.Itoa(port)).Run()
if err == nil {
fmt.Println("forwarding successful")
fmt.Println("Waiting for port", port, "to be open")
// wait for port to be open
retries := 5
out := ""
address := net.JoinHostPort("localhost", strconv.Itoa(port))
for retries > 0 {
fmt.Println("retries left", retries)

// wait 3s between retries
time.Sleep(time.Second * 3)

conn, err := net.Dial("tcp", address)
if err != nil {
fmt.Println("port still closed")
retries = retries - 1
} else {
if conn != nil {
defer conn.Close()
fmt.Println("connecting to", port)

fmt.Println("sending PING")
_, err = conn.Write([]byte("PING"))
framework.ExpectNoError(err)

fmt.Println("waiting for response")
out, err = bufio.NewReader(conn).ReadString('\n')
if err != nil {
fmt.Println("invalid response")
retries = retries - 1
} else {
fmt.Println("received", out)

break
}
} else {
fmt.Println("invalid connection")
retries = retries - 1
}
}
}
framework.ExpectNoError(err)
framework.ExpectNotEqual(retries, 0)

fmt.Println("Verifying output match")
framework.ExpectEqual(out, "PONG\n")
fmt.Println("Success")
})
})

0 comments on commit dd7380b

Please sign in to comment.