From e2071ecd08f8cb157e61f557a16502a907c21a02 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 25 Nov 2015 16:15:45 -0500 Subject: [PATCH] testing: document that T and B are safe for concurrent calls Fixes #13108. Change-Id: I474cc2a3b7ced1c9eb978fc815f9c6bae9fb3ecc Reviewed-on: https://go-review.googlesource.com/17235 Reviewed-by: Ian Lance Taylor --- src/testing/benchmark.go | 11 +++++++++++ src/testing/testing.go | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/src/testing/benchmark.go b/src/testing/benchmark.go index 62e696d221..85178c2f86 100644 --- a/src/testing/benchmark.go +++ b/src/testing/benchmark.go @@ -33,6 +33,17 @@ type InternalBenchmark struct { // B is a type passed to Benchmark functions to manage benchmark // timing and to specify the number of iterations to run. +// +// A benchmark ends when its Benchmark function returns or calls any of the methods +// FailNow, Fatal, Fatalf, SkipNow, Skip, or Skipf. Those methods must be called +// only from the goroutine running the Benchmark function. +// The other reporting methods, such as the variations of Log and Error, +// may be called simultaneously from multiple goroutines. +// +// Like in tests, benchmark logs are accumulated during execution +// and dumped to standard error when done. Unlike in tests, benchmark logs +// are always printed, so as not to hide output whose existence may be +// affecting benchmark results. type B struct { common N int diff --git a/src/testing/testing.go b/src/testing/testing.go index c478adea9f..99d7798431 100644 --- a/src/testing/testing.go +++ b/src/testing/testing.go @@ -282,6 +282,14 @@ var _ TB = (*B)(nil) // T is a type passed to Test functions to manage test state and support formatted test logs. // Logs are accumulated during execution and dumped to standard error when done. +// +// A test ends when its Test function returns or calls any of the methods +// FailNow, Fatal, Fatalf, SkipNow, Skip, or Skipf. Those methods, as well as +// the Parallel method, must be called only from the goroutine running the +// Test function. +// +// The other reporting methods, such as the variations of Log and Error, +// may be called simultaneously from multiple goroutines. type T struct { common name string // Name of test. -- 2.48.1