当前位置: 首页>>代码示例>>Golang>>正文


Golang testing.Clock类代码示例

本文整理汇总了Golang中github.com/juju/testing.Clock的典型用法代码示例。如果您正苦于以下问题:Golang Clock类的具体用法?Golang Clock怎么用?Golang Clock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Clock类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: waitAlarm

func waitAlarm(c *gc.C, clock *jujutesting.Clock) {
	select {
	case <-time.After(testing.LongWait):
		c.Fatalf("alarm never set")
	case <-clock.Alarms():
	}
}
开发者ID:bac,项目名称:juju,代码行数:7,代码来源:root_test.go

示例2: waitForClock

func waitForClock(c *gc.C, clock *testing.Clock) {
	select {
	case <-clock.Alarms():
	case <-time.After(coretesting.LongWait):
		c.Fatal("timed out waiting for clock")
	}
}
开发者ID:bac,项目名称:juju,代码行数:7,代码来源:pinger_test.go

示例3: WaitAlarms

// WaitAlarms waits until the supplied clock has sent count values on
// its Alarms channel.
func WaitAlarms(c *gc.C, clock *testing.Clock, count int) {
	timeout := time.After(jujutesting.LongWait)
	for i := 0; i < count; i++ {
		select {
		case <-timeout:
			c.Fatalf("never saw alarm %d", i)
		case <-clock.Alarms():
		}
	}
}
开发者ID:kat-co,项目名称:juju,代码行数:12,代码来源:fixture_test.go

示例4: waitAlarms

func waitAlarms(c *gc.C, clock *testing.Clock, count int) {
	timeout := time.After(coretesting.LongWait)
	for i := 0; i < count; i++ {
		select {
		case <-clock.Alarms():
		case <-timeout:
			c.Fatalf("timed out waiting for %dth alarm set", i)
		}
	}
}
开发者ID:bac,项目名称:juju,代码行数:10,代码来源:fixture_test.go

示例5: assertNextOp

func assertNextOp(c *gc.C, s *schedule.Schedule, clock *jujutesting.Clock, d time.Duration) {
	next := s.Next()
	c.Assert(next, gc.NotNil)
	if d > 0 {
		select {
		case <-next:
			c.Fatal("Next channel signalled too soon")
		default:
		}
	}

	// temporarily move time forward
	clock.Advance(d)
	defer clock.Advance(-d)

	select {
	case _, ok := <-next:
		c.Assert(ok, jc.IsTrue)
		// the time value is unimportant to us
	default:
		c.Fatal("Next channel not signalled")
	}
}
开发者ID:bac,项目名称:juju,代码行数:23,代码来源:schedule_test.go

示例6: PrimeUnitStatusHistory

// PrimeUnitStatusHistory will add count history elements, advancing the test clock by
// one second for each entry.
func PrimeUnitStatusHistory(
	c *gc.C, clock *testing.Clock,
	unit *Unit, statusVal status.Status,
	count, batchSize int,
	nextData func(int) map[string]interface{},
) {
	globalKey := unit.globalKey()

	history, closer := unit.st.getCollection(statusesHistoryC)
	defer closer()
	historyW := history.Writeable()

	var data map[string]interface{}
	for i := 0; i < count; {
		var docs []interface{}
		for j := 0; j < batchSize && i < count; j++ {
			clock.Advance(time.Second)
			if nextData != nil {
				data = utils.EscapeKeys(nextData(i))
			}
			docs = append(docs, &historicalStatusDoc{
				Status:     statusVal,
				StatusData: data,
				Updated:    clock.Now().UnixNano(),
				GlobalKey:  globalKey,
			})
			// Seems like you can't increment two values in one loop
			i++
		}
		err := historyW.Insert(docs...)
		c.Assert(err, jc.ErrorIsNil)
	}
	// Set the status for the unit itself.
	doc := statusDoc{
		Status:     statusVal,
		StatusData: data,
		Updated:    clock.Now().UnixNano(),
	}
	buildTxn := updateStatusSource(unit.st, globalKey, doc)
	err := unit.st.run(buildTxn)
	c.Assert(err, jc.ErrorIsNil)
}
开发者ID:kat-co,项目名称:juju,代码行数:44,代码来源:export_test.go

示例7: waitAndAdvance

func waitAndAdvance(c *gc.C, clock *testing.Clock, delta time.Duration) {
	waitForClock(c, clock)
	clock.Advance(delta)
}
开发者ID:bac,项目名称:juju,代码行数:4,代码来源:pinger_test.go

示例8: assertReady

func assertReady(c *gc.C, s *schedule.Schedule, clock *jujutesting.Clock, expect ...interface{}) {
	ready := s.Ready(clock.Now())
	c.Assert(ready, jc.DeepEquals, expect)
}
开发者ID:bac,项目名称:juju,代码行数:4,代码来源:schedule_test.go

示例9: advanceClock

func (s *pingerSuite) advanceClock(c *gc.C, clock *testing.Clock, delta time.Duration, count int) {
	for i := 0; i < count; i++ {
		clock.Advance(delta)
	}
}
开发者ID:kat-co,项目名称:juju,代码行数:5,代码来源:pinger_test.go


注:本文中的github.com/juju/testing.Clock类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。