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

Function TestChangesViewBackfill

rest/changestest/changes_api_test.go:2203–2257  ·  view source on GitHub ↗

Tests view backfill and validates that results are prepended to cache

(t *testing.T)

Source from the content-addressed store, hash-verified

2201
2202// Tests view backfill and validates that results are prepended to cache
2203func TestChangesViewBackfill(t *testing.T) {
2204
2205 base.SetUpTestLogging(t, base.LevelInfo, base.KeyHTTP, base.KeyChanges, base.KeyCache)
2206
2207 rtConfig := rest.RestTesterConfig{SyncFn: `function(doc, oldDoc){channel(doc.channels);}`}
2208 rt := rest.NewRestTester(t, &rtConfig)
2209 defer rt.Close()
2210
2211 // Create user:
2212 ctx := rt.Context()
2213 a := rt.ServerContext().Database(ctx, "db").Authenticator(ctx)
2214 bernard, err := a.NewUser("bernard", "letmein", channels.BaseSetOf(t, "PBS", "ABC"))
2215 assert.NoError(t, err)
2216 assert.NoError(t, a.Save(bernard))
2217
2218 testDb := rt.ServerContext().Database(ctx, "db")
2219 cacheWaiter := testDb.NewDCPCachingCountWaiter(t)
2220
2221 // Put several documents
2222 response := rt.SendAdminRequest("PUT", "/{{.keyspace}}/doc1", `{"channels":["PBS"]}`)
2223 rest.RequireStatus(t, response, 201)
2224 response = rt.SendAdminRequest("PUT", "/{{.keyspace}}/doc2", `{"channels":["PBS"]}`)
2225 rest.RequireStatus(t, response, 201)
2226 response = rt.SendAdminRequest("PUT", "/{{.keyspace}}/doc3", `{"channels":["PBS"]}`)
2227 rest.RequireStatus(t, response, 201)
2228
2229 cacheWaiter.AddAndWait(3)
2230
2231 collection, ctx := rt.GetSingleTestDatabaseCollection()
2232 // Flush the channel cache
2233 assert.NoError(t, collection.FlushChannelCache(ctx))
2234
2235 // Add a few more docs (to increment the channel cache's validFrom)
2236 response = rt.SendAdminRequest("PUT", "/{{.keyspace}}/doc4", `{"channels":["PBS"]}`)
2237 rest.RequireStatus(t, response, 201)
2238
2239 response = rt.SendAdminRequest("PUT", "/{{.keyspace}}/doc5", `{"channels":["PBS"]}`)
2240 rest.RequireStatus(t, response, 201)
2241
2242 cacheWaiter.AddAndWait(2)
2243
2244 // Issue a since=0 changes request. Validate that there's a view-based backfill
2245 changesJSON := `{"since":0, "limit":50}`
2246 changes := rt.PostChanges("/{{.keyspace}}/_changes", changesJSON, "bernard")
2247 require.Len(t, changes.Results, 5)
2248 queryCount := testDb.DbStats.Cache().ViewQueries.Value()
2249 log.Printf("After initial changes request, query count is: %d", queryCount)
2250
2251 // Issue another since=0 changes request. Validate that there is not another a view-based backfill
2252 changes = rt.PostChanges("/{{.keyspace}}/_changes", changesJSON, "bernard")
2253 require.Len(t, changes.Results, 5)
2254 // Validate that there haven't been any more view queries
2255 assert.Equal(t, testDb.DbStats.Cache().ViewQueries.Value(), queryCount)
2256
2257}
2258
2259// Tests view backfill and validates that results are prepended to cache
2260func TestChangesViewBackfillStarChannel(t *testing.T) {

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
ContextMethod · 0.95
ServerContextMethod · 0.95
SendAdminRequestMethod · 0.95
PostChangesMethod · 0.95
SetUpTestLoggingFunction · 0.92
NewRestTesterFunction · 0.92
BaseSetOfFunction · 0.92
RequireStatusFunction · 0.92
NewUserMethod · 0.80
SaveMethod · 0.80

Tested by

no test coverage detected