open-consul/agent/checks
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
..
alias.go checks: wait for goroutine to complete 2020-07-20 18:55:39 -04:00
alias_test.go Enable gofmt simplify 2020-06-16 13:21:11 -04:00
check.go testutil: NewLogBuffer - buffer logs until a test fails 2020-07-21 12:50:40 -04:00
check_test.go feat: support sending body in HTTP checks (#6602) 2020-02-10 09:27:12 -07:00
docker.go Sets tty in docker client back to true, as a potential fix for docker exec weirdness 2017-11-05 09:44:55 -06:00
docker_unix.go Decouple the code that executes checks from the agent 2017-10-25 11:18:07 +02:00
docker_windows.go Decouple the code that executes checks from the agent 2017-10-25 11:18:07 +02:00
grpc.go grpc: use default resolver scheme for grpc dialing (#7617) 2020-05-20 22:26:26 +02:00
grpc_test.go Allow users to configure either unstructured or JSON logging (#7130) 2020-01-28 17:50:41 -06:00