func (s *workerSuite) TestSupportsSpaceDiscoveryBroken(c *gc.C) { s.AssertConfigParameterUpdated(c, "broken", "SupportsSpaceDiscovery") newWorker, spacesDiscovered := discoverspaces.NewWorker(s.API) s.spacesDiscovered = spacesDiscovered err := worker.Stop(newWorker) c.Assert(err, gc.ErrorMatches, "dummy.SupportsSpaceDiscovery is broken") s.assertSpaceDiscoveryCompleted(c) }
func checkAlwaysInvalid(c *gc.C, config discoverspaces.Config, message string) { check := func(err error) { c.Check(err.Error(), gc.Equals, message) c.Check(err, jc.Satisfies, errors.IsNotValid) } err := config.Validate() check(err) worker, err := discoverspaces.NewWorker(config) c.Check(worker, gc.IsNil) check(err) }
func (s *WorkerSuite) startWorker(c *gc.C) (worker.Worker, gate.Lock) { // create fresh environ to see any injected broken-ness environ, err := stateenvirons.GetNewEnvironFunc(environs.New)(s.State) c.Assert(err, jc.ErrorIsNil) lock := gate.NewLock() worker, err := discoverspaces.NewWorker(discoverspaces.Config{ Facade: s.API, Environ: environ, NewName: network.ConvertSpaceName, Unlocker: lock, }) c.Assert(err, jc.ErrorIsNil) return worker, lock }
func (s *workerSuite) TestWorkerIdempotent(c *gc.C) { dummy.SetSupportsSpaceDiscovery(true) s.startWorker() var err error var spaces []*state.Space for a := common.ShortAttempt.Start(); a.Next(); { spaces, err = s.State.AllSpaces() if err != nil { break } if len(spaces) == 4 { // All spaces have been created. break } if !a.HasNext() { c.Fatalf("spaces not imported") } } c.Assert(err, jc.ErrorIsNil) newWorker, _ := discoverspaces.NewWorker(s.API) // This ensures that the worker can handle re-importing without error. defer func() { c.Assert(worker.Stop(newWorker), jc.ErrorIsNil) }() // Check that no extra spaces are imported. for a := common.ShortAttempt.Start(); a.Next(); { spaces, err = s.State.AllSpaces() if err != nil { break } if len(spaces) != 4 { c.Fatalf("unexpected number of spaces: %v", len(spaces)) } if !a.HasNext() { break } } }
func (s *workerSuite) startWorker() { s.Worker, s.spacesDiscovered = discoverspaces.NewWorker(s.API) }