OLD | NEW |
1 package watcher_test | 1 package watcher_test |
2 | 2 |
3 import ( | 3 import ( |
4 "labix.org/v2/mgo" | 4 "labix.org/v2/mgo" |
5 "labix.org/v2/mgo/txn" | 5 "labix.org/v2/mgo/txn" |
6 . "launchpad.net/gocheck" | 6 . "launchpad.net/gocheck" |
7 "launchpad.net/juju-core/log" | 7 "launchpad.net/juju-core/log" |
8 "launchpad.net/juju-core/mstate/watcher" | 8 "launchpad.net/juju-core/mstate/watcher" |
9 "launchpad.net/juju-core/testing" | 9 "launchpad.net/juju-core/testing" |
10 "launchpad.net/tomb" | 10 "launchpad.net/tomb" |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 c.Fatalf("not enough changes: got %d, want %d", len(seen
), N/2) | 433 c.Fatalf("not enough changes: got %d, want %d", len(seen
), N/2) |
434 } | 434 } |
435 } | 435 } |
436 c.Assert(len(seen), Equals, N/2) | 436 c.Assert(len(seen), Equals, N/2) |
437 assertNoChange(c, s.ch) | 437 assertNoChange(c, s.ch) |
438 } | 438 } |
439 | 439 |
440 func (s *WatcherSuite) TestStartSync(c *C) { | 440 func (s *WatcherSuite) TestStartSync(c *C) { |
441 s.w.Watch("test", "a", -1, s.ch) | 441 s.w.Watch("test", "a", -1, s.ch) |
442 | 442 |
443 // Nothing to do here. | |
444 s.w.StartSync() | |
445 | |
446 revno := s.insert(c, "test", "a") | 443 revno := s.insert(c, "test", "a") |
447 | 444 |
448 done := make(chan bool) | 445 done := make(chan bool) |
449 go func() { | 446 go func() { |
450 s.w.StartSync() | 447 s.w.StartSync() |
451 s.w.StartSync() | 448 s.w.StartSync() |
452 s.w.StartSync() | 449 s.w.StartSync() |
453 done <- true | 450 done <- true |
454 }() | 451 }() |
455 | 452 |
456 select { | 453 select { |
457 case <-done: | 454 case <-done: |
458 case <-time.After(100 * time.Millisecond): | 455 case <-time.After(100 * time.Millisecond): |
459 » » c.Fatalf("SyncStart failed to return") | 456 » » c.Fatalf("StartSync failed to return") |
460 } | 457 } |
461 | 458 |
462 assertChange(c, s.ch, watcher.Change{"test", "a", revno}) | 459 assertChange(c, s.ch, watcher.Change{"test", "a", revno}) |
463 } | 460 } |
464 | 461 |
465 func (s *WatcherSuite) TestSync(c *C) { | 462 func (s *WatcherSuite) TestSync(c *C) { |
466 s.w.Watch("test", "a", -1, s.ch) | 463 s.w.Watch("test", "a", -1, s.ch) |
467 | 464 |
468 // Nothing to do here. | 465 // Nothing to do here. |
469 s.w.Sync() | 466 s.w.Sync() |
470 | 467 |
471 revno := s.insert(c, "test", "a") | 468 revno := s.insert(c, "test", "a") |
472 | 469 |
473 done := make(chan bool) | 470 done := make(chan bool) |
474 go func() { | 471 go func() { |
475 s.w.Sync() | 472 s.w.Sync() |
476 done <- true | 473 done <- true |
477 }() | 474 }() |
478 | 475 |
479 select { | 476 select { |
480 case <-done: | 477 case <-done: |
481 c.Fatalf("Sync returned too early") | 478 c.Fatalf("Sync returned too early") |
482 » case <-time.After(500 * time.Millisecond): | 479 » case <-time.After(200 * time.Millisecond): |
483 } | 480 } |
484 | 481 |
485 assertChange(c, s.ch, watcher.Change{"test", "a", revno}) | 482 assertChange(c, s.ch, watcher.Change{"test", "a", revno}) |
486 | 483 |
487 select { | 484 select { |
488 case <-done: | 485 case <-done: |
489 case <-time.After(100 * time.Millisecond): | 486 case <-time.After(100 * time.Millisecond): |
490 c.Fatalf("Sync failed to returned") | 487 c.Fatalf("Sync failed to returned") |
491 } | 488 } |
492 } | 489 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 | 572 |
576 revno2 := s.insert(c, "test", "a") | 573 revno2 := s.insert(c, "test", "a") |
577 | 574 |
578 c.Assert(revno1, Equals, revno2) | 575 c.Assert(revno1, Equals, revno2) |
579 | 576 |
580 s.w.StartSync() | 577 s.w.StartSync() |
581 | 578 |
582 assertNoChange(c, chA1) | 579 assertNoChange(c, chA1) |
583 assertNoChange(c, chA) | 580 assertNoChange(c, chA) |
584 } | 581 } |
OLD | NEW |