(t *testing.T)
| 285 | } |
| 286 | |
| 287 | func 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! |
nothing calls this directly
no test coverage detected
searching dependent graphs…