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


Golang T.Stop方法代码示例

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


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

示例1: TestTimer

func TestTimer(t *testing.T) {

	signal := test.NewSignalTester(t)

	pipe := cellnet.NewEventPipe()

	evq := pipe.AddQueue()

	pipe.Start()

	const testTimes = 3

	var count int = testTimes

	cellnet.NewTimer(evq, time.Second, func(t *cellnet.Timer) {
		log.Debugln("timer 1 sec tick")

		signal.Done(1)

		count--

		if count == 0 {
			t.Stop()
			signal.Done(2)
		}
	})

	for i := 0; i < testTimes; i++ {
		signal.WaitAndExpect(1, "timer not tick")
	}

	signal.WaitAndExpect(2, "timer not stop")

}
开发者ID:CaiGuaiNi,项目名称:cellnet,代码行数:34,代码来源:timer_test.go

示例2: TestHistogramConcurrentUpdateCount

// TestHistogramConcurrentUpdateCount would expose data race problems with
// concurrent Update and Count calls on Sample when test is called with -race
// argument
func TestHistogramConcurrentUpdateCount(t *testing.T) {
	if testing.Short() {
		t.Skip("skipping in short mode")
	}
	h := NewHistogram(NewUniformSample(100))
	for i := 0; i < 100; i++ {
		h.Update(int64(i))
	}
	start := make(chan struct{})
	quit := make(chan struct{})
	go func() {
		t := time.NewTicker(10 * time.Millisecond)
		close(start)
		for {
			select {
			case <-t.C:
				h.Update(rand.Int63())
			case <-quit:
				t.Stop()
				return
			}
		}
	}()
	<-start // wait for background goroutine to start its job
	for i := 0; i < 1000; i++ {
		h.Count()
		time.Sleep(5 * time.Millisecond)
	}
	quit <- struct{}{}
}
开发者ID:ivaxer,项目名称:go-metrics,代码行数:33,代码来源:sample_test.go

示例3: TestUniformSampleConcurrentUpdateCount

// TestUniformSampleConcurrentUpdateCount would expose data race problems with
// concurrent Update and Count calls on Sample when test is called with -race
// argument
func TestUniformSampleConcurrentUpdateCount(t *testing.T) {
	if testing.Short() {
		t.Skip("skipping in short mode")
	}
	s := NewUniformSample(100)
	for i := 0; i < 100; i++ {
		s.Update(int64(i))
	}
	quit := make(chan struct{})
	go func() {
		t := time.NewTicker(10 * time.Millisecond)
		for {
			select {
			case <-t.C:
				s.Update(rand.Int63())
			case <-quit:
				t.Stop()
				return
			}
		}
	}()
	for i := 0; i < 1000; i++ {
		s.Count()
		time.Sleep(5 * time.Millisecond)
	}
	quit <- struct{}{}
}
开发者ID:Robin7Ma,项目名称:grafana,代码行数:30,代码来源:sample_test.go

示例4: TestConnection

func TestConnection(t *testing.T) {
	irccon1 := New("go-eventirc1", "go-eventirc1")
	irccon1.VerboseCallbackHandler = true
	irccon1.Debug = true
	irccon2 := New("go-eventirc2", "go-eventirc2")
	irccon2.VerboseCallbackHandler = true
	irccon2.Debug = true
	err := irccon1.Connect("irc.yolo-swag.com:6667")
	if err != nil {
		t.Log(err.Error())
		t.Fatal("Can't connect to ShadowNET.")
	}
	err = irccon2.Connect("irc.yolo-swag.com:6667")
	if err != nil {
		t.Log(err.Error())
		t.Fatal("Can't connect to ShadowNET.")
	}
	irccon1.AddCallback("001", func(e *Event) { irccon1.Join("#go-eventirc") })
	irccon2.AddCallback("001", func(e *Event) { irccon2.Join("#go-eventirc") })
	con2ok := false
	irccon1.AddCallback("366", func(e *Event) {
		t := time.NewTicker(1 * time.Second)
		i := 10
		for {
			<-t.C
			irccon1.Privmsgf("#go-eventirc", "Test Message%d\n", i)
			if con2ok {
				i--
			}
			if i == 0 {
				t.Stop()
				irccon1.Quit()
			}
		}
	})

	irccon2.AddCallback("366", func(e *Event) {
		irccon2.Privmsg("#go-eventirc", "Test Message\n")
		con2ok = true
		irccon2.Nick("go-eventnewnick")
	})

	irccon2.AddCallback("PRIVMSG", func(e *Event) {
		t.Log(e.Message())
		if e.Message() == "Test Message5" {
			irccon2.Quit()
		}
	})

	irccon2.AddCallback("NICK", func(e *Event) {
		if irccon2.nickcurrent == "go-eventnewnick" {
			t.Fatal("Nick change did not work!")
		}
	})
	go irccon2.Loop()
	irccon1.Loop()
}
开发者ID:Elemental-IRCd,项目名称:irc,代码行数:57,代码来源:irc_test.go

示例5: TestSystemTimer

func TestSystemTimer(t *testing.T) {
	t.Parallel()

	Convey(`A systemTimer instance`, t, func() {
		t := new(systemTimer)

		Convey(`Should start with a nil channel.`, func() {
			So(t.GetC(), ShouldBeNil)
		})

		Convey(`When stopped, should return inactive.`, func() {
			So(t.Stop(), ShouldBeFalse)
		})

		Convey(`When reset`, func() {
			active := t.Reset(1 * time.Hour)
			So(active, ShouldBeFalse)

			Convey(`When reset to a short duration`, func() {
				// Upper bound of supported platform resolution. Windows is 15ms, so
				// make sure we exceed that.
				active := t.Reset(100 * time.Millisecond)

				Convey(`Should return active.`, func() {
					So(active, ShouldBeTrue)
				})

				Convey(`Should trigger shortly.`, func() {
					tm := <-t.GetC()
					So(tm, ShouldNotResemble, time.Time{})
				})
			})

			Convey(`When stopped, should return active and have a non-nil C.`, func() {
				active := t.Stop()
				So(active, ShouldBeTrue)
				So(t.GetC(), ShouldNotBeNil)
			})

			Convey(`When stopped, should return active.`, func() {
				active := t.Stop()
				So(active, ShouldBeTrue)
			})

			Convey(`Should have a non-nil channel.`, func() {
				So(t.GetC(), ShouldNotBeNil)
			})

			Reset(func() {
				t.Stop()
			})
		})
	})
}
开发者ID:shishkander,项目名称:luci-go,代码行数:54,代码来源:systemtimer_test.go


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