コード例 #1
0
func TestStopEmptyThrottledPersister(t *testing.T) {
	// Test bug: not stopped without traffic

	assert := assert.New(t)
	for _, maxUpdatesPerSecond := range []int{0, 4000} {
		for _, workers := range []int{1, 4} {
			qa.Root(t, func(root string) {

				ch := make(chan *points.Points, 10)
				p := NewWhisper(root, nil, nil, ch)
				p.SetMaxUpdatesPerSecond(maxUpdatesPerSecond)
				p.SetWorkers(workers)

				p.mockStore = func(p *Whisper, values *points.Points) {}

				p.Start()
				time.Sleep(10 * time.Millisecond)

				start := time.Now()
				p.Stop()
				worktime := time.Now().Sub(start)

				assert.True(worktime.Seconds() < 1, "maxUpdatesPerSecond: %d, workers: %d", maxUpdatesPerSecond, workers)
			})
		}
	}
}
コード例 #2
0
ファイル: app_stop_test.go プロジェクト: xyntrix/go-carbon
func TestStartStop(t *testing.T) {
	assert := assert.New(t)

	startGoroutineNum := runtime.NumGoroutine()

	for i := 0; i < 10; i++ {
		qa.Root(t, func(root string) {
			configFile := TestConfig(root)

			app := carbon.New(configFile)

			assert.NoError(app.ParseConfig())
			assert.NoError(app.Start())

			app.Stop()
		})
	}

	endGoroutineNum := runtime.NumGoroutine()

	// GC worker etc
	if !assert.InDelta(startGoroutineNum, endGoroutineNum, 3) {
		p := pprof.Lookup("goroutine")
		p.WriteTo(os.Stdout, 1)
	}

}
コード例 #3
0
func TestGracefullyStop(t *testing.T) {
	assert := assert.New(t)

	do := func(maxUpdatesPerSecond int, workers int) {
		ch := make(chan *points.Points, 1000)

		qa.Root(t, func(root string) {
			p := NewWhisper(root, nil, nil, ch)
			p.SetMaxUpdatesPerSecond(maxUpdatesPerSecond)
			p.SetWorkers(workers)

			storeWait := make(chan bool)
			var storeCount uint32

			p.mockStore = func(p *Whisper, values *points.Points) {
				<-storeWait
				atomic.AddUint32(&storeCount, 1)
			}

			var sentCount int

			p.Start()

		SEND_LOOP:
			for {
				select {
				case ch <- points.NowPoint(fmt.Sprintf("%d", sentCount), float64(sentCount)):
					sentCount++
				default:
					break SEND_LOOP
				}
			}

			time.Sleep(10 * time.Millisecond)
			close(storeWait)

			p.Stop()

			storeCount += uint32(len(ch))
			assert.Equal(sentCount, int(storeCount), "maxUpdatesPerSecond: %d, workers: %d", maxUpdatesPerSecond, workers)

		})
	}

	startGoroutineNum := runtime.NumGoroutine()
	for i := 0; i < 5; i++ {
		for _, maxUpdatesPerSecond := range []int{0, 4000} {
			for _, workers := range []int{1, 4} {
				do(maxUpdatesPerSecond, workers)
			}
		}
	}
	endGoroutineNum := runtime.NumGoroutine()
	// GC worker etc
	assert.InDelta(startGoroutineNum, endGoroutineNum, 2)
}