示例#1
0
文件: session_test.go 项目: xozrc/xo
//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")

}
示例#2
0
文件: session_test.go 项目: xozrc/xo
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))+"]")
}
示例#3
0
文件: session_test.go 项目: xozrc/xo
//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")

}