Flakes in integration/clientv3/examples/...

The tests sometimes flaked due to already existing socket-files.
Now each execution works in a tempoarary directory.
This commit is contained in:
Piotr Tabor 2022-04-02 16:16:25 +02:00
parent 3b589fb3b2
commit 8cd8a1ea10

View File

@ -15,6 +15,7 @@
package clientv3_test
import (
"log"
"os"
"testing"
"time"
@ -44,6 +45,16 @@ func forUnitTestsRunInMockedContext(mocking func(), example func()) {
// TestMain sets up an etcd cluster if running the examples.
func TestMain(m *testing.M) {
testutil.ExitInShortMode("Skipping: the tests require real cluster")
tempDir := os.TempDir()
defer os.RemoveAll(tempDir)
err := os.Chdir(tempDir)
if err != nil {
log.Printf("Failed to change working dir to: %s: %v", tempDir, err)
os.Exit(1)
}
v := m.Run()
lazyCluster.Terminate()