MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestWriteTombstonedDocUsingXattrs

Function TestWriteTombstonedDocUsingXattrs

rest/api_test.go:1737–1790  ·  view source on GitHub ↗

Repro attempt for SG #3307. Before fix for #3307, fails when SG_TEST_USE_XATTRS=true and run against an actual couchbase server

(t *testing.T)

Source from the content-addressed store, hash-verified

1735
1736// Repro attempt for SG #3307. Before fix for #3307, fails when SG_TEST_USE_XATTRS=true and run against an actual couchbase server
1737func TestWriteTombstonedDocUsingXattrs(t *testing.T) {
1738
1739 if !base.TestUseXattrs() {
1740 t.Skip("XATTR based tests not enabled. Enable via SG_TEST_USE_XATTRS=true environment variable")
1741 }
1742
1743 // This doesn't need to specify XATTR's because that is controlled by the test
1744 // env variable: SG_TEST_USE_XATTRS
1745 rt := NewRestTester(t, nil)
1746 defer rt.Close()
1747
1748 bulkDocsBody := `
1749{
1750 "docs": [
1751 {
1752 "_id":"-21SK00U-ujxUO9fU2HezxL",
1753 "_rev":"2-466a1fab90a810dc0a63565b70680e4e",
1754 "_deleted":true,
1755 "_revisions":{
1756 "ids":[
1757 "466a1fab90a810dc0a63565b70680e4e",
1758 "9e1084304cd2e60c5c106b308a82f40e"
1759 ],
1760 "start":2
1761 }
1762 }
1763 ],
1764 "new_edits": false
1765}
1766`
1767
1768 response := rt.SendAdminRequest("POST", "/{{.keyspace}}/_bulk_docs", bulkDocsBody)
1769 log.Printf("Response: %s", response.Body)
1770
1771 bulkDocsResponse := []map[string]interface{}{}
1772 err := base.JSONUnmarshal(response.Body.Bytes(), &bulkDocsResponse)
1773 assert.NoError(t, err, "Unexpected error")
1774 log.Printf("bulkDocsResponse: %+v", bulkDocsResponse)
1775 for _, bulkDocResponse := range bulkDocsResponse {
1776 bulkDocErr, gotErr := bulkDocResponse["error"]
1777 if gotErr && bulkDocErr.(string) == "not_found" {
1778 t.Errorf("The bulk docs response had an embedded error: %v. Response for this doc: %+v", bulkDocErr, bulkDocsResponse)
1779 }
1780 }
1781
1782 // Fetch the xattr and make sure it contains the above value
1783 xattrs, _, err := rt.GetSingleDataStore().GetXattrs(rt.Context(), "-21SK00U-ujxUO9fU2HezxL", []string{base.SyncXattrName})
1784 require.NoError(t, err)
1785 require.Contains(t, xattrs, base.SyncXattrName)
1786 var retrievedSyncData db.SyncData
1787 require.NoError(t, base.JSONUnmarshal(xattrs[base.SyncXattrName], &retrievedSyncData))
1788 assert.Equal(t, "2-466a1fab90a810dc0a63565b70680e4e", retrievedSyncData.GetRevTreeID())
1789
1790}
1791
1792// Reproduces https://github.com/couchbase/sync_gateway/issues/916. The test-only RestartListener operation used to simulate a
1793// SG restart isn't race-safe, so disabling the test for now. Should be possible to reinstate this as a proper unit test

Callers

nothing calls this directly

Calls 12

CloseMethod · 0.95
SendAdminRequestMethod · 0.95
GetSingleDataStoreMethod · 0.95
ContextMethod · 0.95
GetRevTreeIDMethod · 0.95
TestUseXattrsFunction · 0.92
JSONUnmarshalFunction · 0.92
NewRestTesterFunction · 0.85
ErrorfMethod · 0.80
ContainsMethod · 0.65
GetXattrsMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected