@@ -50,53 +50,43 @@ func stripInternalProperties(body db.Body) {
50
50
}
51
51
52
52
// waitForVersionAndBody waits for a document to reach a specific version on all peers.
53
- func waitForVersionAndBody (t * testing.T , dsName base.ScopeAndCollectionName , peers Peers , replications Replications , docID string , expectedVersion BodyAndVersion ) {
53
+ func waitForVersionAndBody (t * testing.T , dsName base.ScopeAndCollectionName , docID string , expectedVersion BodyAndVersion , topology Topology ) {
54
54
t .Logf ("waiting for doc version on all peers, written from %s: %#v" , expectedVersion .updatePeer , expectedVersion )
55
- for _ , peer := range peers .SortedPeers () {
55
+ for _ , peer := range topology .SortedPeers () {
56
56
t .Logf ("waiting for doc version on peer %s, written from %s: %#v" , peer , expectedVersion .updatePeer , expectedVersion )
57
- body := peer .WaitForDocVersion (dsName , docID , expectedVersion .docMeta , replications )
57
+ body := peer .WaitForDocVersion (dsName , docID , expectedVersion .docMeta , topology )
58
58
requireBodyEqual (t , expectedVersion .body , body )
59
59
}
60
60
}
61
61
62
- func waitForTombstoneVersion (t * testing.T , dsName base.ScopeAndCollectionName , peers Peers , replications Replications , docID string , expectedVersion BodyAndVersion ) {
63
- t .Logf ("waiting for tombstone version on all peers, written from %s: %#v" , expectedVersion .updatePeer , expectedVersion )
64
- for _ , peer := range peers .SortedPeers () {
65
- t .Logf ("waiting for tombstone version on peer %s, written from %s: %#v" , peer , expectedVersion .updatePeer , expectedVersion )
66
- peer .WaitForTombstoneVersion (dsName , docID , expectedVersion .docMeta , replications )
62
+ // waitForCVAndBody waits for a document to reach a specific cv on all peers.
63
+ func waitForCVAndBody (t * testing.T , dsName base.ScopeAndCollectionName , docID string , expectedVersion BodyAndVersion , topology Topology ) {
64
+ t .Logf ("waiting for doc version on all peers, written from %s: %#v" , expectedVersion .updatePeer , expectedVersion )
65
+ for _ , peer := range topology .SortedPeers () {
66
+ t .Logf ("waiting for doc version on peer %s, written from %s: %#v" , peer , expectedVersion .updatePeer , expectedVersion )
67
+ body := peer .WaitForCV (dsName , docID , expectedVersion .docMeta , topology )
68
+ requireBodyEqual (t , expectedVersion .body , body )
67
69
}
68
70
}
69
-
70
- // removeSyncGatewayBackingPeers will check if there is sync gateway in topology, if so will track the backing CBS
71
- // so we can skip creating docs on these peers (avoiding conflicts between docs created on the SGW and cbs)
72
- func removeSyncGatewayBackingPeers (peers map [string ]Peer ) map [string ]bool {
73
- peersToRemove := make (map [string ]bool )
74
- if peers ["sg1" ] != nil {
75
- // remove the backing store from doc update cycle to avoid conflicts on creating the document in bucket
76
- peersToRemove ["cbs1" ] = true
77
- }
78
- if peers ["sg2" ] != nil {
79
- // remove the backing store from doc update cycle to avoid conflicts on creating the document in bucket
80
- peersToRemove ["cbs2" ] = true
71
+ func waitForTombstoneVersion (t * testing.T , dsName base.ScopeAndCollectionName , docID string , expectedVersion BodyAndVersion , topology Topology ) {
72
+ t .Logf ("waiting for tombstone version on all peers, written from %s: %#v" , expectedVersion .updatePeer , expectedVersion )
73
+ for _ , peer := range topology .SortedPeers () {
74
+ t .Logf ("waiting for tombstone version on peer %s, written from %s: %#v" , peer , expectedVersion .updatePeer , expectedVersion )
75
+ peer .WaitForTombstoneVersion (dsName , docID , expectedVersion .docMeta , topology )
81
76
}
82
- return peersToRemove
83
77
}
84
78
85
79
// createConflictingDocs will create a doc on each peer of the same doc ID to create conflicting documents, then
86
80
// returns the last peer to have a doc created on it
87
- func createConflictingDocs (t * testing.T , dsName base.ScopeAndCollectionName , peers Peers , docID , topologyDescription string ) (lastWrite BodyAndVersion ) {
88
- backingPeers := removeSyncGatewayBackingPeers (peers )
89
- documentVersion := make ([]BodyAndVersion , 0 , len (peers ))
90
- for peerName , peer := range peers {
91
- if backingPeers [peerName ] {
92
- continue
93
- }
81
+ func createConflictingDocs (t * testing.T , dsName base.ScopeAndCollectionName , docID string , topology Topology ) (lastWrite BodyAndVersion ) {
82
+ var documentVersion []BodyAndVersion
83
+ for peerName , peer := range topology .peers .NonImportSortedPeers () {
94
84
if peer .Type () == PeerTypeCouchbaseLite {
95
85
// FIXME: Skipping Couchbase Lite tests for multi actor conflicts, CBG-4434
96
86
continue
97
87
}
98
- docBody := [] byte ( fmt .Sprintf (`{"activePeer": "%s", "topology": "%s", "action": "create"}` , peerName , topologyDescription ) )
99
- docVersion := peer .CreateDocument (dsName , docID , docBody )
88
+ docBody := fmt .Sprintf (`{"activePeer": "%s", "topology": "%s", "action": "create"}` , peerName , topology . specDescription )
89
+ docVersion := peer .CreateDocument (dsName , docID , [] byte ( docBody ) )
100
90
t .Logf ("%s - createVersion: %#v" , peerName , docVersion .docMeta )
101
91
documentVersion = append (documentVersion , docVersion )
102
92
}
@@ -108,15 +98,11 @@ func createConflictingDocs(t *testing.T, dsName base.ScopeAndCollectionName, pee
108
98
109
99
// updateConflictingDocs will update a doc on each peer of the same doc ID to create conflicting document mutations, then
110
100
// returns the last peer to have a doc updated on it.
111
- func updateConflictingDocs (t * testing.T , dsName base.ScopeAndCollectionName , peers Peers , docID , topologyDescription string ) (lastWrite BodyAndVersion ) {
112
- backingPeers := removeSyncGatewayBackingPeers (peers )
101
+ func updateConflictingDocs (t * testing.T , dsName base.ScopeAndCollectionName , docID string , topology Topology ) (lastWrite BodyAndVersion ) {
113
102
var documentVersion []BodyAndVersion
114
- for peerName , peer := range peers {
115
- if backingPeers [peerName ] {
116
- continue
117
- }
118
- docBody := []byte (fmt .Sprintf (`{"activePeer": "%s", "topology": "%s", "action": "update"}` , peerName , topologyDescription ))
119
- docVersion := peer .WriteDocument (dsName , docID , docBody )
103
+ for peerName , peer := range topology .peers .NonImportSortedPeers () {
104
+ docBody := fmt .Sprintf (`{"activePeer": "%s", "topology": "%s", "action": "update"}` , peerName , topology .specDescription )
105
+ docVersion := peer .WriteDocument (dsName , docID , []byte (docBody ))
120
106
t .Logf ("updateVersion: %#v" , docVersion .docMeta )
121
107
documentVersion = append (documentVersion , docVersion )
122
108
}
@@ -128,13 +114,9 @@ func updateConflictingDocs(t *testing.T, dsName base.ScopeAndCollectionName, pee
128
114
129
115
// deleteConflictDocs will delete a doc on each peer of the same doc ID to create conflicting document deletions, then
130
116
// returns the last peer to have a doc deleted on it
131
- func deleteConflictDocs (t * testing.T , dsName base.ScopeAndCollectionName , peers Peers , docID string ) (lastWrite BodyAndVersion ) {
132
- backingPeers := removeSyncGatewayBackingPeers (peers )
117
+ func deleteConflictDocs (t * testing.T , dsName base.ScopeAndCollectionName , docID string , topology Topology ) (lastWrite BodyAndVersion ) {
133
118
var documentVersion []BodyAndVersion
134
- for peerName , peer := range peers {
135
- if backingPeers [peerName ] {
136
- continue
137
- }
119
+ for peerName , peer := range topology .peers .NonImportSortedPeers () {
138
120
deleteVersion := peer .DeleteDocument (dsName , docID )
139
121
t .Logf ("deleteVersion: %#v" , deleteVersion )
140
122
documentVersion = append (documentVersion , BodyAndVersion {docMeta : deleteVersion , updatePeer : peerName })
0 commit comments