Example #1
0
func Test_Proto_GRPC_Timeout(t *testing.T) {
	t.Skip()
	logx.SetLevel(logx.DEBUG)
	srv1 := new(GRPCServer)
	srv1.Start()
	defer srv1.srv.Stop()

	conn, err := grpc.Dial(fmt.Sprintf("localhost:%d", srv1.Port), grpc.WithInsecure())
	assert.NoError(t, err)
	defer conn.Close()

	c := pb3.NewBarClient(conn)

	req := pb3.TestRep{
		"test",
		[]byte(strings.Repeat("m", 10)),
	}
	res, err := c.Test(context.Background(), &req)
	assert.NoError(t, err)
	assert.EqualValues(t, req, *res)

	res1, err := c.Test(context.Background(), &req)
	assert.NoError(t, err)
	assert.EqualValues(t, req, *res1)
}
Example #2
0
func Benchmark_Proto_GRPC_Large(b *testing.B) {
	b.Skip()
	logx.SetLevel(logx.DEBUG)
	srv1 := new(GRPCServer)
	srv1.Start()
	defer srv1.srv.Stop()

	conn, err := grpc.Dial(fmt.Sprintf("localhost:%d", srv1.Port), grpc.WithInsecure())
	assert.NoError(b, err)
	defer conn.Close()

	c := pb3.NewBarClient(conn)

	b.Log(srv1.Port, b.N)

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		b.StartTimer()
		req := pb3.TestRep{
			fmt.Sprintf("%d", i),
			[]byte(strings.Repeat("m", 1024*1024)),
		}
		res, err := c.Test(context.Background(), &req)
		b.StopTimer()
		assert.NoError(b, err)
		assert.EqualValues(b, req, *res)
		b.SetBytes(int64(len(req.Body) * 2))
	}
}