예제 #1
0
파일: export_test.go 프로젝트: kat-co/juju
// 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)
}
예제 #2
0
파일: schedule_test.go 프로젝트: bac/juju
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")
	}
}
예제 #3
0
파일: pinger_test.go 프로젝트: bac/juju
func waitAndAdvance(c *gc.C, clock *testing.Clock, delta time.Duration) {
	waitForClock(c, clock)
	clock.Advance(delta)
}
예제 #4
0
파일: pinger_test.go 프로젝트: kat-co/juju
func (s *pingerSuite) advanceClock(c *gc.C, clock *testing.Clock, delta time.Duration, count int) {
	for i := 0; i < count; i++ {
		clock.Advance(delta)
	}
}