sourcegraph/lib/output
Jean-Hadrien Chabran 2dfeb486d5
fix(local): fix race in sg_start_test.go (#63642)
Fixes DINF-82; This was very much a rabbithole. A few things: 

- The race that @bobheadxi mentioned here
https://github.com/sourcegraph/sourcegraph/pull/63405#discussion_r1648180713
wasn't from `*output.Output` being unsafe, but `outputtest.Buffer` as it
happened again (see
[DINF-82](https://linear.app/sourcegraph/issue/DINF-82/devsgsg-test-failed-with-a-detected-race-condition))
- There something messed up with `cmds.start()`, which sometimes ends up
printing the command output _after_ the exit message instead of before.
- The crude `sort.Strings(want|have)` that was there already fixes that.
- And without the sleep, it's possible to read the output from the
`outputtest.Buffer` before the command outputs get written to it.
- The `time.Sleep(300 * time.Milliseconds)` _mitigates/hides_ that
problem.

At least, this shouldn't blow up in CI and buys us time to fix the whole
thing. We're tracking this in DINF-104. And out of 200 runs, I also
stumbled on a race in `progress_tty`, tracked in DINF-105 (that packages
is originally meant to be used by `src-cli` and was re-used for `sg` 3
years ago).

I'm pretty unhappy about the solution, but a bandage is better than
nothing. While ideally, we should really reconsider dropping
`std.Output` entirely in `sg` and use the good stuff from
github.com/charmbracelet instead because we don't want to spend too much
time on arcane terminal things ourselves, I'm much more about concerned
the concurrency issues mentioned above.

## Test plan

CI + `sg bazel test //dev/sg:sg_test --runs_per_test=100`
2024-07-04 19:11:10 +02:00
..
_examples bazel: introduce build files for Go (#46770) 2023-01-23 14:00:01 +01:00
outputtest fix(local): fix race in sg_start_test.go (#63642) 2024-07-04 19:11:10 +02:00
block.go dev/sg: fix diff output in Buildkite without using Buildkite condition (#36193) 2022-05-30 11:48:15 -07:00
BUILD.bazel migrator: extract non-cli specifics from cli package (#53247) 2023-06-09 18:51:56 +01:00
capabilities.go lib/output: ForceTTY can be used to disable Isatty (#60640) 2024-02-21 09:18:06 +02:00
emoji.go migrator: extract non-cli specifics from cli package (#53247) 2023-06-09 18:51:56 +01:00
line.go sg/msp: filter generated environments by category (#62131) 2024-04-24 09:44:16 -07:00
logger.go migrator: extract non-cli specifics from cli package (#53247) 2023-06-09 18:51:56 +01:00
noop_writer.go lib: use any instead of interface{} (#35121) 2022-05-09 14:55:38 +00:00
output_unix_test.go dev/sg: fix diff output in Buildkite without using Buildkite condition (#36193) 2022-05-30 11:48:15 -07:00
output_unix.go Simplify goroutine params (#61009) 2024-03-12 09:05:55 -07:00
output_windows.go dev/sg: fix diff output in Buildkite without using Buildkite condition (#36193) 2022-05-30 11:48:15 -07:00
output.go sg: print teammate details to terminal (#62031) 2024-04-19 12:59:36 +02:00
pending_simple.go lib: use any instead of interface{} (#35121) 2022-05-09 14:55:38 +00:00
pending_tty.go dev/sg: fix diff output in Buildkite without using Buildkite condition (#36193) 2022-05-30 11:48:15 -07:00
pending.go lib: use any instead of interface{} (#35121) 2022-05-09 14:55:38 +00:00
progress_simple.go dev/sg: fix diff output in Buildkite without using Buildkite condition (#36193) 2022-05-30 11:48:15 -07:00
progress_tty.go lib/output: add a percentage summary label at the end of progress bar (#37711) 2022-06-29 18:55:17 +00:00
progress_with_status_bars_simple.go dev/sg: fix diff output in Buildkite without using Buildkite condition (#36193) 2022-05-30 11:48:15 -07:00
progress_with_status_bars_tty.go dev/sg: fix diff output in Buildkite without using Buildkite condition (#36193) 2022-05-30 11:48:15 -07:00
progress_with_status_bars.go lib: use any instead of interface{} (#35121) 2022-05-09 14:55:38 +00:00
progress.go
spinner.go
status_bar.go lib: use any instead of interface{} (#35121) 2022-05-09 14:55:38 +00:00
style.go sg/msp: filter generated environments by category (#62131) 2024-04-24 09:44:16 -07:00
visible_string_width.go all: run gofmt -s -w from 1.19 (#41629) 2022-09-13 07:44:06 +00:00