本文整理汇总了Golang中github.com/juju/utils.AttemptStrategy.Total方法的典型用法代码示例。如果您正苦于以下问题:Golang AttemptStrategy.Total方法的具体用法?Golang AttemptStrategy.Total怎么用?Golang AttemptStrategy.Total使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/utils.AttemptStrategy
的用法示例。
在下文中一共展示了AttemptStrategy.Total方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestCurrentStatus
func (s *MongoSuite) TestCurrentStatus(c *gc.C) {
session := s.root.MustDial()
defer session.Close()
inst1 := newServer(c)
defer inst1.Destroy()
defer Remove(session, inst1.Addr())
inst2 := newServer(c)
defer inst2.Destroy()
defer Remove(session, inst2.Addr())
var err error
strategy := utils.AttemptStrategy{Total: time.Minute * 2, Delay: time.Millisecond * 500}
attempt := strategy.Start()
for attempt.Next() {
err = Add(session, Member{Address: inst1.Addr()}, Member{Address: inst2.Addr()})
if err == nil || !attempt.HasNext() {
break
}
}
c.Assert(err, gc.IsNil)
expected := &Status{
Name: rsName,
Members: []MemberStatus{{
Id: 1,
Address: s.root.Addr(),
Self: true,
ErrMsg: "",
Healthy: true,
State: PrimaryState,
}, {
Id: 2,
Address: inst1.Addr(),
Self: false,
ErrMsg: "",
Healthy: true,
State: SecondaryState,
}, {
Id: 3,
Address: inst2.Addr(),
Self: false,
ErrMsg: "",
Healthy: true,
State: SecondaryState,
}},
}
strategy.Total = time.Second * 90
attempt = strategy.Start()
var res *Status
for attempt.Next() {
var err error
res, err = CurrentStatus(session)
if err != nil {
if !attempt.HasNext() {
c.Errorf("Couldn't get status before timeout, got err: %v", err)
return
} else {
// try again
continue
}
}
if res.Members[0].State == PrimaryState &&
res.Members[1].State == SecondaryState &&
res.Members[2].State == SecondaryState {
break
}
if !attempt.HasNext() {
c.Errorf("Servers did not get into final state before timeout. Status: %#v", res)
return
}
}
for x, _ := range res.Members {
// non-empty uptime and ping
c.Check(res.Members[x].Uptime, gc.Not(gc.Equals), 0)
// ping is always going to be zero since we're on localhost
// so we can't really test it right now
// now overwrite Uptime so it won't throw off DeepEquals
res.Members[x].Uptime = 0
}
c.Check(res, jc.DeepEquals, expected)
}