From 050c77a5f747eb52798a127767881b1b62ccc762 Mon Sep 17 00:00:00 2001 From: what Date: Tue, 30 May 2023 17:47:53 +0800 Subject: [PATCH] =?UTF-8?q?[doc]=20=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- grpcall_test.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/grpcall_test.go b/grpcall_test.go index 1e3cd47..bba6ce0 100644 --- a/grpcall_test.go +++ b/grpcall_test.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "testing" + "time" "google.golang.org/grpc" ) @@ -18,12 +19,11 @@ func TestMain(m *testing.M) { gc = _gc } - defer gc.Close() - // 执行测试 code := m.Run() // 在这里执行一些清理工作,例如关闭数据库连接等 + gc.Close() // 退出测试 os.Exit(code) @@ -41,6 +41,7 @@ func TestGetServiceMethods(t *testing.T) { } } +// 数据请求测试 func TestInvokeUnary(t *testing.T) { if resp, err := gc.Invoke("User.UserResourceStatus", "TestInt64Value", `123`, nil); err != nil { t.Error(err) @@ -49,6 +50,7 @@ func TestInvokeUnary(t *testing.T) { } } +// 服务流测试 func TestInvokeServStream(t *testing.T) { if resp, err := gc.Invoke("User.UserResourceStatus", "GetEvent", `{}`, nil); err != nil { t.Error(err) @@ -75,6 +77,8 @@ func TestInvokeServStream(t *testing.T) { <-flag } } + +// 双向流测试 func TestInvokeBidiStream(t *testing.T) { if resp, err := gc.Invoke("User.UserResourceStatus", "TestBidiStream", `"hello"`, nil); err != nil { t.Error(err) @@ -98,6 +102,8 @@ func TestInvokeBidiStream(t *testing.T) { } flag <- true return + case <-time.After(time.Second): + resp.Cancel() } } }()