Ejemplo n.º 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))
}
Ejemplo n.º 2
0
func TestMain(m *testing.M) {
	defer glog.Flush()
	flag.Parse()
	if testing.Verbose() {
		flag.Set("logtostderr", "1")
	}
	os.Exit(m.Run())
}
Ejemplo n.º 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)
	}
}
Ejemplo n.º 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()
}
Ejemplo n.º 5
0
func TestMain(m *testing.M) {
	defer glog.Flush()
	os.Exit(m.Run())
}