Skip to content

Commit f6fb341

Browse files
torcolvinbbrks
authored andcommitted
CBG-4366 enable resurrection tests (#7229)
1 parent 4fc9df0 commit f6fb341

File tree

7 files changed

+144
-99
lines changed

7 files changed

+144
-99
lines changed

rest/utilities_testing_resttester.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ func (rt *RestTester) Run(name string, test func(*testing.T)) {
3636
})
3737
}
3838

39+
func (rt *RestTester) UpdateTB(t *testing.T) {
40+
var tb testing.TB = t
41+
rt.testingTB.Store(&tb)
42+
}
43+
3944
// GetDocBody returns the doc body for the given docID. If the document is not found, t.Fail will be called.
4045
func (rt *RestTester) GetDocBody(docID string) db.Body {
4146
rawResponse := rt.SendAdminRequest("GET", "/{{.keyspace}}/"+docID, "")

topologytest/couchbase_lite_mock_peer_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ func (p *CouchbaseLiteMockPeer) TB() testing.TB {
170170
return p.t
171171
}
172172

173+
// UpdateTB updates the testing.TB for the peer.
174+
func (p *CouchbaseLiteMockPeer) UpdateTB(t *testing.T) {
175+
p.t = t
176+
}
177+
173178
// GetBackingBucket returns the backing bucket for the peer. This is always nil.
174179
func (p *CouchbaseLiteMockPeer) GetBackingBucket() base.Bucket {
175180
return nil

topologytest/couchbase_server_peer_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ func (p *CouchbaseServerPeer) TB() testing.TB {
276276
return p.tb
277277
}
278278

279+
func (p *CouchbaseServerPeer) UpdateTB(tb *testing.T) {
280+
p.tb = tb
281+
}
282+
279283
// getDocVersion returns a DocVersion from a cas and xattrs with _vv (hlv) and _sync (RevTreeID).
280284
func getDocVersion(docID string, peer Peer, cas uint64, xattrs map[string][]byte) DocMetadata {
281285
docVersion := DocMetadata{

topologytest/hlv_test.go

Lines changed: 101 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,6 @@ func (t singleActorTest) collectionName() base.ScopeAndCollectionName {
5656
return getSingleDsName()
5757
}
5858

59-
// getSingleActorTestCase returns a list of test cases in the matrix for all topologies * active peers.
60-
func getSingleActorTestCase() []singleActorTest {
61-
var tests []singleActorTest
62-
for _, tc := range append(simpleTopologies, Topologies...) {
63-
for _, activePeerID := range tc.PeerNames() {
64-
tests = append(tests, singleActorTest{topology: tc, activePeerID: activePeerID})
65-
}
66-
}
67-
return tests
68-
}
69-
7059
// multiActorTest represents a test case for a single actor in a given topology.
7160
type multiActorTest struct {
7261
topology Topology
@@ -118,14 +107,19 @@ func startPeerReplications(peerReplications []PeerReplication) {
118107
func TestHLVCreateDocumentSingleActor(t *testing.T) {
119108

120109
base.SetUpTestLogging(t, base.LevelDebug, base.KeyCRUD, base.KeyImport, base.KeyVV)
121-
for _, tc := range getSingleActorTestCase() {
122-
t.Run(tc.description(), func(t *testing.T) {
123-
peers, _ := setupTests(t, tc.topology, tc.activePeerID)
124-
125-
docID := getDocID(t)
126-
docBody := []byte(fmt.Sprintf(`{"peer": "%s", "topology": "%s"}`, tc.activePeerID, tc.description()))
127-
docVersion := peers[tc.activePeerID].CreateDocument(tc.collectionName(), docID, docBody)
128-
waitForVersionAndBody(t, tc, peers, docID, docVersion)
110+
for _, topology := range append(simpleTopologies, Topologies...) {
111+
t.Run(topology.description, func(t *testing.T) {
112+
peers, _ := setupTests(t, topology)
113+
for _, activePeerID := range topology.PeerNames() {
114+
t.Run(fmt.Sprintf("actor=%s", activePeerID), func(t *testing.T) {
115+
updatePeersT(t, peers)
116+
tc := singleActorTest{topology: topology, activePeerID: activePeerID}
117+
docID := getDocID(t)
118+
docBody := []byte(fmt.Sprintf(`{"peer": "%s", "topology": "%s"}`, activePeerID, tc.description()))
119+
docVersion := peers[activePeerID].CreateDocument(getSingleDsName(), docID, docBody)
120+
waitForVersionAndBody(t, tc, peers, docID, docVersion)
121+
})
122+
}
129123
})
130124
}
131125
}
@@ -135,7 +129,7 @@ func TestHLVCreateDocumentMultiActor(t *testing.T) {
135129

136130
for _, tc := range getMultiActorTestCases() {
137131
t.Run(tc.description(), func(t *testing.T) {
138-
peers, _ := setupTests(t, tc.topology, "")
132+
peers, _ := setupTests(t, tc.topology)
139133

140134
var docVersionList []BodyAndVersion
141135

@@ -173,7 +167,7 @@ func TestHLVCreateDocumentMultiActorConflict(t *testing.T) {
173167
t.Skip("We need to be able to wait for a specific version to arrive over pull replication, CBG-4257")
174168
}
175169
t.Run(tc.description(), func(t *testing.T) {
176-
peers, replications := setupTests(t, tc.topology, "")
170+
peers, replications := setupTests(t, tc.topology)
177171

178172
stopPeerReplications(replications)
179173

@@ -196,7 +190,7 @@ func TestHLVUpdateDocumentMultiActor(t *testing.T) {
196190
if strings.Contains(tc.description(), "CBL") {
197191
t.Skip("Skipping Couchbase Lite test, returns unexpected body in proposeChanges: [304], CBG-4257")
198192
}
199-
peers, _ := setupTests(t, tc.topology, "")
193+
peers, _ := setupTests(t, tc.topology)
200194

201195
// grab sorted peer list and create a list to store expected version,
202196
// doc body and the peer the write came from
@@ -228,25 +222,32 @@ func TestHLVUpdateDocumentMultiActor(t *testing.T) {
228222
func TestHLVUpdateDocumentSingleActor(t *testing.T) {
229223

230224
base.SetUpTestLogging(t, base.LevelDebug, base.KeyCRUD, base.KeyImport, base.KeyVV)
231-
for _, tc := range getSingleActorTestCase() {
232-
t.Run(tc.description(), func(t *testing.T) {
233-
if strings.HasPrefix(tc.activePeerID, "cbl") {
234-
t.Skip("Skipping Couchbase Lite test, returns unexpected body in proposeChanges: [304], CBG-4257")
235-
}
236-
peers, _ := setupTests(t, tc.topology, tc.activePeerID)
237225

238-
docID := getDocID(t)
239-
body1 := []byte(fmt.Sprintf(`{"peer": "%s", "topology": "%s", "write": 1}`, tc.activePeerID, tc.description()))
240-
createVersion := peers[tc.activePeerID].CreateDocument(tc.collectionName(), docID, body1)
226+
for _, topology := range append(simpleTopologies, Topologies...) {
227+
t.Run(topology.description, func(t *testing.T) {
228+
peers, _ := setupTests(t, topology)
229+
for _, activePeerID := range topology.PeerNames() {
230+
t.Run(fmt.Sprintf("actor=%s", activePeerID), func(t *testing.T) {
231+
updatePeersT(t, peers)
232+
tc := singleActorTest{topology: topology, activePeerID: activePeerID}
233+
if strings.HasPrefix(tc.activePeerID, "cbl") {
234+
t.Skip("Skipping Couchbase Lite test, returns unexpected body in proposeChanges: [304], CBG-4257")
235+
}
236+
237+
docID := getDocID(t)
238+
body1 := []byte(fmt.Sprintf(`{"peer": "%s", "topology": "%s", "write": 1}`, tc.activePeerID, tc.description()))
239+
createVersion := peers[tc.activePeerID].CreateDocument(tc.collectionName(), docID, body1)
241240

242-
waitForVersionAndBody(t, tc, peers, docID, createVersion)
241+
waitForVersionAndBody(t, tc, peers, docID, createVersion)
243242

244-
body2 := []byte(fmt.Sprintf(`{"peer": "%s", "topology": "%s", "write": 2}`, tc.activePeerID, tc.description()))
245-
updateVersion := peers[tc.activePeerID].WriteDocument(tc.collectionName(), docID, body2)
246-
t.Logf("createVersion: %+v, updateVersion: %+v", createVersion.docMeta, updateVersion.docMeta)
247-
t.Logf("waiting for document version 2 on all peers")
243+
body2 := []byte(fmt.Sprintf(`{"peer": "%s", "topology": "%s", "write": 2}`, tc.activePeerID, tc.description()))
244+
updateVersion := peers[tc.activePeerID].WriteDocument(tc.collectionName(), docID, body2)
245+
t.Logf("createVersion: %+v, updateVersion: %+v", createVersion.docMeta, updateVersion.docMeta)
246+
t.Logf("waiting for document version 2 on all peers")
248247

249-
waitForVersionAndBody(t, tc, peers, docID, updateVersion)
248+
waitForVersionAndBody(t, tc, peers, docID, updateVersion)
249+
})
250+
}
250251
})
251252
}
252253
}
@@ -272,7 +273,7 @@ func TestHLVUpdateDocumentMultiActorConflict(t *testing.T) {
272273
t.Skip("We need to be able to wait for a specific version to arrive over pull replication + unexpected body in proposeChanges: [304] issue, CBG-4257")
273274
}
274275
t.Run(tc.description(), func(t *testing.T) {
275-
peers, replications := setupTests(t, tc.topology, "")
276+
peers, replications := setupTests(t, tc.topology)
276277
stopPeerReplications(replications)
277278

278279
docID := getDocID(t)
@@ -294,23 +295,31 @@ func TestHLVUpdateDocumentMultiActorConflict(t *testing.T) {
294295
func TestHLVDeleteDocumentSingleActor(t *testing.T) {
295296

296297
base.SetUpTestLogging(t, base.LevelDebug, base.KeyImport, base.KeyVV)
297-
for _, tc := range getSingleActorTestCase() {
298-
t.Run(tc.description(), func(t *testing.T) {
299-
if strings.HasPrefix(tc.activePeerID, "cbl") {
300-
t.Skip("Skipping Couchbase Lite test, does not know how to push a deletion yet CBG-4257")
301-
}
302-
peers, _ := setupTests(t, tc.topology, tc.activePeerID)
303298

304-
docID := getDocID(t)
305-
body1 := []byte(fmt.Sprintf(`{"peer": "%s", "topology": "%s", "write": 1}`, tc.activePeerID, tc.description()))
306-
createVersion := peers[tc.activePeerID].CreateDocument(tc.collectionName(), docID, body1)
299+
for _, topology := range append(simpleTopologies, Topologies...) {
300+
t.Run(topology.description, func(t *testing.T) {
301+
peers, _ := setupTests(t, topology)
302+
for _, activePeerID := range topology.PeerNames() {
303+
t.Run(fmt.Sprintf("actor=%s", activePeerID), func(t *testing.T) {
304+
updatePeersT(t, peers)
305+
tc := singleActorTest{topology: topology, activePeerID: activePeerID}
307306

308-
waitForVersionAndBody(t, tc, peers, docID, createVersion)
307+
if strings.HasPrefix(tc.activePeerID, "cbl") {
308+
t.Skip("Skipping Couchbase Lite test, does not know how to push a deletion yet CBG-4257")
309+
}
310+
311+
docID := getDocID(t)
312+
body1 := []byte(fmt.Sprintf(`{"peer": "%s", "topology": "%s", "write": 1}`, tc.activePeerID, tc.description()))
313+
createVersion := peers[tc.activePeerID].CreateDocument(tc.collectionName(), docID, body1)
309314

310-
deleteVersion := peers[tc.activePeerID].DeleteDocument(tc.collectionName(), docID)
311-
t.Logf("createVersion: %+v, deleteVersion: %+v", createVersion.docMeta, deleteVersion)
312-
t.Logf("waiting for document deletion on all peers")
313-
waitForDeletion(t, tc, peers, docID, tc.activePeerID)
315+
waitForVersionAndBody(t, tc, peers, docID, createVersion)
316+
317+
deleteVersion := peers[tc.activePeerID].DeleteDocument(tc.collectionName(), docID)
318+
t.Logf("createVersion: %+v, deleteVersion: %+v", createVersion.docMeta, deleteVersion)
319+
t.Logf("waiting for document deletion on all peers")
320+
waitForDeletion(t, tc, peers, docID, tc.activePeerID)
321+
})
322+
}
314323
})
315324
}
316325
}
@@ -323,7 +332,7 @@ func TestHLVDeleteDocumentMultiActor(t *testing.T) {
323332
if strings.Contains(tc.description(), "CBL") {
324333
t.Skip("Skipping Couchbase Lite test, does not know how to push a deletion yet CBG-4257")
325334
}
326-
peers, _ := setupTests(t, tc.topology, "")
335+
peers, _ := setupTests(t, tc.topology)
327336

328337
for peerName := range peers {
329338
docID := getDocID(t) + "_" + peerName
@@ -368,7 +377,7 @@ func TestHLVDeleteDocumentMultiActorConflict(t *testing.T) {
368377
t.Skip("We need to be able to wait for a specific version to arrive over pull replication + unexpected body in proposeChanges: [304] issue, CBG-4257")
369378
}
370379
t.Run(tc.description(), func(t *testing.T) {
371-
peers, replications := setupTests(t, tc.topology, "")
380+
peers, replications := setupTests(t, tc.topology)
372381
stopPeerReplications(replications)
373382

374383
docID := getDocID(t)
@@ -408,7 +417,7 @@ func TestHLVUpdateDeleteDocumentMultiActorConflict(t *testing.T) {
408417
}
409418
t.Run(tc.description(), func(t *testing.T) {
410419
peerList := tc.PeerNames()
411-
peers, replications := setupTests(t, tc.topology, "")
420+
peers, replications := setupTests(t, tc.topology)
412421
stopPeerReplications(replications)
413422

414423
docID := getDocID(t)
@@ -453,7 +462,7 @@ func TestHLVDeleteUpdateDocumentMultiActorConflict(t *testing.T) {
453462
}
454463
t.Run(tc.description(), func(t *testing.T) {
455464
peerList := tc.PeerNames()
456-
peers, replications := setupTests(t, tc.topology, "")
465+
peers, replications := setupTests(t, tc.topology)
457466
stopPeerReplications(replications)
458467

459468
docID := getDocID(t)
@@ -481,38 +490,43 @@ func TestHLVDeleteUpdateDocumentMultiActorConflict(t *testing.T) {
481490
func TestHLVResurrectDocumentSingleActor(t *testing.T) {
482491

483492
base.SetUpTestLogging(t, base.LevelDebug, base.KeyImport, base.KeyVV)
484-
for _, tc := range getSingleActorTestCase() {
485-
t.Run(tc.description(), func(t *testing.T) {
486-
if strings.HasPrefix(tc.activePeerID, "cbl") {
487-
t.Skip("Skipping Couchbase Lite test, does not know how to push a deletion yet CBG-4257")
488-
}
489-
t.Skip("Skipping resurection tests CBG-4366")
493+
for _, topology := range append(simpleTopologies, Topologies...) {
494+
t.Run(topology.description, func(t *testing.T) {
495+
peers, _ := setupTests(t, topology)
496+
for _, activePeerID := range topology.PeerNames() {
497+
t.Run(fmt.Sprintf("actor=%s", activePeerID), func(t *testing.T) {
498+
updatePeersT(t, peers)
499+
tc := singleActorTest{topology: topology, activePeerID: activePeerID}
500+
501+
if strings.HasPrefix(tc.activePeerID, "cbl") {
502+
t.Skip("Skipping Couchbase Lite test, does not know how to push a deletion yet CBG-4257")
503+
}
490504

491-
peers, _ := setupTests(t, tc.topology, tc.activePeerID)
505+
docID := getDocID(t)
506+
body1 := []byte(fmt.Sprintf(`{"peer": "%s", "topology": "%s", "write": 1}`, tc.activePeerID, tc.description()))
507+
createVersion := peers[tc.activePeerID].CreateDocument(tc.collectionName(), docID, body1)
508+
waitForVersionAndBody(t, tc, peers, docID, createVersion)
492509

493-
docID := getDocID(t)
494-
body1 := []byte(fmt.Sprintf(`{"peer": "%s", "topology": "%s", "write": 1}`, tc.activePeerID, tc.description()))
495-
createVersion := peers[tc.activePeerID].CreateDocument(tc.collectionName(), docID, body1)
496-
waitForVersionAndBody(t, tc, peers, docID, createVersion)
497-
498-
deleteVersion := peers[tc.activePeerID].DeleteDocument(tc.collectionName(), docID)
499-
t.Logf("createVersion: %+v, deleteVersion: %+v", createVersion, deleteVersion)
500-
t.Logf("waiting for document deletion on all peers")
501-
waitForDeletion(t, tc, peers, docID, tc.activePeerID)
502-
503-
body2 := []byte(fmt.Sprintf(`{"peer": "%s", "topology": "%s", "write": "resurrection"}`, tc.activePeerID, tc.description()))
504-
resurrectVersion := peers[tc.activePeerID].WriteDocument(tc.collectionName(), docID, body2)
505-
t.Logf("createVersion: %+v, deleteVersion: %+v, resurrectVersion: %+v", createVersion.docMeta, deleteVersion, resurrectVersion.docMeta)
506-
t.Logf("waiting for document resurrection on all peers")
507-
508-
// Couchbase Lite peers do not know how to push a deletion yet, so we need to filter them out CBG-4257
509-
nonCBLPeers := make(map[string]Peer)
510-
for peerName, peer := range peers {
511-
if !strings.HasPrefix(peerName, "cbl") {
512-
nonCBLPeers[peerName] = peer
513-
}
510+
deleteVersion := peers[tc.activePeerID].DeleteDocument(tc.collectionName(), docID)
511+
t.Logf("createVersion: %+v, deleteVersion: %+v", createVersion, deleteVersion)
512+
t.Logf("waiting for document deletion on all peers")
513+
waitForDeletion(t, tc, peers, docID, tc.activePeerID)
514+
515+
body2 := []byte(fmt.Sprintf(`{"peer": "%s", "topology": "%s", "write": "resurrection"}`, tc.activePeerID, tc.description()))
516+
resurrectVersion := peers[tc.activePeerID].WriteDocument(tc.collectionName(), docID, body2)
517+
t.Logf("createVersion: %+v, deleteVersion: %+v, resurrectVersion: %+v", createVersion.docMeta, deleteVersion, resurrectVersion.docMeta)
518+
t.Logf("waiting for document resurrection on all peers")
519+
520+
// Couchbase Lite peers do not know how to push a deletion yet, so we need to filter them out CBG-4257
521+
nonCBLPeers := make(map[string]Peer)
522+
for peerName, peer := range peers {
523+
if !strings.HasPrefix(peerName, "cbl") {
524+
nonCBLPeers[peerName] = peer
525+
}
526+
}
527+
waitForVersionAndBody(t, tc, peers, docID, resurrectVersion)
528+
})
514529
}
515-
waitForVersionAndBody(t, tc, peers, docID, resurrectVersion)
516530
})
517531
}
518532
}
@@ -524,9 +538,8 @@ func TestHLVResurrectDocumentMultiActor(t *testing.T) {
524538
if strings.Contains(tc.description(), "CBL") {
525539
t.Skip("Skipping Couchbase Lite test, does not know how to push a deletion yet CBG-4257")
526540
}
527-
t.Skip("skipped resurrection test, intermittent failures CBG-4372")
528541

529-
peers, _ := setupTests(t, tc.topology, "")
542+
peers, _ := setupTests(t, tc.topology)
530543

531544
var docVersionList []BodyAndVersion
532545
for _, peerName := range tc.PeerNames() {
@@ -578,7 +591,7 @@ func TestHLVResurrectDocumentMultiActorConflict(t *testing.T) {
578591
t.Skip("We need to be able to wait for a specific version to arrive over pull replication + unexpected body in proposeChanges: [304] issue, CBG-4257")
579592
}
580593
t.Run(tc.description(), func(t *testing.T) {
581-
peers, replications := setupTests(t, tc.topology, "")
594+
peers, replications := setupTests(t, tc.topology)
582595
stopPeerReplications(replications)
583596

584597
docID := getDocID(t)

topologytest/peer_test.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,17 @@ import (
2222
"github.com/stretchr/testify/require"
2323
)
2424

25-
const (
26-
totalWaitTime = 10 * time.Second
27-
pollInterval = 50 * time.Millisecond
28-
)
25+
// totalWaitTime is the time to wait for a document on a peer. This time is low for rosmar and high for Couchbase Server.
26+
var totalWaitTime = 3 * time.Second
27+
28+
// pollInterval is the time to poll to see if a document is updated on a peer
29+
var pollInterval = 50 * time.Millisecond
30+
31+
func init() {
32+
if !base.UnitTestUrlIsWalrus() {
33+
totalWaitTime = 40 * time.Second
34+
}
35+
}
2936

3037
// Peer represents a peer in an Mobile workflow. The types of Peers are Couchbase Server, Sync Gateway, or Couchbase Lite.
3138
type Peer interface {
@@ -70,6 +77,9 @@ type internalPeer interface {
7077
// TB returns the testing.TB for the peer.
7178
TB() testing.TB
7279

80+
// UpdateTB updates the testing.TB for the peer.
81+
UpdateTB(*testing.T)
82+
7383
// Context returns the context for the peer.
7484
Context() context.Context
7585
}
@@ -239,14 +249,19 @@ func createPeers(t *testing.T, peersOptions map[string]PeerOptions) map[string]P
239249
return peers
240250
}
241251

252+
func updatePeersT(t *testing.T, peers map[string]Peer) {
253+
for _, peer := range peers {
254+
oldTB := peer.TB().(*testing.T)
255+
t.Cleanup(func() { peer.UpdateTB(oldTB) })
256+
peer.UpdateTB(t)
257+
}
258+
}
259+
242260
// setupTests returns a map of peers and a list of replications. The peers will be closed and the buckets will be destroyed by t.Cleanup.
243-
func setupTests(t *testing.T, topology Topology, activePeerID string) (map[string]Peer, []PeerReplication) {
261+
func setupTests(t *testing.T, topology Topology) (map[string]Peer, []PeerReplication) {
244262
peers := createPeers(t, topology.peers)
245263
replications := createPeerReplications(t, peers, topology.replications)
246264

247-
if topology.skipIf != nil {
248-
topology.skipIf(t, activePeerID, peers)
249-
}
250265
for _, replication := range replications {
251266
// temporarily start the replication before writing the document, limitation of CouchbaseLiteMockPeer as active peer since WriteDocument is calls PushRev
252267
replication.Start()

0 commit comments

Comments
 (0)