clientv3/concurrency: Expose examples close to the source-code.

This commit is contained in:
Piotr Tabor
2020-10-06 14:19:02 +02:00
parent c5ccebf792
commit dd45d04b2d
10 changed files with 281 additions and 207 deletions

View File

@ -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)
}