Example #1
0
func TestQueue(t *testing.T) {
	queue := NewQueue(5)
	for i := 0; i < 5; i++ {
		queue.Add(NewJob(
			func() {
				panic("Test panic")
			},
		))
	}
	counter := util.NewCounter(0)
	for i := 0; i < 100; i++ {
		queue.Add(NewJob(
			func() {
				counter.Add(1)
				runtime.Gosched()
			},
		))
	}

	queue.Stop()
	var expected int64 = 100
	if expected != counter.Value() {
		t.Fail()
	}
}
Example #2
0
//MakeCounter makes thread safe counter
func MakeCounter(value int) *util.Counter {
	return util.NewCounter(int64(value))
}