open-consul/sdk
Daniel Nephin 80ff174880 testutil: NewLogBuffer - buffer logs until a test fails
Replaces #7559

Running tests in parallel, with background goroutines, results in test output not being associated with the correct test. `go test` does not make any guarantees about output from goroutines being attributed to the correct test case.

Attaching log output from background goroutines also cause data races.  If the goroutine outlives the test, it will race with the test being marked done. Previously this was noticed as a panic when logging, but with the race detector enabled it is shown as a data race.

The previous solution did not address the problem of correct test attribution because test output could still be hidden when it was associated with a test that did not fail. You would have to look at all of the log output to find the relevant lines. It also made debugging test failures more difficult because each log line was very long.

This commit attempts a new approach. Instead of printing all the logs, only print when a test fails. This should work well when there are a small number of failures, but may not work well when there are many test failures at the same time. In those cases the failures are unlikely a result of a specific test, and the log output is likely less useful.

All of the logs are printed from the test goroutine, so they should be associated with the correct test.

Also removes some test helpers that were not used, or only had a single caller. Packages which expose many functions with similar names can be difficult to use correctly.

Related:
https://github.com/golang/go/issues/38458 (may be fixed in go1.15)
https://github.com/golang/go/issues/38382#issuecomment-612940030
2020-07-21 12:50:40 -04:00
..
freeport [BUGFIX] Fix race condition in freeport (#7567) 2020-04-01 13:14:33 -05:00
testutil testutil: NewLogBuffer - buffer logs until a test fails 2020-07-21 12:50:40 -04:00
.golangci.yml ci: Use golangci-lint for linting 2020-03-17 13:43:40 -04:00
README.md Move internal/ to sdk/ (#5568) 2019-03-27 08:54:56 -04:00
go.mod Allow users to configure either unstructured or JSON logging (#7130) 2020-01-28 17:50:41 -06:00
go.sum Allow users to configure either unstructured or JSON logging (#7130) 2020-01-28 17:50:41 -06:00

README.md

Internal SDK

Please note that this folder, while public, is not meant for new consumers of these libraries; this should currently be considered an internal, not external, SDK. It is public due to existing needs from other HashiCorp software. The tags in this folder will stay at the 0.x.y level; accordingly users should expect that things can move around, disappear, or change API at any time.