本文整理汇总了Golang中github.com/juju/juju/worker/workertest.NewErrorWorker函数的典型用法代码示例。如果您正苦于以下问题:Golang NewErrorWorker函数的具体用法?Golang NewErrorWorker怎么用?Golang NewErrorWorker使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewErrorWorker函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestStopKills
func (*WorkerSuite) TestStopKills(c *gc.C) {
w := workertest.NewErrorWorker(nil)
defer workertest.CleanKill(c, w)
worker.Stop(w)
workertest.CheckKilled(c, w)
}
示例2: TestStartSuccess
func (*OccupySuite) TestStartSuccess(c *gc.C) {
fix := newFixture(c)
defer fix.TearDown(c)
c.Check(fix.Guard(c).Unlock(), jc.ErrorIsNil)
// Start a worker...
expect := workertest.NewErrorWorker(nil)
defer workertest.CleanKill(c, expect)
run := func() (worker.Worker, error) {
return expect, nil
}
worker, err := fortress.Occupy(fix.Guest(c), run, nil)
c.Assert(err, jc.ErrorIsNil)
c.Check(worker, gc.Equals, expect)
// ...and check we can't lockdown again...
locked := make(chan error, 1)
go func() {
locked <- fix.Guard(c).Lockdown(nil)
}()
select {
case err := <-locked:
c.Fatalf("unexpected Lockdown result: %v", err)
case <-time.After(coretesting.ShortWait):
}
// ...until the worker completes.
workertest.CleanKill(c, worker)
select {
case err := <-locked:
c.Check(err, jc.ErrorIsNil)
case <-time.After(coretesting.LongWait):
c.Fatalf("visit never completed")
}
}
示例3: newMockBackend
func newMockBackend() *mockBackend {
return &mockBackend{
envWatcher: &mockEnvWatcher{
Worker: workertest.NewErrorWorker(nil),
changes: make(chan []string),
},
}
}
示例4: TestCheckKilledTimeout
func (s *Suite) TestCheckKilledTimeout(c *gc.C) {
w := workertest.NewErrorWorker(nil)
defer workertest.CleanKill(c, w)
err := workertest.CheckKilled(c, w)
s.CheckFailed(c)
c.Check(err, gc.ErrorMatches, "workertest: worker not stopping")
}
示例5: TestCheckKillSuccess
func (s *Suite) TestCheckKillSuccess(c *gc.C) {
expect := errors.New("fledbon")
w := workertest.NewErrorWorker(expect)
defer workertest.DirtyKill(c, w)
err := workertest.CheckKill(c, w)
c.Check(err, gc.Equals, expect)
}
示例6: NewFakeNotifyWatcher
func NewFakeNotifyWatcher() *FakeNotifyWatcher {
ch := make(chan struct{}, 1)
ch <- struct{}{}
return &FakeNotifyWatcher{
Worker: workertest.NewErrorWorker(nil),
C: ch,
}
}
示例7: TestCheckKilledSuccess
func (s *Suite) TestCheckKilledSuccess(c *gc.C) {
expect := errors.New("snifplog")
w := workertest.NewErrorWorker(expect)
defer workertest.DirtyKill(c, w)
w.Kill()
err := workertest.CheckKilled(c, w)
c.Check(err, gc.Equals, expect)
}
示例8: newStubWatcher
func newStubWatcher() *stubWatcher {
changes := make(chan []string, 3)
changes <- []string{"expected", "first"}
changes <- []string{"expected", "second"}
changes <- []string{"unexpected?"}
return &stubWatcher{
Worker: workertest.NewErrorWorker(nil),
changes: changes,
}
}
示例9: newStubWatcher
func newStubWatcher() *stubWatcher {
changes := make(chan struct{}, 3)
changes <- struct{}{}
changes <- struct{}{}
changes <- struct{}{}
return &stubWatcher{
Worker: workertest.NewErrorWorker(nil),
notifyChan: changes,
}
}
示例10: newMockWatcher
// newMockWatcher returns a watcher.NotifyWatcher that always
// sends 3 changes and then sits quietly until killed.
func newMockWatcher() *mockWatcher {
const count = 3
changes := make(chan struct{}, count)
for i := 0; i < count; i++ {
changes <- struct{}{}
}
return &mockWatcher{
Worker: workertest.NewErrorWorker(nil),
changes: changes,
}
}
示例11: startPinger
func (context *context) startPinger() (presence.Pinger, error) {
context.stub.AddCall("Start")
context.checkCleanedUp()
if startErr := context.stub.NextErr(); startErr != nil {
return nil, startErr
}
context.mu.Lock()
defer context.mu.Unlock()
pingerErr := context.stub.NextErr()
context.current = workertest.NewErrorWorker(pingerErr)
context.starts <- context.current
return mockPinger{context.current}, nil
}
示例12: WatchModelResources
func (mock *mockFacade) WatchModelResources() (watcher.NotifyWatcher, error) {
mock.stub.AddCall("WatchModelResources")
if err := mock.stub.NextErr(); err != nil {
return nil, err
}
const count = 5
changes := make(chan struct{}, count)
for i := 0; i < count; i++ {
changes <- struct{}{}
}
return &mockWatcher{
Worker: workertest.NewErrorWorker(nil),
changes: changes,
}, nil
}
示例13: newWorkerList
// newWorkerList converts the supplied errors into a list of workers to
// be returned in order from the result's Next func (at which point they
// are sent on the reports chan as well).
func newWorkerList(errs []error) *workerList {
count := len(errs)
reports := make(chan worker.Worker, count)
workers := make([]worker.Worker, count)
for i, err := range errs {
if err == ErrFailStart {
workers[i] = nil
} else {
workers[i] = workertest.NewErrorWorker(err)
}
}
return &workerList{
workers: workers,
reports: reports,
}
}
示例14: TestOccupySuccess
func (*HousingSuite) TestOccupySuccess(c *gc.C) {
expectWorker := workertest.NewErrorWorker(errors.New("ignored"))
defer workertest.DirtyKill(c, expectWorker)
manifold := util.Housing{
Occupy: "fortress",
}.Decorate(dependency.Manifold{
Start: func(dependency.Context) (worker.Worker, error) {
return expectWorker, nil
},
})
guest := newGuest(true)
context := dt.StubContext(nil, map[string]interface{}{
"fortress": guest,
})
// wait for the start func to complete
started := make(chan struct{})
go func() {
defer close(started)
worker, err := manifold.Start(context)
c.Check(worker, gc.Equals, expectWorker)
c.Check(err, jc.ErrorIsNil)
}()
select {
case <-started:
case <-time.After(coretesting.LongWait):
c.Fatalf("timed out")
}
// check the worker's alive
workertest.CheckAlive(c, expectWorker)
// check the visit keeps running...
select {
case <-time.After(coretesting.ShortWait):
case <-guest.done:
c.Fatalf("visit finished early")
}
// ...until the worker stops
expectWorker.Kill()
select {
case <-guest.done:
case <-time.After(coretesting.LongWait):
c.Fatalf("timed out")
}
}
示例15: TestDeadWaits
func (*WorkerSuite) TestDeadWaits(c *gc.C) {
w := workertest.NewErrorWorker(nil)
defer workertest.CleanKill(c, w)
dead := worker.Dead(w)
select {
case <-time.After(coretesting.ShortWait):
case _, ok := <-dead:
if !ok {
c.Fatalf("Dead closed early")
} else {
c.Fatalf("Dead sent unexpectedly")
}
}
w.Kill()
select {
case _, ok := <-dead:
c.Check(ok, jc.IsFalse)
case <-time.After(coretesting.LongWait):
c.Fatalf("Dead never closed")
}
}