sourcegraph/lib
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
..
accesstoken chore: Expose ParsePersonalAccessToken publicly for src-cli (#62587) 2024-05-10 19:32:14 +08:00
api enterprise: Move last directory out (#57392) 2023-10-05 20:15:40 +00:00
background feat/cody-gateway: use Enterprise Portal for actor/productsubscriptions (#62934) 2024-06-07 11:46:01 -07:00
batches chore: Change errors.HasType to respect multi-errors (#63024) 2024-06-06 13:02:14 +00:00
cliutil sg: improve positional completions (#58569) 2023-11-27 16:30:59 -08:00
codeintel chore(codeintel): Differentiate between paths relative to upload root vs repo root (#63437) 2024-06-24 20:27:26 +08:00
enterpriseportal feat/enterpriseportal: define GetCodyGatewayUsage RPC, use uint64 for rate limits (#63531) 2024-07-02 09:25:23 -07:00
errors chore(codenav): Resolve repo and commit in common code (#63072) 2024-06-07 21:58:36 +08:00
gitservice bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
iterator ci: re-enable race detection (#52776) 2023-06-05 20:41:47 +02:00
managedservicesplatform feat/enterpriseportal: make UpdateEnterpriseSubscriptionMembership authoritative (#63502) 2024-06-27 12:52:46 -07:00
output fix(local): fix race in sg_start_test.go (#63642) 2024-07-04 19:11:10 +02:00
pointers feat/sg: add 'sg enterprise' commands for Cody Analytics (#63414) 2024-06-21 16:29:31 -07:00
process fix/sg: fix mangled log output from sg start and sg run (#63405) 2024-06-20 16:07:27 -07:00
redislock enterprise-portal: implement basic MSP IAM and RPCs (#63173) 2024-06-19 21:46:48 -04:00
servicecatalog bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
telemetrygateway internal/telemetry: make adding EventsStore middleware easier (#63216) 2024-06-13 11:55:06 +01:00
buf.yaml lib/enterpriseportal: initial service API for RFC 885 (#62263) 2024-05-15 12:58:55 -07:00
go.mod feat/enterpriseportal: validate and normalize instance domains (#63415) 2024-06-21 16:14:23 -07:00
go.sum feat/enterpriseportal: validate and normalize instance domains (#63415) 2024-06-21 16:14:23 -07:00
README.md lib: Introduce non-enterprise lib directory (#18992) 2021-03-10 19:41:33 -06:00
tools.go bump to Go 1.22.1 (#60902) 2024-03-06 17:38:43 -07:00

Sourcegraph lib module

This directory is the root of a separate go module from the primary module rooted at sourcegraph/sourcegraph. This module exists to hold code that we want to reuse outside of the sourcegraph/sourcegraph repo.

Code in this module should not import from sourcegraph/sourcegraph or from other Sourcegraph repositories to avoid complicated dependency relationships. Instead consider moving code from elsewhere into this module.