diff --git a/core/ledger/kvledger/txmgmt/statedb/statecouchdb/statecouchdb_test.go b/core/ledger/kvledger/txmgmt/statedb/statecouchdb/statecouchdb_test.go index d5ceb67c90..9b1aece381 100644 --- a/core/ledger/kvledger/txmgmt/statedb/statecouchdb/statecouchdb_test.go +++ b/core/ledger/kvledger/txmgmt/statedb/statecouchdb/statecouchdb_test.go @@ -41,7 +41,8 @@ func TestBasicRW(t *testing.T) { if ledgerconfig.IsCouchDBEnabled() == true { env := NewTestVDBEnv(t) - defer env.Cleanup() + env.Cleanup("TestDB") + defer env.Cleanup("TestDB") commontests.TestBasicRW(t, env.DBProvider) } @@ -51,7 +52,10 @@ func TestMultiDBBasicRW(t *testing.T) { if ledgerconfig.IsCouchDBEnabled() == true { env := NewTestVDBEnv(t) - defer env.Cleanup() + env.Cleanup("TestDB1") + env.Cleanup("TestDB2") + defer env.Cleanup("TestDB1") + defer env.Cleanup("TestDB2") commontests.TestMultiDBBasicRW(t, env.DBProvider) } @@ -60,7 +64,8 @@ func TestMultiDBBasicRW(t *testing.T) { /* TODO add delete support in couchdb and then convert key value of nil to a couch delete. This will resolve TestDeletes func TestDeletes(t *testing.T) { env := NewTestVDBEnv(t) - defer env.Cleanup() + env.Cleanup("TestDB") + defer env.Cleanup("TestDB") commontests.TestDeletes(t, env.DBProvider) } */ @@ -69,7 +74,8 @@ func TestIterator(t *testing.T) { if ledgerconfig.IsCouchDBEnabled() == true { env := NewTestVDBEnv(t) - defer env.Cleanup() + env.Cleanup("TestDB") + defer env.Cleanup("TestDB") commontests.TestIterator(t, env.DBProvider) } @@ -113,7 +119,8 @@ func TestQuery(t *testing.T) { if ledgerconfig.IsCouchDBEnabled() == true { env := NewTestVDBEnv(t) - defer env.Cleanup() + env.Cleanup("TestDB") + defer env.Cleanup("TestDB") commontests.TestQuery(t, env.DBProvider) } diff --git a/core/ledger/kvledger/txmgmt/statedb/statecouchdb/statecouchdb_test_export.go b/core/ledger/kvledger/txmgmt/statedb/statecouchdb/statecouchdb_test_export.go index c38e85641f..b59f3f9c3f 100644 --- a/core/ledger/kvledger/txmgmt/statedb/statecouchdb/statecouchdb_test_export.go +++ b/core/ledger/kvledger/txmgmt/statedb/statecouchdb/statecouchdb_test_export.go @@ -17,6 +17,7 @@ limitations under the License. package statecouchdb import ( + "strings" "testing" "github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb" @@ -29,28 +30,26 @@ var badConnectURL = "localhost:5990" var username = "" var password = "" -// TestVDBEnv provides a level db backed versioned db for testing +// TestVDBEnv provides a couch db backed versioned db for testing type TestVDBEnv struct { t testing.TB DBProvider statedb.VersionedDBProvider } -// NewTestVDBEnv instantiates and new level db backed TestVDB +// NewTestVDBEnv instantiates and new couch db backed TestVDB func NewTestVDBEnv(t testing.TB) *TestVDBEnv { t.Logf("Creating new TestVDBEnv") dbProvider, _ := NewVersionedDBProvider() testVDBEnv := &TestVDBEnv{t, dbProvider} - testVDBEnv.Cleanup() + // No cleanup for new test environment. Need to cleanup per test for each DB used in the test. return testVDBEnv } // Cleanup drops the test couch databases and closes the db provider -func (env *TestVDBEnv) Cleanup() { +func (env *TestVDBEnv) Cleanup(dbName string) { env.t.Logf("Cleaningup TestVDBEnv") - cleanupDB("testdb") - cleanupDB("testdb1") - cleanupDB("testdb2") + cleanupDB(strings.ToLower(dbName)) env.DBProvider.Close() } diff --git a/core/ledger/kvledger/txmgmt/txmgr/commontests/pkg_test.go b/core/ledger/kvledger/txmgmt/txmgr/commontests/pkg_test.go index ccf35ea05d..9002d4aefc 100644 --- a/core/ledger/kvledger/txmgmt/txmgr/commontests/pkg_test.go +++ b/core/ledger/kvledger/txmgmt/txmgr/commontests/pkg_test.go @@ -55,6 +55,8 @@ func init() { } +///////////// LevelDB Environment ////////////// + type levelDBLockBasedEnv struct { testDBEnv *stateleveldb.TestVDBEnv testDB statedb.VersionedDB @@ -90,6 +92,10 @@ func (env *levelDBLockBasedEnv) cleanup() { defer env.testDBEnv.Cleanup() } +///////////// CouchDB Environment ////////////// + +var couchTestChainID = "TxmgrTestDB" + type couchDBLockBasedEnv struct { testDBEnv *statecouchdb.TestVDBEnv testDB statedb.VersionedDB @@ -104,7 +110,7 @@ func (env *couchDBLockBasedEnv) init(t *testing.T) { viper.Set("peer.fileSystemPath", "/tmp/fabric/ledgertests") viper.Set("ledger.state.couchDBConfig.couchDBAddress", "127.0.0.1:5984") testDBEnv := statecouchdb.NewTestVDBEnv(t) - testDB, err := testDBEnv.DBProvider.GetDBHandle("TestDB") + testDB, err := testDBEnv.DBProvider.GetDBHandle(couchTestChainID) testutil.AssertNoError(t, err, "") txMgr := lockbasedtxmgr.NewLockBasedTxMgr(testDB) @@ -123,9 +129,11 @@ func (env *couchDBLockBasedEnv) getVDB() statedb.VersionedDB { func (env *couchDBLockBasedEnv) cleanup() { defer env.txmgr.Shutdown() - defer env.testDBEnv.Cleanup() + defer env.testDBEnv.Cleanup(couchTestChainID) } +//////////// txMgrTestHelper ///////////// + type txMgrTestHelper struct { t *testing.T txMgr txmgr.TxMgr diff --git a/core/ledger/util/couchdb/couchdb_test.go b/core/ledger/util/couchdb/couchdb_test.go index 05da31910e..0847943d51 100644 --- a/core/ledger/util/couchdb/couchdb_test.go +++ b/core/ledger/util/couchdb/couchdb_test.go @@ -28,7 +28,7 @@ import ( //Basic setup to test couch var connectURL = "localhost:5984" var badConnectURL = "localhost:5990" -var database = "testdb1" +var database = "couch_util_testdb" var username = "" var password = ""