Skip to content

Commit eb0aa5a

Browse files
committed
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 366b614 commit eb0aa5a

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
@@ -4790,7 +4790,7 @@ func testX11Forwarding(t *testing.T, suite *integrationTestSuite) {
47904790

47914791
// Reading the display may fail if the session is not fully initialized
47924792
// and the write to stdin is swallowed.
4793-
var display string
4793+
display := make(chan string, 1)
47944794
require.EventuallyWithT(t, func(t *assert.CollectT) {
47954795
// enter 'printenv DISPLAY > /path/to/tmp/file' into the session (dumping the value of DISPLAY into the temp file)
47964796
_, err = keyboard.Write([]byte(fmt.Sprintf("printenv %v > %s\n\r", x11.DisplayEnv, tmpFile.Name())))
@@ -4799,15 +4799,15 @@ func testX11Forwarding(t *testing.T, suite *integrationTestSuite) {
47994799
assert.Eventually(t, func() bool {
48004800
output, err := os.ReadFile(tmpFile.Name())
48014801
if err == nil && len(output) != 0 {
4802-
display = strings.TrimSpace(string(output))
4802+
display <- strings.TrimSpace(string(output))
48034803
return true
48044804
}
48054805
return false
48064806
}, time.Second, 100*time.Millisecond, "failed to read display")
48074807
}, 10*time.Second, time.Second)
48084808

48094809
// Make a new connection to the XServer proxy to confirm that forwarding is working.
4810-
serverDisplay, err := x11.ParseDisplay(display)
4810+
serverDisplay, err := x11.ParseDisplay(<-display)
48114811
require.NoError(t, err)
48124812

48134813
conn, err := serverDisplay.Dial()

0 commit comments

Comments
 (0)