diff --git a/db/hybrid_logical_vector.go b/db/hybrid_logical_vector.go index d6460e0056..d9479274c8 100644 --- a/db/hybrid_logical_vector.go +++ b/db/hybrid_logical_vector.go @@ -180,6 +180,32 @@ func NewHybridLogicalVector() *HybridLogicalVector { } } +func (hlv *HybridLogicalVector) Equals(other *HybridLogicalVector) bool { + if hlv.SourceID != other.SourceID { + return false + } + if hlv.Version != other.Version { + return false + } + if len(hlv.PreviousVersions) != len(other.PreviousVersions) { + return false + } + for k, v := range hlv.PreviousVersions { + if other.PreviousVersions[k] != v { + return false + } + } + if len(hlv.MergeVersions) != len(other.MergeVersions) { + return false + } + for k, v := range hlv.MergeVersions { + if other.MergeVersions[k] != v { + return false + } + } + return true +} + // GetCurrentVersion returns the current version from the HLV in memory. func (hlv *HybridLogicalVector) GetCurrentVersion() (string, uint64) { return hlv.SourceID, hlv.Version diff --git a/topologytest/couchbase_lite_mock_peer_test.go b/topologytest/couchbase_lite_mock_peer_test.go index 22aea4ef57..10bb03ddcc 100644 --- a/topologytest/couchbase_lite_mock_peer_test.go +++ b/topologytest/couchbase_lite_mock_peer_test.go @@ -11,6 +11,7 @@ package topologytest import ( "context" "fmt" + "log" "testing" sgbucket "github.com/couchbase/sg-bucket" @@ -135,6 +136,10 @@ func (p *CouchbaseLiteMockPeer) WaitForDocVersion(dsName sgbucket.DataStoreName, if !assert.NotNil(c, actual, "Could not find docID:%+v on %p\nVersion %#v", docID, p, expected) { return } + if !actual.IsHLVEqual(expected) { + log.Printf("not equal") + } + assert.True(c, actual.IsHLVEqual(expected), "Actual HLV does not match expected on %s for peer %s. Expected: %+v, Actual: %+v", docID, p, expected.HLV, actual.HLV) assert.Equal(c, expected.CV(c), actual.CV(c), "Could not find matching CV on %s for peer %s (sourceID:%s)\nexpected: %#v\nactual: %#v\n body: %+v\n", docID, p, p.SourceID(), expected, actual, string(data)) }, totalWaitTime, pollInterval) diff --git a/topologytest/couchbase_server_peer_test.go b/topologytest/couchbase_server_peer_test.go index a1a5b8d085..fb71315d70 100644 --- a/topologytest/couchbase_server_peer_test.go +++ b/topologytest/couchbase_server_peer_test.go @@ -183,7 +183,7 @@ func (p *CouchbaseServerPeer) waitForDocVersion(dsName sgbucket.DataStoreName, d } // have to use p.tb instead of c because of the assert.CollectT doesn't implement TB version = getDocVersion(docID, p, cas, xattrs) - + assert.True(c, version.IsHLVEqual(expected), "Actual HLV does not match expected on %s for peer %s. Expected: %+v, Actual: %+v", docID, p, expected, version) assert.Equal(c, expected.CV(c), version.CV(c), "Could not find matching CV on %s for peer %s\nexpected: %#v\nactual: %#v\n body: %#v\n", docID, p, expected, version, string(docBytes)) }, totalWaitTime, pollInterval) diff --git a/topologytest/version_test.go b/topologytest/version_test.go index 520f7d869d..b8acdebf26 100644 --- a/topologytest/version_test.go +++ b/topologytest/version_test.go @@ -38,6 +38,27 @@ func (v DocMetadata) CV(t require.TestingT) db.Version { return db.Version{} } +func (v DocMetadata) IsHLVEqual(other DocMetadata) bool { + if v.ImplicitHLV != nil { + return other.hlvEquals(v.ImplicitHLV) + } else if v.HLV != nil { + return other.hlvEquals(v.HLV) + } else { + return other.ImplicitHLV == nil && other.HLV == nil + } +} + +func (v DocMetadata) hlvEquals(hlv *db.HybridLogicalVector) bool { + if v.ImplicitHLV != nil { + return v.ImplicitHLV.Equals(hlv) + } else if v.HLV != nil { + return v.HLV.Equals(hlv) + } else { + return hlv == nil + } + +} + // DocMetadataFromDocument returns a DocVersion from the given document. func DocMetadataFromDocument(doc *db.Document) DocMetadata { return DocMetadata{