Skip to content

Commit 963042a

Browse files
committed
FAB-1758 Fix CouchDB tests when run in parallel
When various packages that utilize CouchDB were tested all together, we received intermitent test failures due to collisions in test envionment. Fixed by scoping each test package to different CouchDB databases (chains). Change-Id: I93b9043f7a5a60b1052d74e9f5f877f9e19a29d9 Signed-off-by: denyeart <[email protected]>
1 parent add2776 commit 963042a

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
lines changed

core/ledger/kvledger/txmgmt/statedb/statecouchdb/statecouchdb_test.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ func TestBasicRW(t *testing.T) {
4141
if ledgerconfig.IsCouchDBEnabled() == true {
4242

4343
env := NewTestVDBEnv(t)
44-
defer env.Cleanup()
44+
env.Cleanup("TestDB")
45+
defer env.Cleanup("TestDB")
4546
commontests.TestBasicRW(t, env.DBProvider)
4647

4748
}
@@ -51,7 +52,10 @@ func TestMultiDBBasicRW(t *testing.T) {
5152
if ledgerconfig.IsCouchDBEnabled() == true {
5253

5354
env := NewTestVDBEnv(t)
54-
defer env.Cleanup()
55+
env.Cleanup("TestDB1")
56+
env.Cleanup("TestDB2")
57+
defer env.Cleanup("TestDB1")
58+
defer env.Cleanup("TestDB2")
5559
commontests.TestMultiDBBasicRW(t, env.DBProvider)
5660

5761
}
@@ -60,7 +64,8 @@ func TestMultiDBBasicRW(t *testing.T) {
6064
/* TODO add delete support in couchdb and then convert key value of nil to a couch delete. This will resolve TestDeletes
6165
func TestDeletes(t *testing.T) {
6266
env := NewTestVDBEnv(t)
63-
defer env.Cleanup()
67+
env.Cleanup("TestDB")
68+
defer env.Cleanup("TestDB")
6469
commontests.TestDeletes(t, env.DBProvider)
6570
}
6671
*/
@@ -69,7 +74,8 @@ func TestIterator(t *testing.T) {
6974
if ledgerconfig.IsCouchDBEnabled() == true {
7075

7176
env := NewTestVDBEnv(t)
72-
defer env.Cleanup()
77+
env.Cleanup("TestDB")
78+
defer env.Cleanup("TestDB")
7379
commontests.TestIterator(t, env.DBProvider)
7480

7581
}
@@ -113,7 +119,8 @@ func TestQuery(t *testing.T) {
113119
if ledgerconfig.IsCouchDBEnabled() == true {
114120

115121
env := NewTestVDBEnv(t)
116-
defer env.Cleanup()
122+
env.Cleanup("TestDB")
123+
defer env.Cleanup("TestDB")
117124
commontests.TestQuery(t, env.DBProvider)
118125

119126
}

core/ledger/kvledger/txmgmt/statedb/statecouchdb/statecouchdb_test_export.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package statecouchdb
1818

1919
import (
20+
"strings"
2021
"testing"
2122

2223
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb"
@@ -29,28 +30,26 @@ var badConnectURL = "localhost:5990"
2930
var username = ""
3031
var password = ""
3132

32-
// TestVDBEnv provides a level db backed versioned db for testing
33+
// TestVDBEnv provides a couch db backed versioned db for testing
3334
type TestVDBEnv struct {
3435
t testing.TB
3536
DBProvider statedb.VersionedDBProvider
3637
}
3738

38-
// NewTestVDBEnv instantiates and new level db backed TestVDB
39+
// NewTestVDBEnv instantiates and new couch db backed TestVDB
3940
func NewTestVDBEnv(t testing.TB) *TestVDBEnv {
4041
t.Logf("Creating new TestVDBEnv")
4142

4243
dbProvider, _ := NewVersionedDBProvider()
4344
testVDBEnv := &TestVDBEnv{t, dbProvider}
44-
testVDBEnv.Cleanup()
45+
// No cleanup for new test environment. Need to cleanup per test for each DB used in the test.
4546
return testVDBEnv
4647
}
4748

4849
// Cleanup drops the test couch databases and closes the db provider
49-
func (env *TestVDBEnv) Cleanup() {
50+
func (env *TestVDBEnv) Cleanup(dbName string) {
5051
env.t.Logf("Cleaningup TestVDBEnv")
51-
cleanupDB("testdb")
52-
cleanupDB("testdb1")
53-
cleanupDB("testdb2")
52+
cleanupDB(strings.ToLower(dbName))
5453
env.DBProvider.Close()
5554

5655
}

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

+10-2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ func init() {
5555

5656
}
5757

58+
///////////// LevelDB Environment //////////////
59+
5860
type levelDBLockBasedEnv struct {
5961
testDBEnv *stateleveldb.TestVDBEnv
6062
testDB statedb.VersionedDB
@@ -90,6 +92,10 @@ func (env *levelDBLockBasedEnv) cleanup() {
9092
defer env.testDBEnv.Cleanup()
9193
}
9294

95+
///////////// CouchDB Environment //////////////
96+
97+
var couchTestChainID = "TxmgrTestDB"
98+
9399
type couchDBLockBasedEnv struct {
94100
testDBEnv *statecouchdb.TestVDBEnv
95101
testDB statedb.VersionedDB
@@ -104,7 +110,7 @@ func (env *couchDBLockBasedEnv) init(t *testing.T) {
104110
viper.Set("peer.fileSystemPath", "/tmp/fabric/ledgertests")
105111
viper.Set("ledger.state.couchDBConfig.couchDBAddress", "127.0.0.1:5984")
106112
testDBEnv := statecouchdb.NewTestVDBEnv(t)
107-
testDB, err := testDBEnv.DBProvider.GetDBHandle("TestDB")
113+
testDB, err := testDBEnv.DBProvider.GetDBHandle(couchTestChainID)
108114
testutil.AssertNoError(t, err, "")
109115

110116
txMgr := lockbasedtxmgr.NewLockBasedTxMgr(testDB)
@@ -123,9 +129,11 @@ func (env *couchDBLockBasedEnv) getVDB() statedb.VersionedDB {
123129

124130
func (env *couchDBLockBasedEnv) cleanup() {
125131
defer env.txmgr.Shutdown()
126-
defer env.testDBEnv.Cleanup()
132+
defer env.testDBEnv.Cleanup(couchTestChainID)
127133
}
128134

135+
//////////// txMgrTestHelper /////////////
136+
129137
type txMgrTestHelper struct {
130138
t *testing.T
131139
txMgr txmgr.TxMgr

core/ledger/util/couchdb/couchdb_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
//Basic setup to test couch
2929
var connectURL = "localhost:5984"
3030
var badConnectURL = "localhost:5990"
31-
var database = "testdb1"
31+
var database = "couch_util_testdb"
3232
var username = ""
3333
var password = ""
3434

0 commit comments

Comments
 (0)