Files
gvisor-tap-vsock/test-win-sshproxy/basic_test.go
lstocchi 08769de7e0 win-sshproxy.tid created before thread id is available
this commit fixes a potential race condition that prevented the tests to succeed
when running in a github workflow.
Basically the thread id was not actually available before
writing it on the file, resulting in a thread id equals to 0 written in it.
So, when the tests were trying to retrieve the thread id to use it to send
the WM_QUIT signal, they failed.

This patch adds a check on the thread id before writing
it on the file. Now, if the thread id is 0, it keeps calling winquit to
retrieve it. If, after 10 secs, there is no success it returns an error.

Signed-off-by: lstocchi <lstocchi@redhat.com>
2024-11-29 11:18:44 +01:00

91 lines
2.3 KiB
Go

//go:build windows
// +build windows
package e2e
import (
"context"
"io"
"net"
"net/http"
"os"
"os/exec"
"strings"
"time"
winio "github.com/Microsoft/go-winio"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var timeout = 1 * time.Minute
var _ = Describe("connectivity", func() {
It("proxy exits as requested, without a kill", func() {
err := startProxy()
Expect(err).ShouldNot(HaveOccurred())
var pid, tid uint32
for i := 0; i < 20; i++ {
pid, tid, err = readTid()
if err == nil && tid != 0 {
break
}
time.Sleep(100 * time.Millisecond)
}
Expect(tid).ShouldNot(Equal(0))
Expect(err).ShouldNot(HaveOccurred())
proc, err := os.FindProcess(int(pid))
Expect(err).ShouldNot(HaveOccurred())
Expect(proc).ShouldNot(BeNil())
err = stopProxy(true)
Expect(err).ShouldNot(HaveOccurred())
})
It("proxies over a windows pipe", func() {
err := startProxy()
Expect(err).ShouldNot(HaveOccurred())
defer stopProxy(false)
httpClient := &http.Client{
Transport: &http.Transport{
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
return winio.DialPipe(`\\.\pipe\fake_docker_engine`, &timeout)
},
},
}
Eventually(func(g Gomega) {
resp, err := httpClient.Get("http://host/ping")
g.Expect(err).ShouldNot(HaveOccurred())
defer resp.Body.Close()
g.Expect(resp.StatusCode).To(Equal(http.StatusOK))
g.Expect(resp.ContentLength).To(Equal(int64(4)))
reply := make([]byte, resp.ContentLength)
_, err = io.ReadAtLeast(resp.Body, reply, len(reply))
g.Expect(err).ShouldNot(HaveOccurred())
g.Expect(string(reply)).To(Equal("pong"))
}).Should(Succeed())
err = stopProxy(true)
Expect(err).ShouldNot(HaveOccurred())
})
It("windows event logs were created", func() {
cmd := exec.Command("powershell", "-Command", "&{Get-WinEvent -ProviderName \".NET Runtime\" -MaxEvents 10 | Where-Object -Property Message -Match \"test:\"}")
reader, err := cmd.StdoutPipe()
Expect(err).ShouldNot(HaveOccurred())
cmd.Start()
output, err := io.ReadAll(reader)
Expect(err).ShouldNot(HaveOccurred())
cmd.Wait()
Expect(strings.Contains(string(output), `[info ] test: Listening on: \\.\pipe\fake_docker_engine`)).Should(BeTrue())
Expect(strings.Contains(string(output), `[debug] test: Socket forward established`)).Should(BeTrue())
})
})