Skip to content

Commit 88e0e87

Browse files
committed
Use different folders for ledger tests in packages
https://jira.hyperledger.org/browse/FAB-1817 The golang tests in different packages are run in parallel (unless controlled by special flag `-p=1`). To avoid collision among tests of different packages, use different folders that are used to store ledger contents. Change-Id: I71a0d935a752fe26b8f309372db9210393bfcd49 Signed-off-by: manish <[email protected]>
1 parent 230f3cc commit 88e0e87

15 files changed

+40
-25
lines changed

core/ledger/blkstorage/fsblkstorage/block_stream_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestBlockfileStream(t *testing.T) {
3030
}
3131

3232
func testBlockfileStream(t *testing.T, numBlocks int) {
33-
env := newTestEnv(t, NewConf("/tmp/fabric/ledgertests", 0))
33+
env := newTestEnv(t, NewConf(testPath, 0))
3434
defer env.Cleanup()
3535
ledgerid := "testledger"
3636
w := newTestBlockfileWrapper(env, ledgerid)
@@ -71,7 +71,7 @@ func TestBlockFileStreamUnexpectedEOF(t *testing.T) {
7171
}
7272

7373
func testBlockFileStreamUnexpectedEOF(t *testing.T, numBlocks int, partialBlockBytes []byte) {
74-
env := newTestEnv(t, NewConf("/tmp/fabric/ledgertests", 0))
74+
env := newTestEnv(t, NewConf(testPath, 0))
7575
defer env.Cleanup()
7676
w := newTestBlockfileWrapper(env, "testLedger")
7777
blockfileMgr := w.blockfileMgr
@@ -100,7 +100,7 @@ func TestBlockStream(t *testing.T) {
100100
}
101101

102102
func testBlockStream(t *testing.T, numFiles int) {
103-
env := newTestEnv(t, NewConf("/tmp/fabric/ledgertests", 0))
103+
env := newTestEnv(t, NewConf(testPath, 0))
104104
defer env.Cleanup()
105105
w := newTestBlockfileWrapper(env, "testLedger")
106106
defer w.close()

core/ledger/blkstorage/fsblkstorage/blockfile_mgr_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
)
2929

3030
func TestBlockfileMgrBlockReadWrite(t *testing.T) {
31-
env := newTestEnv(t, NewConf("/tmp/fabric/ledgertests", 0))
31+
env := newTestEnv(t, NewConf(testPath, 0))
3232
defer env.Cleanup()
3333
blkfileMgrWrapper := newTestBlockfileWrapper(env, "testLedger")
3434
defer blkfileMgrWrapper.close()
@@ -47,7 +47,7 @@ func TestBlockfileMgrCrashDuringWriting(t *testing.T) {
4747

4848
func testBlockfileMgrCrashDuringWriting(t *testing.T, numBlocksBeforeCheckpoint int,
4949
numBlocksAfterCheckpoint int, numLastBlockBytes int, numPartialBytesToWrite int) {
50-
env := newTestEnv(t, NewConf("/tmp/fabric/ledgertests", 0))
50+
env := newTestEnv(t, NewConf(testPath, 0))
5151
defer env.Cleanup()
5252
ledgerid := "testLedger"
5353
blkfileMgrWrapper := newTestBlockfileWrapper(env, ledgerid)
@@ -92,7 +92,7 @@ func testBlockfileMgrCrashDuringWriting(t *testing.T, numBlocksBeforeCheckpoint
9292
}
9393

9494
func TestBlockfileMgrBlockIterator(t *testing.T) {
95-
env := newTestEnv(t, NewConf("/tmp/fabric/ledgertests", 0))
95+
env := newTestEnv(t, NewConf(testPath, 0))
9696
defer env.Cleanup()
9797
blkfileMgrWrapper := newTestBlockfileWrapper(env, "testLedger")
9898
defer blkfileMgrWrapper.close()
@@ -120,7 +120,7 @@ func testBlockfileMgrBlockIterator(t *testing.T, blockfileMgr *blockfileMgr,
120120
}
121121

122122
func TestBlockfileMgrBlockchainInfo(t *testing.T) {
123-
env := newTestEnv(t, NewConf("/tmp/fabric/ledgertests", 0))
123+
env := newTestEnv(t, NewConf(testPath, 0))
124124
defer env.Cleanup()
125125
blkfileMgrWrapper := newTestBlockfileWrapper(env, "testLedger")
126126
defer blkfileMgrWrapper.close()
@@ -135,7 +135,7 @@ func TestBlockfileMgrBlockchainInfo(t *testing.T) {
135135
}
136136

137137
func TestBlockfileMgrGetTxById(t *testing.T) {
138-
env := newTestEnv(t, NewConf("/tmp/fabric/ledgertests", 0))
138+
env := newTestEnv(t, NewConf(testPath, 0))
139139
defer env.Cleanup()
140140
blkfileMgrWrapper := newTestBlockfileWrapper(env, "testLedger")
141141
defer blkfileMgrWrapper.close()
@@ -156,7 +156,7 @@ func TestBlockfileMgrGetTxById(t *testing.T) {
156156
}
157157

158158
func TestBlockfileMgrRestart(t *testing.T) {
159-
env := newTestEnv(t, NewConf("/tmp/fabric/ledgertests", 0))
159+
env := newTestEnv(t, NewConf(testPath, 0))
160160
defer env.Cleanup()
161161
ledgerid := "testLedger"
162162
blkfileMgrWrapper := newTestBlockfileWrapper(env, ledgerid)
@@ -182,7 +182,7 @@ func TestBlockfileMgrFileRolling(t *testing.T) {
182182
}
183183

184184
maxFileSie := int(0.75 * float64(size))
185-
env := newTestEnv(t, NewConf("/tmp/fabric/ledgertests", maxFileSie))
185+
env := newTestEnv(t, NewConf(testPath, maxFileSie))
186186
defer env.Cleanup()
187187
ledgerid := "testLedger"
188188
blkfileMgrWrapper := newTestBlockfileWrapper(env, ledgerid)

core/ledger/blkstorage/fsblkstorage/blockfile_scan_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
)
2828

2929
func TestBlockFileScanSmallTxOnly(t *testing.T) {
30-
env := newTestEnv(t, NewConf("/tmp/fabric/ledgertests", 0))
30+
env := newTestEnv(t, NewConf(testPath, 0))
3131
defer env.Cleanup()
3232
ledgerid := "testLedger"
3333
blkfileMgrWrapper := newTestBlockfileWrapper(env, ledgerid)
@@ -50,7 +50,7 @@ func TestBlockFileScanSmallTxOnly(t *testing.T) {
5050
}
5151

5252
func TestBlockFileScanSmallTxLastTxIncomplete(t *testing.T) {
53-
env := newTestEnv(t, NewConf("/tmp/fabric/ledgertests", 0))
53+
env := newTestEnv(t, NewConf(testPath, 0))
5454
defer env.Cleanup()
5555
ledgerid := "testLedger"
5656
blkfileMgrWrapper := newTestBlockfileWrapper(env, ledgerid)

core/ledger/blkstorage/fsblkstorage/blockindex_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestBlockIndexSync(t *testing.T) {
5454
}
5555

5656
func testBlockIndexSync(t *testing.T, numBlocks int, numBlocksToIndex int, syncByRestart bool) {
57-
env := newTestEnv(t, NewConf("/tmp/fabric/ledgertests", 0))
57+
env := newTestEnv(t, NewConf(testPath, 0))
5858
defer env.Cleanup()
5959
ledgerid := "testledger"
6060
blkfileMgrWrapper := newTestBlockfileWrapper(env, ledgerid)
@@ -113,7 +113,7 @@ func TestBlockIndexSelectiveIndexing(t *testing.T) {
113113
}
114114

115115
func testBlockIndexSelectiveIndexing(t *testing.T, indexItems []blkstorage.IndexableAttr) {
116-
env := newTestEnvSelectiveIndexing(t, NewConf("/tmp/fabric/ledgertests", 0), indexItems)
116+
env := newTestEnvSelectiveIndexing(t, NewConf(testPath, 0), indexItems)
117117
defer env.Cleanup()
118118
blkfileMgrWrapper := newTestBlockfileWrapper(env, "testledger")
119119
defer blkfileMgrWrapper.close()

core/ledger/blkstorage/fsblkstorage/blocks_itr_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
)
2626

2727
func TestBlocksItrBlockingNext(t *testing.T) {
28-
env := newTestEnv(t, NewConf("/tmp/fabric/ledgertests", 0))
28+
env := newTestEnv(t, NewConf(testPath, 0))
2929
defer env.Cleanup()
3030
blkfileMgrWrapper := newTestBlockfileWrapper(env, "testLedger")
3131
defer blkfileMgrWrapper.close()

core/ledger/blkstorage/fsblkstorage/fs_blockstore_provider_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
)
2929

3030
func TestMultipleBlockStores(t *testing.T) {
31-
env := newTestEnv(t, NewConf("/tmp/fabric/ledgertests", 0))
31+
env := newTestEnv(t, NewConf(testPath, 0))
3232
defer env.Cleanup()
3333

3434
provider := env.provider
@@ -65,7 +65,7 @@ func checkBlocks(t *testing.T, expectedBlocks []*common.Block, store blkstorage.
6565
}
6666

6767
func TestBlockStoreProvider(t *testing.T) {
68-
env := newTestEnv(t, NewConf("/tmp/fabric/ledgertests", 0))
68+
env := newTestEnv(t, NewConf(testPath, 0))
6969
defer env.Cleanup()
7070

7171
provider := env.provider

core/ledger/blkstorage/fsblkstorage/pkg_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"github.com/hyperledger/fabric/protos/common"
2929
)
3030

31-
var testPath = "/tmp/fabric/ledgertests"
31+
var testPath = "/tmp/fabric/ledgertests/blkstorage/fsblkstorage"
3232

3333
type testEnv struct {
3434
t testing.TB

core/ledger/kvledger/pkg_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type testEnv struct {
2929
}
3030

3131
func newTestEnv(t testing.TB) *testEnv {
32-
viper.Set("peer.fileSystemPath", "/tmp/fabric/ledgertests")
32+
viper.Set("peer.fileSystemPath", "/tmp/fabric/ledgertests/kvledger")
3333
env := &testEnv{t}
3434
env.cleanup()
3535
return env

core/ledger/kvledger/txmgmt/statedb/stateleveldb/stateleveldb_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
)
2828

2929
func TestMain(m *testing.M) {
30-
viper.Set("peer.fileSystemPath", "/tmp/fabric/ledgertests")
30+
viper.Set("peer.fileSystemPath", "/tmp/fabric/ledgertests/kvledger/txmgmt/statedb/stateleveldb")
3131
os.Exit(m.Run())
3232
}
3333

core/ledger/kvledger/txmgmt/txmgr/commontests/pkg_test.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ import (
3131
"github.com/spf13/viper"
3232
)
3333

34+
const (
35+
testFilesystemPath = "/tmp/fabric/ledgertests/kvledger/txmgmt/txmgr/commontests"
36+
)
37+
3438
type testEnv interface {
3539
init(t *testing.T)
3640
getName() string
@@ -68,7 +72,7 @@ func (env *levelDBLockBasedEnv) getName() string {
6872
}
6973

7074
func (env *levelDBLockBasedEnv) init(t *testing.T) {
71-
viper.Set("peer.fileSystemPath", "/tmp/fabric/ledgertests")
75+
viper.Set("peer.fileSystemPath", testFilesystemPath)
7276
testDBEnv := stateleveldb.NewTestVDBEnv(t)
7377
testDB, err := testDBEnv.DBProvider.GetDBHandle("TestDB")
7478
testutil.AssertNoError(t, err, "")
@@ -107,7 +111,7 @@ func (env *couchDBLockBasedEnv) getName() string {
107111
}
108112

109113
func (env *couchDBLockBasedEnv) init(t *testing.T) {
110-
viper.Set("peer.fileSystemPath", "/tmp/fabric/ledgertests")
114+
viper.Set("peer.fileSystemPath", testFilesystemPath)
111115
viper.Set("ledger.state.couchDBConfig.couchDBAddress", "127.0.0.1:5984")
112116
testDBEnv := statecouchdb.NewTestVDBEnv(t)
113117
testDB, err := testDBEnv.DBProvider.GetDBHandle(couchTestChainID)

core/ledger/kvledger/txmgmt/validator/statebasedval/state_based_validator_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
)
3232

3333
func TestMain(m *testing.M) {
34-
viper.Set("peer.fileSystemPath", "/tmp/fabric/ledgertests")
34+
viper.Set("peer.fileSystemPath", "/tmp/fabric/ledgertests/kvledger/txmgmt/validator/statebasedval")
3535
os.Exit(m.Run())
3636
}
3737

core/ledger/ledgermgmt/ledger_mgmt_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,18 @@ import (
2020
"fmt"
2121
"testing"
2222

23+
"os"
24+
2325
"github.com/hyperledger/fabric/core/ledger"
2426
"github.com/hyperledger/fabric/core/ledger/testutil"
27+
"github.com/spf13/viper"
2528
)
2629

30+
func TestMain(m *testing.M) {
31+
viper.Set("peer.fileSystemPath", "/tmp/fabric/ledgertests/ledgermgmt")
32+
os.Exit(m.Run())
33+
}
34+
2735
func TestLedgerMgmt(t *testing.T) {
2836
InitializeTestEnv()
2937
defer CleanupTestEnv()

core/ledger/ledgermgmt/ledger_mgmt_test_exports.go

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package ledgermgmt
1919
import (
2020
"os"
2121

22+
"fmt"
23+
2224
"github.com/hyperledger/fabric/core/ledger/ledgerconfig"
2325
)
2426

@@ -36,6 +38,7 @@ func CleanupTestEnv() {
3638

3739
func remove() {
3840
path := ledgerconfig.GetRootPath()
41+
fmt.Printf("removing dir = %s\n", path)
3942
err := os.RemoveAll(path)
4043
if err != nil {
4144
logger.Errorf("Error: %s", err)

core/ledger/ordererledger/fs_ordererledger_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
)
2727

2828
const (
29-
testFolder = "/tmp/test/ledger/ordererledger"
29+
testFolder = "/tmp/fabric/ledgertests/ordererledger"
3030
)
3131

3232
func TestOrdererLedger(t *testing.T) {

core/ledger/util/leveldbhelper/leveldb_helper_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"github.com/hyperledger/fabric/core/ledger/testutil"
2525
)
2626

27-
const testDBPath = "/tmp/test/hyperledger/fabric/core/ledger/util/db"
27+
const testDBPath = "/tmp/fabric/ledgertests/util/leveldbhelper"
2828

2929
func TestDBBasicWriteAndReads(t *testing.T) {
3030
testDBBasicWriteAndReads(t, "db1", "db2", "")

0 commit comments

Comments
 (0)