Beispiel #1
0
func Test_Fatals(t *testing.T) {
	// missing passphrase
	oldSecret := cfgSecret
	defer func() {
		cfgSecret = oldSecret
	}()
	cfgSecret = nil
	func() {
		defer func() {
			err := recover()
			utest.NotNilNow(t, err)
			utest.Assert(t, strings.Contains(err.(string), "Missing passphrase"))
		}()
		main()
	}()
	cfgSecret = oldSecret

	// bad pprof address
	cfgPprofAddr = "xxoo"
	func() {
		defer func() {
			err := recover()
			utest.NotNilNow(t, err)
			utest.Assert(t, strings.Contains(err.(string), "Setup pprof failed"))
		}()
		main()
	}()
	cfgPprofAddr = "0.0.0.0:0"

	// bad gateway address
	oldAddr := cfgGatewayAddr
	defer func() {
		cfgGatewayAddr = oldAddr
	}()
	cfgGatewayAddr = "abc"
	func() {
		defer func() {
			err := recover()
			utest.NotNilNow(t, err)
			utest.Assert(t, strings.Contains(err.(string), "Setup listener failed"))
		}()
		main()
	}()

	// bad gateway address with reuse port
	cfgReusePort = true
	func() {
		defer func() {
			err := recover()
			utest.NotNilNow(t, err)
			utest.Assert(t, strings.Contains(err.(string), "Setup listener failed"))
		}()
		start()
	}()
}
Beispiel #2
0
func Test_LockPool_DoubleFree(t *testing.T) {
	pool := NewLockPool(128, 1024, 2, 1024)
	mem := pool.Alloc(64)
	go func() {
		defer func() {
			utest.NotNilNow(t, recover())
		}()
		pool.Free(mem)
		pool.Free(mem)
	}()
}
Beispiel #3
0
func Test_Accept(t *testing.T) {
	_, err := accept(&TestListener{
		9, TestError{false, true},
	})
	utest.IsNilNow(t, err)

	_, err = accept(&TestListener{
		-1, TestError{true, false},
	})
	utest.NotNilNow(t, err)

	func() {
		defer func() {
			err := recover()
			utest.NotNilNow(t, err)
			utest.Assert(t, strings.Contains(err.(string), "Gateway accept failed"))
		}()
		loop(&TestListener{
			-1, TestError{true, false},
		})
	}()
}
Beispiel #4
0
func Test_AllocFree(t *testing.T) {
	pool := NewPool(128, 64*1024, 2, 1024*1024)
	for i := 0; i < len(pool.classes); i++ {
		temp := make([][]byte, len(pool.classes[i].chunks))

		for j := 0; j < len(temp); j++ {
			mem := pool.Alloc(0, pool.classes[i].size)
			utest.EqualNow(t, cap(mem), pool.classes[i].size)
			temp[j] = mem
		}
		utest.Assert(t, pool.classes[i].head == nil)

		for j := 0; j < len(temp); j++ {
			pool.Free(temp[j])
		}
		utest.NotNilNow(t, pool.classes[i].head)
	}
}