Skip to content

Commit 690a0bd

Browse files
authored
Fix racy X11 forwarding test (#48045)
{require,assert}.Eventually run the passed in func on a new goroutine for each attempt, so it's not safe to write to a shared variable without any synchronization. Closes #47756
1 parent af55dbf commit 690a0bd

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

integration/integration_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4740,7 +4740,7 @@ func testX11Forwarding(t *testing.T, suite *integrationTestSuite) {
47404740

47414741
// Reading the display may fail if the session is not fully initialized
47424742
// and the write to stdin is swallowed.
4743-
var display string
4743+
display := make(chan string, 1)
47444744
require.EventuallyWithT(t, func(t *assert.CollectT) {
47454745
// enter 'printenv DISPLAY > /path/to/tmp/file' into the session (dumping the value of DISPLAY into the temp file)
47464746
_, err = keyboard.Write([]byte(fmt.Sprintf("printenv %v > %s\n\r", x11.DisplayEnv, tmpFile.Name())))
@@ -4749,15 +4749,15 @@ func testX11Forwarding(t *testing.T, suite *integrationTestSuite) {
47494749
assert.Eventually(t, func() bool {
47504750
output, err := os.ReadFile(tmpFile.Name())
47514751
if err == nil && len(output) != 0 {
4752-
display = strings.TrimSpace(string(output))
4752+
display <- strings.TrimSpace(string(output))
47534753
return true
47544754
}
47554755
return false
47564756
}, time.Second, 100*time.Millisecond, "failed to read display")
47574757
}, 10*time.Second, time.Second)
47584758

47594759
// Make a new connection to the XServer proxy to confirm that forwarding is working.
4760-
serverDisplay, err := x11.ParseDisplay(display)
4760+
serverDisplay, err := x11.ParseDisplay(<-display)
47614761
require.NoError(t, err)
47624762

47634763
conn, err := serverDisplay.Dial()

0 commit comments

Comments
 (0)