本文整理汇总了Golang中testing.T.state方法的典型用法代码示例。如果您正苦于以下问题:Golang T.state方法的具体用法?Golang T.state怎么用?Golang T.state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类testing.T
的用法示例。
在下文中一共展示了T.state方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestScheduler
//.........这里部分代码省略.........
So(len(err.Errors()), ShouldBeGreaterThan, 0)
So(err.Errors()[0], ShouldResemble, serror.New(ErrSchedulerNotStarted))
s1.metricManager = c
s1.Start()
_, err1 := s1.CreateTask(schedule.NewSimpleSchedule(time.Second*0), w, false)
So(err1.Errors()[0].Error(), ShouldResemble, "Interval must be greater than 0")
})
// // TODO NICK
Convey("create a task", func() {
tsk, err := s.CreateTask(schedule.NewSimpleSchedule(time.Second*5), w, false)
So(len(err.Errors()), ShouldEqual, 0)
So(tsk, ShouldNotBeNil)
So(tsk.(*task).deadlineDuration, ShouldResemble, DefaultDeadlineDuration)
So(len(s.GetTasks()), ShouldEqual, 2)
Convey("error when attempting to add duplicate task", func() {
err := s.tasks.add(tsk.(*task))
So(err, ShouldNotBeNil)
})
Convey("get created task", func() {
t, err := s.GetTask(tsk.ID())
So(err, ShouldBeNil)
So(t, ShouldEqual, tsk)
})
Convey("error when attempting to get a task that doesn't exist", func() {
t, err := s.GetTask("1234")
So(err, ShouldNotBeNil)
So(t, ShouldBeNil)
})
Convey("stop a stopped task", func() {
err := s.StopTask(tsk.ID())
So(len(err), ShouldEqual, 1)
So(err[0].Error(), ShouldEqual, "Task is already stopped.")
})
})
// // // TODO NICK
Convey("returns a task with a 6 second deadline duration", func() {
tsk, err := s.CreateTask(schedule.NewSimpleSchedule(time.Second*6), w, false, core.TaskDeadlineDuration(6*time.Second))
So(len(err.Errors()), ShouldEqual, 0)
So(tsk.(*task).deadlineDuration, ShouldResemble, time.Duration(6*time.Second))
prev := tsk.(*task).Option(core.TaskDeadlineDuration(1 * time.Second))
So(tsk.(*task).deadlineDuration, ShouldResemble, time.Duration(1*time.Second))
tsk.(*task).Option(prev)
So(tsk.(*task).deadlineDuration, ShouldResemble, time.Duration(6*time.Second))
})
Convey("Enable a stopped task", func() {
tsk, _ := s.CreateTask(schedule.NewSimpleSchedule(time.Millisecond*100), w, false)
So(tsk, ShouldNotBeNil)
_, err := s.EnableTask(tsk.ID())
So(err, ShouldNotBeNil)
})
Convey("Enable a disabled task", func() {
tsk, _ := s.CreateTask(schedule.NewSimpleSchedule(time.Millisecond*100), w, false)
So(tsk, ShouldNotBeNil)
t := s.tasks.Get(tsk.ID())
t.state = core.TaskDisabled
etsk, err1 := s.EnableTask(tsk.ID())
So(err1, ShouldBeNil)
So(etsk.State(), ShouldEqual, core.TaskStopped)
})
Convey("Start disabled task", func() {
tsk, _ := s.CreateTask(schedule.NewSimpleSchedule(time.Millisecond*100), w, false)
So(tsk, ShouldNotBeNil)
t := s.tasks.Get(tsk.ID())
t.state = core.TaskDisabled
err := s.StartTask(tsk.ID())
So(err[0].Error(), ShouldResemble, "Task is disabled. Cannot be started.")
So(t.state, ShouldEqual, core.TaskDisabled)
})
})
Convey("Stop()", t, func() {
Convey("Should set scheduler state to SchedulerStopped", func() {
scheduler := New(GetDefaultConfig())
c := new(mockMetricManager)
scheduler.metricManager = c
scheduler.Start()
scheduler.Stop()
So(scheduler.state, ShouldEqual, schedulerStopped)
})
})
Convey("SetMetricManager()", t, func() {
Convey("Should set metricManager for scheduler", func() {
scheduler := New(GetDefaultConfig())
c := new(mockMetricManager)
scheduler.SetMetricManager(c)
So(scheduler.metricManager, ShouldEqual, c)
})
})
}