Ejemplo n.º 1
0
//test panic
func TestPanicContext(t *testing.T) {

	testNum := 1
	queueSize := 1
	taskCacheSize := 1
	prq := core.NewTaskQueue(queueSize, taskCacheSize)
	pwq := core.NewTaskQueue(queueSize, taskCacheSize)
	prh := &panicHandlerTest{}
	pwh := &panicHandlerTest{}

	prc := serverutil.NewContext(nil, nil, prq, prh)
	pwc := serverutil.NewContext(nil, nil, pwq, pwh)
	wg := sync.WaitGroup{}
	wg.Add(testNum)

	for i := 0; i < testNum; i++ {
		go func(ii int) {
			doneRead := prc.Read(i)
			doneWrite := pwc.Write(i)
			<-doneRead
			<-doneWrite
			wg.Done()
		}(i)
	}
	wg.Wait()

	common.AssertTest(t, prh.err == serverutil.ContextProcessMsgErr, "panic  read handler")
	common.AssertTest(t, pwh.err == serverutil.ContextProcessMsgErr, "panic write handler")

}
Ejemplo n.º 2
0
func TestFinalContextResult(t *testing.T) {

	testNum := 100000
	queueSize := 1
	taskCacheSize := 1000
	rq := core.NewTaskQueue(queueSize, taskCacheSize)
	wq := core.NewTaskQueue(queueSize, taskCacheSize)

	srh := &readFinalHandlerTest{}
	swh := &writeFinalHandlerTest{}
	rc := serverutil.NewContext(nil, nil, rq, srh)
	wc := serverutil.NewContext(nil, nil, wq, swh)

	wg := sync.WaitGroup{}
	wg.Add(testNum)

	for i := 0; i < testNum; i++ {
		go func(ii int) {
			doneRead := rc.Read(ii)
			doneWrite := wc.Write(ii)
			<-doneRead
			<-doneWrite
			wg.Done()
		}(i)
	}
	wg.Wait()

	tempReadSum, tempWriteSum := sum(testNum)

	common.AssertTest(t, tempReadSum == int(srh.readSum), "final read result ["+strconv.Itoa(tempReadSum)+"] no equal context result ["+strconv.Itoa(int(srh.readSum))+"]")
	common.AssertTest(t, tempWriteSum == int(swh.writeSum), "final read result ["+strconv.Itoa(tempWriteSum)+"] no equal context result ["+strconv.Itoa(int(swh.writeSum))+"]")
}
Ejemplo n.º 3
0
//test error
func TestErrorContext(t *testing.T) {

	testNum := 1
	queueSize := 1
	taskCacheSize := 1
	eq := core.NewTaskQueue(queueSize, taskCacheSize)
	ewq := core.NewTaskQueue(queueSize, taskCacheSize)
	eh := &errorHandlerTest{}
	ewh := &errorHandlerTest{}

	ec := serverutil.NewContext(nil, nil, eq, eh)
	ewc := serverutil.NewContext(nil, nil, ewq, ewh)
	wg := sync.WaitGroup{}
	wg.Add(testNum)

	for i := 0; i < testNum; i++ {
		go func(ii int) {
			doneRead := ec.Read(i)
			doneWrite := ewc.Write(i)
			<-doneRead
			<-doneWrite
			wg.Done()
		}(i)
	}
	wg.Wait()

	common.AssertTest(t, eh.err == errorRead, "error  read handler")
	common.AssertTest(t, ewh.err == errorWrite, "error write handler")

}
Ejemplo n.º 4
0
func TestRandomNoRepeat(t *testing.T) {

	totalNum := 10
	tempWeights := make([]int, totalNum)
	for i := 0; i < totalNum; i++ {
		tempWeights[i] = i + 1
	}
	randNums := 10
	randItemList := randomutil.RandomListByWeights(tempWeights, randNums, false)

	for _, randItem := range randItemList {
		fmt.Println(randItem)
	}
	common.AssertTest(t, len(randItemList) == randNums, "random nums error")
}
Ejemplo n.º 5
0
func TestNow(t *testing.T) {
	common.AssertTest(t, timeutil.Now() > 0, "time should more than 0 ")
}