Ejemplo n.º 1
0
// AssertUnlocked checks that the supplied Guest can Visit its fortress.
func AssertUnlocked(c *gc.C, guest fortress.Guest) {
	visited := make(chan error)
	go func() {
		visited <- guest.Visit(badVisit, nil)
	}()

	select {
	case err := <-visited:
		c.Assert(err, gc.ErrorMatches, "bad!")
	case <-time.After(coretesting.LongWait):
		c.Fatalf("abort never handled")
	}
}
Ejemplo n.º 2
0
// AssertUnlocked checks that the supplied Guest's Visit calls are blocked
// (and can be cancelled via Abort).
func AssertLocked(c *gc.C, guest fortress.Guest) {
	visited := make(chan error)
	abort := make(chan struct{})
	go func() {
		visited <- guest.Visit(badVisit, abort)
	}()

	// NOTE(fwereade): this isn't about interacting with a timer; it's about
	// making sure other goroutines have had ample opportunity to do stuff.
	delay := time.After(coretesting.ShortWait)
	for {
		select {
		case <-delay:
			delay = nil
			close(abort)
		case err := <-visited:
			c.Assert(err, gc.Equals, fortress.ErrAborted)
			return
		case <-time.After(coretesting.LongWait):
			c.Fatalf("timed out")
		}
	}
}