Skip to content

Commit 130f896

Browse files
committed
[FAB-9222] Fix ledger test race condition
There seems to be contention for a base ledger directory used throughout the tests. This change adds a random directory to the paths for tests in the base package. Change-Id: I25a9f4312cf0f4b55596d69e46ab0b4b07f0912c Signed-off-by: Gari Singh <gari.r.singh@gmail.com>
1 parent 3b6a904 commit 130f896

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

core/ledger/kvledger/pkg_test.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,39 @@ limitations under the License.
1717
package kvledger
1818

1919
import (
20+
"math/rand"
2021
"os"
22+
"path/filepath"
23+
"strconv"
2124
"testing"
2225

23-
"github.com/hyperledger/fabric/core/config"
2426
"github.com/spf13/viper"
2527
)
2628

2729
type testEnv struct {
28-
t testing.TB
30+
t testing.TB
31+
path string
2932
}
3033

3134
func newTestEnv(t testing.TB) *testEnv {
32-
return createTestEnv(t, "/tmp/fabric/ledgertests/kvledger")
35+
path := filepath.Join(
36+
os.TempDir(),
37+
"fabric",
38+
"ledgertests",
39+
"kvledger",
40+
strconv.Itoa(rand.Int()))
41+
return createTestEnv(t, path)
3342
}
3443

3544
func createTestEnv(t testing.TB, path string) *testEnv {
36-
viper.Set("peer.fileSystemPath", path)
37-
env := &testEnv{t}
45+
env := &testEnv{
46+
t: t,
47+
path: path}
3848
env.cleanup()
49+
viper.Set("peer.fileSystemPath", env.path)
3950
return env
4051
}
4152

4253
func (env *testEnv) cleanup() {
43-
path := config.GetPath("peer.fileSystemPath")
44-
os.RemoveAll(path)
54+
os.RemoveAll(env.path)
4555
}

0 commit comments

Comments
 (0)