From 8cd8a1ea10abf73c2bc5462a0c3b5c254028b551 Mon Sep 17 00:00:00 2001 From: Piotr Tabor Date: Sat, 2 Apr 2022 16:16:25 +0200 Subject: [PATCH] Flakes in integration/clientv3/examples/... The tests sometimes flaked due to already existing socket-files. Now each execution works in a tempoarary directory. --- tests/integration/clientv3/examples/main_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/integration/clientv3/examples/main_test.go b/tests/integration/clientv3/examples/main_test.go index d347fa730..223ec2cdb 100644 --- a/tests/integration/clientv3/examples/main_test.go +++ b/tests/integration/clientv3/examples/main_test.go @@ -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()