本文整理汇总了Golang中testing.T.ID方法的典型用法代码示例。如果您正苦于以下问题:Golang T.ID方法的具体用法?Golang T.ID怎么用?Golang T.ID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类testing.T
的用法示例。
在下文中一共展示了T.ID方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestQueue
func TestQueue(t *testing.T) {
var out []string
q := &Queue{
Exec: func(t *Task) (Params, error) {
out = append(out, t.ID())
return nil, nil
},
}
s := &Service{
Name: "queue-test",
Version: "1.0.0",
Debug: true,
Handler: q,
}
if err := s.Start(nil); err != nil {
t.Errorf("start: %s", err)
return
}
// Enqueue blocks until each task is consumed.
for i := 0; i < 5; i++ {
t := q.NewTask()
q.Enqueue(t)
}
if err := s.Stop(); err != nil {
t.Errorf("stop: %s", err)
}
if len(out) != 5 {
t.Errorf("expected %d elements, got %d", 5, len(out))
}
}
示例2: TestList
func TestList(t *testing.T) {
c := setup(t)
testutil.Retry(t, 10, time.Second, func(r *testutil.R) {
topics, err := list(c)
if err != nil {
r.Errorf("failed to list topics: %v", err)
}
for _, t := range topics {
if t.ID() == topicID {
return // PASS
}
}
topicNames := make([]string, len(topics))
for i, t := range topics {
topicNames[i] = t.ID()
}
r.Errorf("got %+v; want a list with topic = %q", topicNames, topicID)
})
}
示例3: TestTask
func TestTask(t *testing.T) {
log.SetLevel(log.FatalLevel)
Convey("Task", t, func() {
sampleWFMap := wmap.Sample()
wf, errs := wmapToWorkflow(sampleWFMap)
So(errs, ShouldBeEmpty)
c := &mockMetricManager{}
c.setAcceptedContentType("rabbitmq", core.PublisherPluginType, 5, []string{plugin.SnapGOBContentType})
mgrs := newManagers(c)
err := wf.BindPluginContentTypes(&mgrs)
So(err, ShouldBeNil)
Convey("task + simple schedule", func() {
sch := schedule.NewSimpleSchedule(time.Millisecond * 100)
task, err := newTask(sch, wf, newWorkManager(), c, emitter)
So(err, ShouldBeNil)
task.Spin()
time.Sleep(time.Millisecond * 10) // it is a race so we slow down the test
So(task.state, ShouldEqual, core.TaskSpinning)
task.Stop()
})
Convey("Task specified-name test", func() {
sch := schedule.NewSimpleSchedule(time.Millisecond * 100)
task, err := newTask(sch, wf, newWorkManager(), c, emitter, core.SetTaskName("My name is unique"))
So(err, ShouldBeNil)
task.Spin()
So(task.GetName(), ShouldResemble, "My name is unique")
})
Convey("Task default-name test", func() {
sch := schedule.NewSimpleSchedule(time.Millisecond * 100)
task, err := newTask(sch, wf, newWorkManager(), c, emitter)
So(err, ShouldBeNil)
task.Spin()
So(task.GetName(), ShouldResemble, "Task-"+task.ID())
})
Convey("Task deadline duration test", func() {
sch := schedule.NewSimpleSchedule(time.Millisecond * 100)
task, err := newTask(sch, wf, newWorkManager(), c, emitter, core.TaskDeadlineDuration(20*time.Second))
So(err, ShouldBeNil)
task.Spin()
So(task.deadlineDuration, ShouldEqual, 20*time.Second)
task.Option(core.TaskDeadlineDuration(20 * time.Second))
So(core.TaskDeadlineDuration(2*time.Second), ShouldNotBeEmpty)
})
Convey("Tasks are created and creation of task table is checked", func() {
sch := schedule.NewSimpleSchedule(time.Millisecond * 100)
task, err := newTask(sch, wf, newWorkManager(), c, emitter)
So(err, ShouldBeNil)
task1, err := newTask(sch, wf, newWorkManager(), c, emitter)
So(err, ShouldBeNil)
task1.Spin()
task.Spin()
tC := newTaskCollection()
tC.add(task)
tC.add(task1)
taskTable := tC.Table()
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)
//.........这里部分代码省略.........
示例4: TestDistributedSubscriptions
func TestDistributedSubscriptions(t *testing.T) {
Convey("Load control/scheduler with a mock remote scheduler", t, func() {
l, _ := net.Listen("tcp", ":0")
l.Close()
cfg := control.GetDefaultConfig()
cfg.ListenPort = l.Addr().(*net.TCPAddr).Port
c1 := control.New(cfg)
c1.Start()
m, _ := net.Listen("tcp", ":0")
m.Close()
cfg.ListenPort = m.Addr().(*net.TCPAddr).Port
port1 := cfg.ListenPort
c2 := control.New(cfg)
schcfg := GetDefaultConfig()
sch := New(schcfg)
c2.Start()
sch.SetMetricManager(c1)
err := sch.Start()
So(err, ShouldBeNil)
// Load appropriate plugins into each control.
mock2Path := helper.PluginFilePath("snap-plugin-collector-mock2")
passthruPath := helper.PluginFilePath("snap-plugin-processor-passthru")
filePath := helper.PluginFilePath("snap-plugin-publisher-mock-file")
// mock2 and file onto c1
rp, err := core.NewRequestedPlugin(mock2Path)
So(err, ShouldBeNil)
_, err = c1.Load(rp)
So(err, ShouldBeNil)
rp, err = core.NewRequestedPlugin(filePath)
So(err, ShouldBeNil)
_, err = c1.Load(rp)
So(err, ShouldBeNil)
// passthru on c2
rp, err = core.NewRequestedPlugin(passthruPath)
So(err, ShouldBeNil)
_, err = c2.Load(rp)
So(err, ShouldBeNil)
Convey("Starting task should not succeed if remote dep fails to subscribe", func() {
//Create a task
//Create a workflowmap
wf := dsWFMap(port1)
// Create a task that is not started immediately so we can
// validate deps correctly.
t, errs := sch.CreateTask(schedule.NewSimpleSchedule(time.Second), wf, false)
So(len(errs.Errors()), ShouldEqual, 0)
So(t, ShouldNotBeNil)
schTask := t.(*task)
remoteMockManager := &subscriptionManager{Fail: true}
schTask.RemoteManagers.Add(fmt.Sprintf("127.0.0.1:%v", port1), remoteMockManager)
localMockManager := &subscriptionManager{Fail: false}
schTask.RemoteManagers.Add("", localMockManager)
// Start task. We expect it to fail while subscribing deps
terrs := sch.StartTask(t.ID())
So(terrs, ShouldNotBeNil)
Convey("So dependencies should have been unsubscribed", func() {
// Ensure that unsubscribe call count is equal to subscribe call count
// i.e that every subscribe call was followed by an unsubscribe since
// we errored
So(remoteMockManager.UnsubscribeCallCount, ShouldEqual, remoteMockManager.SubscribeCallCount)
So(localMockManager.UnsubscribeCallCount, ShouldEqual, localMockManager.UnsubscribeCallCount)
})
})
Convey("Starting task should not succeed if missing local dep fails to subscribe", func() {
//Create a task
//Create a workflowmap
wf := dsWFMap(port1)
// Create a task that is not started immediately so we can
// validate deps correctly.
t, errs := sch.CreateTask(schedule.NewSimpleSchedule(time.Second), wf, false)
So(len(errs.Errors()), ShouldEqual, 0)
So(t, ShouldNotBeNil)
schTask := t.(*task)
localMockManager := &subscriptionManager{Fail: true}
schTask.RemoteManagers.Add("", localMockManager)
remoteMockManager := &subscriptionManager{Fail: false}
schTask.RemoteManagers.Add(fmt.Sprintf("127.0.0.1:%v", port1), remoteMockManager)
// Start task. We expect it to fail while subscribing deps
terrs := sch.StartTask(t.ID())
So(terrs, ShouldNotBeNil)
Convey("So dependencies should have been unsubscribed", func() {
// Ensure that unsubscribe call count is equal to subscribe call count
// i.e that every subscribe call was followed by an unsubscribe since
// we errored
So(remoteMockManager.UnsubscribeCallCount, ShouldEqual, remoteMockManager.SubscribeCallCount)
So(localMockManager.UnsubscribeCallCount, ShouldEqual, localMockManager.UnsubscribeCallCount)
})
})
Convey("Starting task should suceed if all deps are available", func() {
//Create a task
//Create a workflowmap
wf := dsWFMap(port1)
// Create a task that is not started immediately so we can
// validate deps correctly.
//.........这里部分代码省略.........