Skip to content

Commit

Permalink
Use different folders for ledger tests in packages
Browse files Browse the repository at this point in the history
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 <manish.sethi@gmail.com>
  • Loading branch information
manish-sethi committed Jan 24, 2017
1 parent 230f3cc commit 88e0e87
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 25 deletions.
6 changes: 3 additions & 3 deletions core/ledger/blkstorage/fsblkstorage/block_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestBlockfileStream(t *testing.T) {
}

func testBlockfileStream(t *testing.T, numBlocks int) {
env := newTestEnv(t, NewConf("/tmp/fabric/ledgertests", 0))
env := newTestEnv(t, NewConf(testPath, 0))
defer env.Cleanup()
ledgerid := "testledger"
w := newTestBlockfileWrapper(env, ledgerid)
Expand Down Expand Up @@ -71,7 +71,7 @@ func TestBlockFileStreamUnexpectedEOF(t *testing.T) {
}

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

func testBlockStream(t *testing.T, numFiles int) {
env := newTestEnv(t, NewConf("/tmp/fabric/ledgertests", 0))
env := newTestEnv(t, NewConf(testPath, 0))
defer env.Cleanup()
w := newTestBlockfileWrapper(env, "testLedger")
defer w.close()
Expand Down
14 changes: 7 additions & 7 deletions core/ledger/blkstorage/fsblkstorage/blockfile_mgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

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

func testBlockfileMgrCrashDuringWriting(t *testing.T, numBlocksBeforeCheckpoint int,
numBlocksAfterCheckpoint int, numLastBlockBytes int, numPartialBytesToWrite int) {
env := newTestEnv(t, NewConf("/tmp/fabric/ledgertests", 0))
env := newTestEnv(t, NewConf(testPath, 0))
defer env.Cleanup()
ledgerid := "testLedger"
blkfileMgrWrapper := newTestBlockfileWrapper(env, ledgerid)
Expand Down Expand Up @@ -92,7 +92,7 @@ func testBlockfileMgrCrashDuringWriting(t *testing.T, numBlocksBeforeCheckpoint
}

func TestBlockfileMgrBlockIterator(t *testing.T) {
env := newTestEnv(t, NewConf("/tmp/fabric/ledgertests", 0))
env := newTestEnv(t, NewConf(testPath, 0))
defer env.Cleanup()
blkfileMgrWrapper := newTestBlockfileWrapper(env, "testLedger")
defer blkfileMgrWrapper.close()
Expand Down Expand Up @@ -120,7 +120,7 @@ func testBlockfileMgrBlockIterator(t *testing.T, blockfileMgr *blockfileMgr,
}

func TestBlockfileMgrBlockchainInfo(t *testing.T) {
env := newTestEnv(t, NewConf("/tmp/fabric/ledgertests", 0))
env := newTestEnv(t, NewConf(testPath, 0))
defer env.Cleanup()
blkfileMgrWrapper := newTestBlockfileWrapper(env, "testLedger")
defer blkfileMgrWrapper.close()
Expand All @@ -135,7 +135,7 @@ func TestBlockfileMgrBlockchainInfo(t *testing.T) {
}

func TestBlockfileMgrGetTxById(t *testing.T) {
env := newTestEnv(t, NewConf("/tmp/fabric/ledgertests", 0))
env := newTestEnv(t, NewConf(testPath, 0))
defer env.Cleanup()
blkfileMgrWrapper := newTestBlockfileWrapper(env, "testLedger")
defer blkfileMgrWrapper.close()
Expand All @@ -156,7 +156,7 @@ func TestBlockfileMgrGetTxById(t *testing.T) {
}

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

maxFileSie := int(0.75 * float64(size))
env := newTestEnv(t, NewConf("/tmp/fabric/ledgertests", maxFileSie))
env := newTestEnv(t, NewConf(testPath, maxFileSie))
defer env.Cleanup()
ledgerid := "testLedger"
blkfileMgrWrapper := newTestBlockfileWrapper(env, ledgerid)
Expand Down
4 changes: 2 additions & 2 deletions core/ledger/blkstorage/fsblkstorage/blockfile_scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

func TestBlockFileScanSmallTxOnly(t *testing.T) {
env := newTestEnv(t, NewConf("/tmp/fabric/ledgertests", 0))
env := newTestEnv(t, NewConf(testPath, 0))
defer env.Cleanup()
ledgerid := "testLedger"
blkfileMgrWrapper := newTestBlockfileWrapper(env, ledgerid)
Expand All @@ -50,7 +50,7 @@ func TestBlockFileScanSmallTxOnly(t *testing.T) {
}

func TestBlockFileScanSmallTxLastTxIncomplete(t *testing.T) {
env := newTestEnv(t, NewConf("/tmp/fabric/ledgertests", 0))
env := newTestEnv(t, NewConf(testPath, 0))
defer env.Cleanup()
ledgerid := "testLedger"
blkfileMgrWrapper := newTestBlockfileWrapper(env, ledgerid)
Expand Down
4 changes: 2 additions & 2 deletions core/ledger/blkstorage/fsblkstorage/blockindex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestBlockIndexSync(t *testing.T) {
}

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

func testBlockIndexSelectiveIndexing(t *testing.T, indexItems []blkstorage.IndexableAttr) {
env := newTestEnvSelectiveIndexing(t, NewConf("/tmp/fabric/ledgertests", 0), indexItems)
env := newTestEnvSelectiveIndexing(t, NewConf(testPath, 0), indexItems)
defer env.Cleanup()
blkfileMgrWrapper := newTestBlockfileWrapper(env, "testledger")
defer blkfileMgrWrapper.close()
Expand Down
2 changes: 1 addition & 1 deletion core/ledger/blkstorage/fsblkstorage/blocks_itr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

func TestBlocksItrBlockingNext(t *testing.T) {
env := newTestEnv(t, NewConf("/tmp/fabric/ledgertests", 0))
env := newTestEnv(t, NewConf(testPath, 0))
defer env.Cleanup()
blkfileMgrWrapper := newTestBlockfileWrapper(env, "testLedger")
defer blkfileMgrWrapper.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

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

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

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

provider := env.provider
Expand Down
2 changes: 1 addition & 1 deletion core/ledger/blkstorage/fsblkstorage/pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/hyperledger/fabric/protos/common"
)

var testPath = "/tmp/fabric/ledgertests"
var testPath = "/tmp/fabric/ledgertests/blkstorage/fsblkstorage"

type testEnv struct {
t testing.TB
Expand Down
2 changes: 1 addition & 1 deletion core/ledger/kvledger/pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type testEnv struct {
}

func newTestEnv(t testing.TB) *testEnv {
viper.Set("peer.fileSystemPath", "/tmp/fabric/ledgertests")
viper.Set("peer.fileSystemPath", "/tmp/fabric/ledgertests/kvledger")
env := &testEnv{t}
env.cleanup()
return env
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

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

Expand Down
8 changes: 6 additions & 2 deletions core/ledger/kvledger/txmgmt/txmgr/commontests/pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ import (
"github.com/spf13/viper"
)

const (
testFilesystemPath = "/tmp/fabric/ledgertests/kvledger/txmgmt/txmgr/commontests"
)

type testEnv interface {
init(t *testing.T)
getName() string
Expand Down Expand Up @@ -68,7 +72,7 @@ func (env *levelDBLockBasedEnv) getName() string {
}

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

func (env *couchDBLockBasedEnv) init(t *testing.T) {
viper.Set("peer.fileSystemPath", "/tmp/fabric/ledgertests")
viper.Set("peer.fileSystemPath", testFilesystemPath)
viper.Set("ledger.state.couchDBConfig.couchDBAddress", "127.0.0.1:5984")
testDBEnv := statecouchdb.NewTestVDBEnv(t)
testDB, err := testDBEnv.DBProvider.GetDBHandle(couchTestChainID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
)

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

Expand Down
8 changes: 8 additions & 0 deletions core/ledger/ledgermgmt/ledger_mgmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@ import (
"fmt"
"testing"

"os"

"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/ledger/testutil"
"github.com/spf13/viper"
)

func TestMain(m *testing.M) {
viper.Set("peer.fileSystemPath", "/tmp/fabric/ledgertests/ledgermgmt")
os.Exit(m.Run())
}

func TestLedgerMgmt(t *testing.T) {
InitializeTestEnv()
defer CleanupTestEnv()
Expand Down
3 changes: 3 additions & 0 deletions core/ledger/ledgermgmt/ledger_mgmt_test_exports.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package ledgermgmt
import (
"os"

"fmt"

"github.com/hyperledger/fabric/core/ledger/ledgerconfig"
)

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

func remove() {
path := ledgerconfig.GetRootPath()
fmt.Printf("removing dir = %s\n", path)
err := os.RemoveAll(path)
if err != nil {
logger.Errorf("Error: %s", err)
Expand Down
2 changes: 1 addition & 1 deletion core/ledger/ordererledger/fs_ordererledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

const (
testFolder = "/tmp/test/ledger/ordererledger"
testFolder = "/tmp/fabric/ledgertests/ordererledger"
)

func TestOrdererLedger(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion core/ledger/util/leveldbhelper/leveldb_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/hyperledger/fabric/core/ledger/testutil"
)

const testDBPath = "/tmp/test/hyperledger/fabric/core/ledger/util/db"
const testDBPath = "/tmp/fabric/ledgertests/util/leveldbhelper"

func TestDBBasicWriteAndReads(t *testing.T) {
testDBBasicWriteAndReads(t, "db1", "db2", "")
Expand Down

0 comments on commit 88e0e87

Please sign in to comment.