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


Golang T.Status方法代码示例

本文整理汇总了Golang中testing.T.Status方法的典型用法代码示例。如果您正苦于以下问题:Golang T.Status方法的具体用法?Golang T.Status怎么用?Golang T.Status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在testing.T的用法示例。


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

示例1: TestTask


//.........这里部分代码省略.........
			So(len(taskTable), ShouldEqual, 2)

		})

		Convey("Task is created and starts to spin", func() {
			sch := schedule.NewSimpleSchedule(time.Second * 5)
			task, err := newTask(sch, wf, newWorkManager(), c, emitter)
			So(err, ShouldBeNil)
			task.Spin()
			So(task.state, ShouldEqual, core.TaskSpinning)
			Convey("Task is Stopped", func() {
				task.Stop()
				time.Sleep(time.Millisecond * 10) // it is a race so we slow down the test
				So(task.state, ShouldEqual, core.TaskStopped)
			})
		})

		Convey("task fires", func() {
			sch := schedule.NewSimpleSchedule(time.Nanosecond * 100)
			task, err := newTask(sch, wf, newWorkManager(), c, emitter)
			So(err, ShouldBeNil)
			task.Spin()
			time.Sleep(time.Millisecond * 50)
			So(task.hitCount, ShouldBeGreaterThan, 2)
			So(task.missedIntervals, ShouldBeGreaterThan, 2)
			task.Stop()
		})

		Convey("Enable a running task", func() {
			sch := schedule.NewSimpleSchedule(time.Millisecond * 10)
			task, err := newTask(sch, wf, newWorkManager(), c, emitter)
			So(err, ShouldBeNil)
			task.Spin()
			err = task.Enable()
			So(err, ShouldNotBeNil)
			So(task.State(), ShouldEqual, core.TaskSpinning)
		})

		Convey("Enable a disabled task", func() {
			sch := schedule.NewSimpleSchedule(time.Millisecond * 10)
			task, err := newTask(sch, wf, newWorkManager(), c, emitter)
			So(err, ShouldBeNil)

			task.state = core.TaskDisabled
			err = task.Enable()
			So(err, ShouldBeNil)
			So(task.State(), ShouldEqual, core.TaskStopped)
		})
	})

	Convey("Create task collection", t, func() {
		sampleWFMap := wmap.Sample()
		wf, errs := wmapToWorkflow(sampleWFMap)
		So(errs, ShouldBeEmpty)

		sch := schedule.NewSimpleSchedule(time.Millisecond * 10)
		task, err := newTask(sch, wf, newWorkManager(), &mockMetricManager{}, emitter)
		So(err, ShouldBeNil)
		So(task.id, ShouldNotBeEmpty)
		So(task.id, ShouldNotBeNil)
		taskCollection := newTaskCollection()

		Convey("Add task to collection", func() {

			err := taskCollection.add(task)
			So(err, ShouldBeNil)
			So(len(taskCollection.table), ShouldEqual, 1)

			Convey("Attempt to add the same task again", func() {
				err := taskCollection.add(task)
				So(err, ShouldNotBeNil)
			})

			Convey("Get task from collection", func() {
				t := taskCollection.Get(task.id)
				So(t, ShouldNotBeNil)
				So(t.ID(), ShouldEqual, task.id)
				So(t.CreationTime().Nanosecond(), ShouldBeLessThan, time.Now().Nanosecond())
				So(t.HitCount(), ShouldEqual, 0)
				So(t.MissedCount(), ShouldEqual, 0)
				So(t.State(), ShouldEqual, core.TaskStopped)
				So(t.Status(), ShouldEqual, core.WorkflowStopped)
				So(t.LastRunTime().IsZero(), ShouldBeTrue)
			})

			Convey("Attempt to get task with an invalid Id", func() {
				t := taskCollection.Get("1234")
				So(t, ShouldBeNil)
			})

			Convey("Create another task and compare the id", func() {
				task2, err := newTask(sch, wf, newWorkManager(), &mockMetricManager{}, emitter)
				So(err, ShouldBeNil)
				So(task2.id, ShouldNotEqual, task.ID())
			})

		})

	})
}
开发者ID:Collinux,项目名称:snap,代码行数:101,代码来源:task_test.go


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