Ejemplo n.º 1
0
func (s *workerJujuConnSuite) TestPublisherSetsAPIHostPorts(c *gc.C) {
	peergrouper.DoTestForIPv4AndIPv6(func(ipVersion peergrouper.TestIPVersion) {
		st := peergrouper.NewFakeState()
		peergrouper.InitState(c, st, 3, ipVersion)

		publishedAPIServers := make(chan [][]network.HostPort, 1)
		publish := func(apiServers [][]network.HostPort, instanceIds []instance.Id) error {
			publishedAPIServers <- apiServers
			return nil
		}

		w := peergrouper.NewWorker(st, peergrouper.PublisherFunc(publish))
		defer func() {
			c.Check(worker.Stop(w), gc.IsNil)
		}()

		select {
		case hps := <-publishedAPIServers:
			peergrouper.AssertAPIHostPorts(c, hps, peergrouper.ExpectedAPIHostPorts(3, ipVersion))
		case <-time.After(testing.LongWait):
			c.Fatalf("timed out waiting for API server host-ports to be published")
		}

		// There should be only one publication.
		select {
		case <-publishedAPIServers:
			c.Fatalf("unexpected API server host-ports publication")
		case <-time.After(testing.ShortWait):
		}
	})
}
Ejemplo n.º 2
0
func (s *workerJujuConnSuite) TestStartStop(c *gc.C) {
	st := peergrouper.NewFakeState()
	publish := func(apiServers [][]network.HostPort, instanceIds []instance.Id) error {
		return nil
	}
	w := peergrouper.NewWorker(st, peergrouper.PublisherFunc(publish))
	err := worker.Stop(w)
	c.Assert(err, jc.ErrorIsNil)
}