MCPcopy
hub / github.com/hashicorp/go-memdb / TestWatchUpdate

Function TestWatchUpdate

integ_test.go:287–355  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

285}
286
287func TestWatchUpdate(t *testing.T) {
288 db := testComplexDB(t)
289 testPopulateData(t, db)
290 txn := db.Txn(false) // read only
291
292 watchSetIter := NewWatchSet()
293 watchSetSpecific := NewWatchSet()
294 watchSetPrefix := NewWatchSet()
295
296 // Get using an iterator.
297 iter, err := txn.Get("people", "name", "Armon", "Dadgar")
298 noErr(t, err)
299 watchSetIter.Add(iter.WatchCh())
300 if raw := iter.Next(); raw == nil {
301 t.Fatalf("should get person")
302 }
303
304 // Get using a full name.
305 watch, raw, err := txn.FirstWatch("people", "name", "Armon", "Dadgar")
306 noErr(t, err)
307 if raw == nil {
308 t.Fatalf("should get person")
309 }
310 watchSetSpecific.Add(watch)
311
312 // Get using a prefix.
313 watch, raw, err = txn.FirstWatch("people", "name_prefix", "Armon")
314 noErr(t, err)
315 if raw == nil {
316 t.Fatalf("should get person")
317 }
318 watchSetPrefix.Add(watch)
319
320 // Write to a snapshot.
321 snap := db.Snapshot()
322 txn2 := snap.Txn(true) // write
323 noErr(t, txn2.Delete("people", raw))
324 txn2.Commit()
325
326 // None of the watches should trigger since we didn't alter the
327 // primary.
328 wait := 100 * time.Millisecond
329 if timeout := watchSetIter.Watch(time.After(wait)); !timeout {
330 t.Fatalf("should timeout")
331 }
332 if timeout := watchSetSpecific.Watch(time.After(wait)); !timeout {
333 t.Fatalf("should timeout")
334 }
335 if timeout := watchSetPrefix.Watch(time.After(wait)); !timeout {
336 t.Fatalf("should timeout")
337 }
338
339 // Write to the primary.
340 txn3 := db.Txn(true) // write
341 noErr(t, txn3.Delete("people", raw))
342 txn3.Commit()
343
344 // All three watches should trigger!

Callers

nothing calls this directly

Calls 14

AddMethod · 0.95
WatchMethod · 0.95
testComplexDBFunction · 0.85
testPopulateDataFunction · 0.85
NewWatchSetFunction · 0.85
noErrFunction · 0.85
TxnMethod · 0.80
GetMethod · 0.80
FirstWatchMethod · 0.80
DeleteMethod · 0.80
CommitMethod · 0.80
WatchChMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…