databricks-cli/libs/process
Pieter Noordhuis eddaddaf8b
Attempt to reduce test flakiness on Windows (#1845)
## Changes

Test failures indicate that both stdout and stderr are consumed, yet the
content of stdout doesn't end up in the intended output. This can happen
if the goroutines responsible for writing to the combined output buffer
attempt to write to the same underlying buffer concurrently.

Example failure:
```
=== RUN   TestBackgroundCombinedOutput
    background_test.go:65: 
        	Error Trace:	D:/a/cli/cli/libs/process/background_test.go:65
        	Error:      	elements differ
        	            	
        	            	extra elements in list A:
        	            	([]interface {}) (len=1) {
        	            	 (string) (len=1) "2"
        	            	}
        	            	
        	            	
        	            	listA:
        	            	([]string) (len=2) {
        	            	 (string) (len=1) "1",
        	            	 (string) (len=1) "2"
        	            	}
        	            	
        	            	
        	            	listB:
        	            	([]string) (len=1) {
        	            	 (string) (len=1) "1"
        	            	}
        	Test:       	TestBackgroundCombinedOutput
```

With the test body:

ca45e53f42/libs/process/background_test.go (L48-L66)

With the implementation of `WithCombinedOutput`:

ca45e53f42/libs/process/opts.go (L72-L78)

Notice that `c.Stdout` does get the "2", or the test failure would have
included the relevant assertion error. This leads me to believe that
there is a race on writing to `buf` from the two goroutines writing to
`c.Stdout` and `c.Stderr`.

## Tests

The test passes. If this PR has the intended effect remains to be
seen...
2024-10-24 12:03:12 +00:00
..
background.go Added process stubbing for easier testing of launched subprocesses (#963) 2023-11-09 14:24:05 +00:00
background_test.go Use Go 1.22 to build and test (#1562) 2024-07-04 06:54:41 +00:00
forwarded.go Added process stubbing for easier testing of launched subprocesses (#963) 2023-11-09 14:24:05 +00:00
forwarded_test.go Added `process.Background()` and `process.Forwarded()` (#804) 2023-09-27 09:04:44 +00:00
opts.go Attempt to reduce test flakiness on Windows (#1845) 2024-10-24 12:03:12 +00:00
opts_test.go Added `process.Background()` and `process.Forwarded()` (#804) 2023-09-27 09:04:44 +00:00
stub.go Stub out Python virtual environment installation for `labs` commands (#1057) 2023-12-11 16:30:19 +00:00
stub_test.go Added process stubbing for easier testing of launched subprocesses (#963) 2023-11-09 14:24:05 +00:00