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

Function startChanges

tools/cache_perf_tool/main.go:246–291  ·  view source on GitHub ↗
(ctx context.Context, t *testing.T, dbContext *db.DatabaseContext, clientChans int, numClients int, totalSystemChannels int)

Source from the content-addressed store, hash-verified

244}
245
246func startChanges(ctx context.Context, t *testing.T, dbContext *db.DatabaseContext, clientChans int, numClients int, totalSystemChannels int) {
247 mutationListener := dbContext.GetMutationListener(t)
248 chanIDList := make([]channels.ID, 0, clientChans)
249 chanCount := 0
250 var chanID channels.ID
251 for i := 0; i < numClients; i++ {
252 for j := 0; j < clientChans; j++ { // create clientChans number of channels for each change waiter
253 if chanCount == totalSystemChannels {
254 chanCount = 0 // reset channel count so we don't go over system channels count
255 }
256 chanID = channels.NewID("test-"+strconv.Itoa(chanCount), base.DefaultCollectionID)
257 chanIDList = append(chanIDList, chanID)
258 chanCount++
259 }
260 chans, err := channels.SetOf(chanIDList...)
261 if err != nil {
262 log.Printf("Error creating channel set: %v", err)
263 return
264 }
265 chanIDList = make([]channels.ID, 0, clientChans) // overwrite the list for next client
266 waiter := mutationListener.NewWaiterWithChannels(chans, nil, true)
267
268 go func(ctx context.Context, wait *db.ChangeWaiter, chanMap channels.Set) {
269 numGoroutines.Add(1)
270 defer numGoroutines.Add(-1)
271 for {
272 if ctx.Err() != nil {
273 return
274 }
275 num := wait.Wait(ctx)
276 if num == db.WaiterClosed {
277 return
278 } else if num == db.WaiterHasChanges {
279 // get cached changes for map, simulating changes feeds actually using the channel cache
280 for id := range chanMap {
281 _, err := dbContext.GetCachedChanges(t, ctx, id)
282 if err != nil {
283 log.Printf("Error getting cached changes: %v", err)
284 return
285 }
286 }
287 }
288 }
289 }(ctx, waiter, chans)
290 }
291}
292
293func printEndofTestStatsFile(ctx context.Context, dbContext *db.DatabaseContext) {
294 // Print the csv file to stdout

Callers 1

mainFunction · 0.85

Calls 8

NewIDFunction · 0.92
SetOfFunction · 0.92
GetMutationListenerMethod · 0.80
NewWaiterWithChannelsMethod · 0.80
ErrMethod · 0.80
GetCachedChangesMethod · 0.65
AddMethod · 0.45
WaitMethod · 0.45

Tested by

no test coverage detected