本文整理汇总了Golang中github.com/wallyworld/core/state/testing.AssertStop函数的典型用法代码示例。如果您正苦于以下问题:Golang AssertStop函数的具体用法?Golang AssertStop怎么用?Golang AssertStop使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了AssertStop函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestWatchRelations
func (s *serviceSuite) TestWatchRelations(c *gc.C) {
w, err := s.apiService.WatchRelations()
c.Assert(err, gc.IsNil)
defer statetesting.AssertStop(c, w)
wc := statetesting.NewStringsWatcherC(c, s.BackingState, w)
// Initial event.
wc.AssertChange()
wc.AssertNoChange()
// Change something other than the lifecycle and make sure it's
// not detected.
err = s.wordpressService.SetExposed()
c.Assert(err, gc.IsNil)
wc.AssertNoChange()
// Add another service and relate it to wordpress,
// check it's detected.
s.addMachineServiceCharmAndUnit(c, "mysql")
rel := s.addRelation(c, "wordpress", "mysql")
wc.AssertChange(rel.String())
// Destroy the relation and check it's detected.
err = rel.Destroy()
c.Assert(err, gc.IsNil)
wc.AssertChange(rel.String())
wc.AssertNoChange()
statetesting.AssertStop(c, w)
wc.AssertClosed()
}
示例2: TestWatchUnit
func (s *UnitSuite) TestWatchUnit(c *gc.C) {
preventUnitDestroyRemove(c, s.unit)
w := s.unit.Watch()
defer testing.AssertStop(c, w)
// Initial event.
wc := testing.NewNotifyWatcherC(c, s.State, w)
wc.AssertOneChange()
// Make one change (to a separate instance), check one event.
unit, err := s.State.Unit(s.unit.Name())
c.Assert(err, gc.IsNil)
s.setAssignedMachineAddresses(c, unit)
wc.AssertOneChange()
// Make two changes, check one event.
err = unit.SetPassword("arble-farble-dying-yarble")
c.Assert(err, gc.IsNil)
err = unit.Destroy()
c.Assert(err, gc.IsNil)
wc.AssertOneChange()
// Stop, check closed.
testing.AssertStop(c, w)
wc.AssertClosed()
// Remove unit, start new watch, check single event.
err = unit.EnsureDead()
c.Assert(err, gc.IsNil)
err = unit.Remove()
c.Assert(err, gc.IsNil)
w = s.unit.Watch()
defer testing.AssertStop(c, w)
testing.NewNotifyWatcherC(c, s.State, w).AssertOneChange()
}
示例3: TestWatchAPIHostPorts
func (s *APIAddresserTests) TestWatchAPIHostPorts(c *gc.C) {
expectServerAddrs := [][]instance.HostPort{{{
Address: instance.NewAddress("0.1.2.3", instance.NetworkUnknown),
Port: 1234,
}}}
err := s.state.SetAPIHostPorts(expectServerAddrs)
c.Assert(err, gc.IsNil)
w, err := s.facade.WatchAPIHostPorts()
c.Assert(err, gc.IsNil)
defer statetesting.AssertStop(c, w)
wc := statetesting.NewNotifyWatcherC(c, s.state, w)
// Initial event.
wc.AssertOneChange()
// Change the state addresses and check that we get a notification
expectServerAddrs[0][0].Value = "0.1.99.99"
err = s.state.SetAPIHostPorts(expectServerAddrs)
c.Assert(err, gc.IsNil)
wc.AssertOneChange()
statetesting.AssertStop(c, w)
wc.AssertClosed()
}
示例4: TestWatchUnits
func (s *machineSuite) TestWatchUnits(c *gc.C) {
w, err := s.apiMachine.WatchUnits()
c.Assert(err, gc.IsNil)
defer statetesting.AssertStop(c, w)
wc := statetesting.NewStringsWatcherC(c, s.BackingState, w)
// Initial event.
wc.AssertChange("wordpress/0")
wc.AssertNoChange()
// Change something other than the life cycle and make sure it's
// not detected.
err = s.machines[0].SetPassword("foo")
c.Assert(err, gc.ErrorMatches, "password is only 3 bytes long, and is not a valid Agent password")
wc.AssertNoChange()
err = s.machines[0].SetPassword("foo-12345678901234567890")
c.Assert(err, gc.IsNil)
wc.AssertNoChange()
// Unassign unit 0 from the machine and check it's detected.
err = s.units[0].UnassignFromMachine()
c.Assert(err, gc.IsNil)
wc.AssertChange("wordpress/0")
wc.AssertNoChange()
statetesting.AssertStop(c, w)
wc.AssertClosed()
}
示例5: TestWatchUnits
func (s *deployerSuite) TestWatchUnits(c *gc.C) {
machine, err := s.st.Machine(s.machine.Tag())
c.Assert(err, gc.IsNil)
w, err := machine.WatchUnits()
c.Assert(err, gc.IsNil)
defer statetesting.AssertStop(c, w)
wc := statetesting.NewStringsWatcherC(c, s.BackingState, w)
// Initial event.
wc.AssertChange("mysql/0", "logging/0")
wc.AssertNoChange()
// Change something other than the lifecycle and make sure it's
// not detected.
err = s.subordinate.SetPassword("foo")
c.Assert(err, gc.ErrorMatches, "password is only 3 bytes long, and is not a valid Agent password")
wc.AssertNoChange()
err = s.subordinate.SetPassword("foo-12345678901234567890")
c.Assert(err, gc.IsNil)
wc.AssertNoChange()
// Make the subordinate dead and check it's detected.
err = s.subordinate.EnsureDead()
c.Assert(err, gc.IsNil)
wc.AssertChange("logging/0")
wc.AssertNoChange()
statetesting.AssertStop(c, w)
wc.AssertClosed()
}
示例6: TestWatchService
func (s *ServiceSuite) TestWatchService(c *gc.C) {
w := s.mysql.Watch()
defer testing.AssertStop(c, w)
// Initial event.
wc := testing.NewNotifyWatcherC(c, s.State, w)
wc.AssertOneChange()
// Make one change (to a separate instance), check one event.
service, err := s.State.Service(s.mysql.Name())
c.Assert(err, gc.IsNil)
err = service.SetExposed()
c.Assert(err, gc.IsNil)
wc.AssertOneChange()
// Make two changes, check one event.
err = service.ClearExposed()
c.Assert(err, gc.IsNil)
err = service.SetCharm(s.charm, true)
c.Assert(err, gc.IsNil)
wc.AssertOneChange()
// Stop, check closed.
testing.AssertStop(c, w)
wc.AssertClosed()
// Remove service, start new watch, check single event.
err = service.Destroy()
c.Assert(err, gc.IsNil)
w = s.mysql.Watch()
defer testing.AssertStop(c, w)
testing.NewNotifyWatcherC(c, s.State, w).AssertOneChange()
}
示例7: TestWatch
func (s *unitSuite) TestWatch(c *gc.C) {
c.Assert(s.apiUnit.Life(), gc.Equals, params.Alive)
w, err := s.apiUnit.Watch()
c.Assert(err, gc.IsNil)
defer statetesting.AssertStop(c, w)
wc := statetesting.NewNotifyWatcherC(c, s.BackingState, w)
// Initial event.
wc.AssertOneChange()
// Change something other than the life cycle and make sure it's
// not detected.
err = s.units[0].SetStatus(params.StatusStarted, "not really", nil)
c.Assert(err, gc.IsNil)
wc.AssertNoChange()
// Make the unit dead and check it's detected.
err = s.units[0].EnsureDead()
c.Assert(err, gc.IsNil)
wc.AssertOneChange()
statetesting.AssertStop(c, w)
wc.AssertClosed()
}
示例8: TestPeerWatchScope
func (s *RelationUnitSuite) TestPeerWatchScope(c *gc.C) {
pr := NewPeerRelation(c, s.State)
// Test empty initial event.
w0 := pr.ru0.WatchScope()
defer testing.AssertStop(c, w0)
s.assertScopeChange(c, w0, nil, nil)
s.assertNoScopeChange(c, w0)
// ru0 enters; check no change, but settings written.
assertNotInScope(c, pr.ru0)
err := pr.ru0.EnterScope(map[string]interface{}{"foo": "bar"})
c.Assert(err, gc.IsNil)
s.assertNoScopeChange(c, w0)
node, err := pr.ru0.Settings()
c.Assert(err, gc.IsNil)
c.Assert(node.Map(), gc.DeepEquals, map[string]interface{}{"foo": "bar"})
assertInScope(c, pr.ru0)
// ru1 enters; check change is observed.
assertNotInScope(c, pr.ru1)
err = pr.ru1.EnterScope(nil)
c.Assert(err, gc.IsNil)
s.assertScopeChange(c, w0, []string{"riak/1"}, nil)
s.assertNoScopeChange(c, w0)
assertInScope(c, pr.ru1)
// ru1 enters again, check no problems and no changes.
err = pr.ru1.EnterScope(nil)
c.Assert(err, gc.IsNil)
s.assertNoScopeChange(c, w0)
assertInScope(c, pr.ru1)
// Stop watching; ru2 enters.
testing.AssertStop(c, w0)
assertNotInScope(c, pr.ru2)
err = pr.ru2.EnterScope(nil)
c.Assert(err, gc.IsNil)
assertInScope(c, pr.ru2)
// Start watch again, check initial event.
w0 = pr.ru0.WatchScope()
defer testing.AssertStop(c, w0)
s.assertScopeChange(c, w0, []string{"riak/1", "riak/2"}, nil)
s.assertNoScopeChange(c, w0)
// ru1 leaves; check event.
assertInScope(c, pr.ru1)
err = pr.ru1.LeaveScope()
c.Assert(err, gc.IsNil)
s.assertScopeChange(c, w0, nil, []string{"riak/1"})
s.assertNoScopeChange(c, w0)
assertNotInScope(c, pr.ru1)
// ru1 leaves again; check no problems and no changes.
err = pr.ru1.LeaveScope()
c.Assert(err, gc.IsNil)
s.assertNoScopeChange(c, w0)
assertNotInScope(c, pr.ru1)
}
示例9: TestWatchEnvironMachines
func (s *provisionerSuite) TestWatchEnvironMachines(c *gc.C) {
w, err := s.provisioner.WatchEnvironMachines()
c.Assert(err, gc.IsNil)
defer statetesting.AssertStop(c, w)
wc := statetesting.NewStringsWatcherC(c, s.BackingState, w)
// Initial event.
wc.AssertChange(s.machine.Id())
// Add another 2 machines make sure they are detected.
otherMachine, err := s.State.AddMachine("quantal", state.JobHostUnits)
c.Assert(err, gc.IsNil)
otherMachine, err = s.State.AddMachine("quantal", state.JobHostUnits)
c.Assert(err, gc.IsNil)
wc.AssertChange("1", "2")
// Change the lifecycle of last machine.
err = otherMachine.EnsureDead()
c.Assert(err, gc.IsNil)
wc.AssertChange("2")
// Add a container and make sure it's not detected.
template := state.MachineTemplate{
Series: "quantal",
Jobs: []state.MachineJob{state.JobHostUnits},
}
_, err = s.State.AddMachineInsideMachine(template, s.machine.Id(), instance.LXC)
c.Assert(err, gc.IsNil)
wc.AssertNoChange()
statetesting.AssertStop(c, w)
wc.AssertClosed()
}
示例10: TestWatchMachineErrorRetry
func (s *withoutStateServerSuite) TestWatchMachineErrorRetry(c *gc.C) {
s.PatchValue(&provisioner.ErrorRetryWaitDelay, 2*coretesting.ShortWait)
c.Assert(s.resources.Count(), gc.Equals, 0)
_, err := s.provisioner.WatchMachineErrorRetry()
c.Assert(err, gc.IsNil)
// Verify the resources were registered and stop them when done.
c.Assert(s.resources.Count(), gc.Equals, 1)
resource := s.resources.Get("1")
defer statetesting.AssertStop(c, resource)
// Check that the Watch has consumed the initial event ("returned"
// in the Watch call)
wc := statetesting.NewNotifyWatcherC(c, s.State, resource.(state.NotifyWatcher))
wc.AssertNoChange()
// We should now get a time triggered change.
wc.AssertOneChange()
// Make sure WatchMachineErrorRetry fails with a machine agent login.
anAuthorizer := s.authorizer
anAuthorizer.MachineAgent = true
anAuthorizer.EnvironManager = false
aProvisioner, err := provisioner.NewProvisionerAPI(s.State, s.resources, anAuthorizer)
c.Assert(err, gc.IsNil)
result, err := aProvisioner.WatchMachineErrorRetry()
c.Assert(err, gc.ErrorMatches, "permission denied")
c.Assert(result, gc.DeepEquals, params.NotifyWatchResult{})
}
示例11: TestServiceDeath
func (s *FilterSuite) TestServiceDeath(c *gc.C) {
f, err := newFilter(s.uniter, s.unit.Tag())
c.Assert(err, gc.IsNil)
defer statetesting.AssertStop(c, f)
dyingAsserter := coretesting.NotifyAsserterC{
C: c,
Precond: func() { s.BackingState.StartSync() },
Chan: f.UnitDying(),
}
dyingAsserter.AssertNoReceive()
err = s.unit.SetStatus(params.StatusStarted, "", nil)
c.Assert(err, gc.IsNil)
err = s.wordpress.Destroy()
c.Assert(err, gc.IsNil)
timeout := time.After(coretesting.LongWait)
loop:
for {
select {
case <-f.UnitDying():
break loop
case <-time.After(coretesting.ShortWait):
s.BackingState.StartSync()
case <-timeout:
c.Fatalf("dead not detected")
}
}
err = s.unit.Refresh()
c.Assert(err, gc.IsNil)
c.Assert(s.unit.Life(), gc.Equals, state.Dying)
// Can't set s.wordpress to Dead while it still has units.
}
示例12: TestWatchConfigSettings
func (s *uniterSuite) TestWatchConfigSettings(c *gc.C) {
err := s.wordpressUnit.SetCharmURL(s.wpCharm.URL())
c.Assert(err, gc.IsNil)
c.Assert(s.resources.Count(), gc.Equals, 0)
args := params.Entities{Entities: []params.Entity{
{Tag: "unit-mysql-0"},
{Tag: "unit-wordpress-0"},
{Tag: "unit-foo-42"},
}}
result, err := s.uniter.WatchConfigSettings(args)
c.Assert(err, gc.IsNil)
c.Assert(result, gc.DeepEquals, params.NotifyWatchResults{
Results: []params.NotifyWatchResult{
{Error: apiservertesting.ErrUnauthorized},
{NotifyWatcherId: "1"},
{Error: apiservertesting.ErrUnauthorized},
},
})
// Verify the resource was registered and stop when done
c.Assert(s.resources.Count(), gc.Equals, 1)
resource := s.resources.Get("1")
defer statetesting.AssertStop(c, resource)
// Check that the Watch has consumed the initial event ("returned" in
// the Watch call)
wc := statetesting.NewNotifyWatcherC(c, s.State, resource.(state.NotifyWatcher))
wc.AssertNoChange()
}
示例13: TestWatchUnits
func (s *deployerSuite) TestWatchUnits(c *gc.C) {
c.Assert(s.resources.Count(), gc.Equals, 0)
args := params.Entities{Entities: []params.Entity{
{Tag: "machine-1"},
{Tag: "machine-0"},
{Tag: "machine-42"},
}}
result, err := s.deployer.WatchUnits(args)
c.Assert(err, gc.IsNil)
sort.Strings(result.Results[0].Changes)
c.Assert(result, gc.DeepEquals, params.StringsWatchResults{
Results: []params.StringsWatchResult{
{Changes: []string{"logging/0", "mysql/0"}, StringsWatcherId: "1"},
{Error: apiservertesting.ErrUnauthorized},
{Error: apiservertesting.ErrUnauthorized},
},
})
// Verify the resource was registered and stop when done
c.Assert(s.resources.Count(), gc.Equals, 1)
c.Assert(result.Results[0].StringsWatcherId, gc.Equals, "1")
resource := s.resources.Get("1")
defer statetesting.AssertStop(c, resource)
// Check that the Watch has consumed the initial event ("returned" in
// the Watch call)
wc := statetesting.NewStringsWatcherC(c, s.State, resource.(state.StringsWatcher))
wc.AssertNoChange()
}
示例14: TestWatchAuthorisedKeys
func (s *authorisedKeysSuite) TestWatchAuthorisedKeys(c *gc.C) {
args := params.Entities{
Entities: []params.Entity{
{Tag: s.rawMachine.Tag()},
{Tag: s.unrelatedMachine.Tag()},
{Tag: "machine-42"},
},
}
results, err := s.keyupdater.WatchAuthorisedKeys(args)
c.Assert(err, gc.IsNil)
c.Assert(results, gc.DeepEquals, params.NotifyWatchResults{
Results: []params.NotifyWatchResult{
{NotifyWatcherId: "1"},
{Error: apiservertesting.ErrUnauthorized},
{Error: apiservertesting.ErrUnauthorized},
},
})
c.Assert(results.Results[0].NotifyWatcherId, gc.Not(gc.Equals), "")
c.Assert(results.Results[0].Error, gc.IsNil)
resource := s.resources.Get(results.Results[0].NotifyWatcherId)
c.Assert(resource, gc.NotNil)
w := resource.(state.NotifyWatcher)
wc := statetesting.NewNotifyWatcherC(c, s.State, w)
wc.AssertNoChange()
s.setAuthorizedKeys(c, "key1\nkey2")
wc.AssertOneChange()
statetesting.AssertStop(c, w)
wc.AssertClosed()
}
示例15: TestWatchEnvironMachines
func (s *withoutStateServerSuite) TestWatchEnvironMachines(c *gc.C) {
c.Assert(s.resources.Count(), gc.Equals, 0)
got, err := s.provisioner.WatchEnvironMachines()
c.Assert(err, gc.IsNil)
want := params.StringsWatchResult{
StringsWatcherId: "1",
Changes: []string{"0", "1", "2", "3", "4"},
}
c.Assert(got.StringsWatcherId, gc.Equals, want.StringsWatcherId)
c.Assert(got.Changes, jc.SameContents, want.Changes)
// Verify the resources were registered and stop them when done.
c.Assert(s.resources.Count(), gc.Equals, 1)
resource := s.resources.Get("1")
defer statetesting.AssertStop(c, resource)
// Check that the Watch has consumed the initial event ("returned"
// in the Watch call)
wc := statetesting.NewStringsWatcherC(c, s.State, resource.(state.StringsWatcher))
wc.AssertNoChange()
// Make sure WatchEnvironMachines fails with a machine agent login.
anAuthorizer := s.authorizer
anAuthorizer.MachineAgent = true
anAuthorizer.EnvironManager = false
aProvisioner, err := provisioner.NewProvisionerAPI(s.State, s.resources, anAuthorizer)
c.Assert(err, gc.IsNil)
result, err := aProvisioner.WatchEnvironMachines()
c.Assert(err, gc.ErrorMatches, "permission denied")
c.Assert(result, gc.DeepEquals, params.StringsWatchResult{})
}