當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。