clientv3/concurrency: Expose examples close to the source-code.
This commit is contained in:
@ -15,30 +15,28 @@
|
||||
package concurrency_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"go.etcd.io/etcd/tests/v3/integration"
|
||||
"go.etcd.io/etcd/v3/pkg/testutil"
|
||||
)
|
||||
|
||||
var endpoints []string
|
||||
var lazyCluster = integration.NewLazyCluster()
|
||||
|
||||
// TestMain sets up an etcd cluster for running the examples.
|
||||
func exampleEndpoints() []string { return lazyCluster.EndpointsV3() }
|
||||
|
||||
func forUnitTestsRunInMockedContext(mocking func(), example func()) {
|
||||
// For integration tests runs in the provided environment
|
||||
example()
|
||||
}
|
||||
|
||||
// TestMain sets up an etcd cluster if running the examples.
|
||||
func TestMain(m *testing.M) {
|
||||
cfg := integration.ClusterConfig{Size: 1}
|
||||
clus := integration.NewClusterV3(nil, &cfg)
|
||||
endpoints = []string{clus.Client(0).Endpoints()[0]}
|
||||
v := m.Run()
|
||||
clus.Terminate(nil)
|
||||
if err := testutil.CheckAfterTest(time.Second); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if v == 0 && testutil.CheckLeakedGoroutine() {
|
||||
os.Exit(1)
|
||||
lazyCluster.Terminate()
|
||||
if v == 0 {
|
||||
testutil.MustCheckLeakedGoroutine()
|
||||
}
|
||||
os.Exit(v)
|
||||
}
|
||||
|
Reference in New Issue
Block a user