Пример #1
0
func TestScheduleShouldStartAndStop(t *testing.T) {
	defer glog.Flush()
	assert := assert.New(t)

	unit := 10 * time.Millisecond
	calledCount := 0
	testF := func(start time.Time, dur time.Time) {
		remainder := start.Nanosecond() % int(unit)
		assert.Equal(0, remainder, "Start not truncated to 10ms")
		calledCount++
	}
	s := schedule.Schedule{
		Callback: testF,
		Period:   unit,
	}

	assert.NotNil(s)

	sleepCount := 3
	start := time.Now()
	err := s.Start()
	assert.Nil(err)
	time.Sleep(unit * time.Duration(sleepCount))
	s.Stop()
	elapsed := time.Since(start)
	assert.True(calledCount >= sleepCount && calledCount <= int(elapsed/unit))
}
Пример #2
0
func TestMain(m *testing.M) {
	defer glog.Flush()
	flag.Parse()
	if testing.Verbose() {
		flag.Set("logtostderr", "1")
	}
	os.Exit(m.Run())
}
Пример #3
0
func main() {
	defer glog.Flush()
	flag.Parse()
	config, err := morgoth.LoadFromFile(*configPath)
	if err != nil {
		glog.Errorf("Error loading config: %v\n", err)
		os.Exit(2)
	}

	app := morgoth.NewApp(config)
	err = app.Run()
	if err != nil {
		glog.Errorf("Error running application: %v\n", err)
		os.Exit(3)
	}
}
Пример #4
0
func TestScheduleShouldNotDoubleStart(t *testing.T) {
	defer glog.Flush()
	assert := assert.New(t)

	s := schedule.Schedule{
		Callback: func(start time.Time, dur time.Time) {},
		Period:   time.Millisecond,
	}

	assert.NotNil(s)

	err := s.Start()
	assert.Nil(err)

	err = s.Start()
	assert.NotNil(err)

	s.Stop()
}
Пример #5
0
func TestMain(m *testing.M) {
	defer glog.Flush()
	os.Exit(m.Run())
}