@@ -20,8 +20,6 @@ use protocols::sync::{agent, agent_ttrpc, health, health_ttrpc};
2020use std:: thread;
2121use std:: time:: Duration ;
2222use ttrpc:: context:: { self , Context } ;
23- use ttrpc:: error:: Error ;
24- use ttrpc:: proto:: Code ;
2523use ttrpc:: Client ;
2624
2725#[ cfg( not( target_os = "linux" ) ) ]
@@ -45,6 +43,8 @@ fn main() {
4543 thread:: sleep ( Duration :: from_secs ( 1 ) ) ;
4644 let current_fd_count = get_fd_count ( ) ;
4745 assert_eq ! ( current_fd_count, expected_fd_count, "check fd count" ) ;
46+
47+ println ! ( "***** Sync test is OK! *****" ) ;
4848}
4949
5050fn connect_once ( ) {
@@ -67,26 +67,22 @@ fn connect_once() {
6767 now. elapsed( ) ,
6868 ) ;
6969
70- let rsp = thc. check ( default_ctx ( ) , & req) ;
71- match rsp. as_ref ( ) {
72- Err ( Error :: RpcStatus ( s) ) => {
73- assert_eq ! ( Code :: NOT_FOUND , s. code( ) ) ;
74- assert_eq ! ( "Just for fun" . to_string( ) , s. message( ) )
75- }
76- Err ( e) => {
77- panic ! ( "not expecting an error from the example server: {:?}" , e)
78- }
79- Ok ( x) => {
80- panic ! (
81- "not expecting a OK response from the example server: {:?}" ,
82- x
83- )
84- }
85- }
70+ let resp = thc. check (
71+ context:: with_duration ( core:: time:: Duration :: from_millis ( 20 ) ) ,
72+ & req,
73+ ) ;
74+
75+ assert_eq ! (
76+ resp,
77+ Err ( ttrpc:: Error :: Others (
78+ "Receive packet from Receiver timeout: timed out waiting on channel" . into( )
79+ ) )
80+ ) ;
81+
8682 println ! (
8783 "OS Thread {:?} - health.check() -> {:?} ended: {:?}" ,
8884 std:: thread:: current( ) . id( ) ,
89- rsp ,
85+ resp ,
9086 now. elapsed( ) ,
9187 ) ;
9288 } ) ;
@@ -98,21 +94,14 @@ fn connect_once() {
9894 now. elapsed( ) ,
9995 ) ;
10096
101- let show = match tac. list_interfaces ( default_ctx ( ) , & agent:: ListInterfacesRequest :: new ( ) ) {
102- Err ( e) => {
103- panic ! ( "not expecting an error from the example server: {:?}" , e)
104- }
105- Ok ( s) => {
106- assert_eq ! ( "first" . to_string( ) , s. Interfaces [ 0 ] . name) ;
107- assert_eq ! ( "second" . to_string( ) , s. Interfaces [ 1 ] . name) ;
108- format ! ( "{s:?}" )
109- }
110- } ;
97+ let resp = tac. list_interfaces ( default_ctx ( ) , & agent:: ListInterfacesRequest :: new ( ) ) ;
98+ let expected_resp = utils:: resp:: sync:: agent_list_interfaces ( ) ;
99+ assert_eq ! ( resp, expected_resp) ;
111100
112101 println ! (
113102 "OS Thread {:?} - agent.list_interfaces() -> {} ended: {:?}" ,
114103 std:: thread:: current( ) . id( ) ,
115- show ,
104+ "{resp:?}" ,
116105 now. elapsed( ) ,
117106 ) ;
118107 } ) ;
@@ -121,34 +110,22 @@ fn connect_once() {
121110 "Main OS Thread - agent.online_cpu_mem() started: {:?}" ,
122111 now. elapsed( )
123112 ) ;
124- let show = match ac. online_cpu_mem ( default_ctx ( ) , & agent:: OnlineCPUMemRequest :: new ( ) ) {
125- Err ( Error :: RpcStatus ( s) ) => {
126- assert_eq ! ( Code :: NOT_FOUND , s. code( ) ) ;
127- assert_eq ! (
128- "/grpc.AgentService/OnlineCPUMem is not supported" . to_string( ) ,
129- s. message( )
130- ) ;
131- format ! ( "{s:?}" )
132- }
133- Err ( e) => {
134- panic ! ( "not expecting an error from the example server: {:?}" , e)
135- }
136- Ok ( s) => {
137- panic ! (
138- "not expecting a OK response from the example server: {:?}" ,
139- s
140- )
141- }
142- } ;
113+ let resp = ac
114+ . online_cpu_mem ( default_ctx ( ) , & agent:: OnlineCPUMemRequest :: new ( ) )
115+ . expect_err ( "not the expecting error from the example server" ) ;
116+ let expected_resp = utils:: resp:: online_cpu_mem_not_impl ( ) ;
117+ assert_eq ! ( resp, expected_resp) ;
118+
143119 println ! (
144- "Main OS Thread - agent.online_cpu_mem() -> {} ended: {:?}" ,
145- show ,
120+ "Main OS Thread - agent.online_cpu_mem() -> {:? } ended: {:?}" ,
121+ resp ,
146122 now. elapsed( )
147123 ) ;
148124
149125 let version = hc. version ( default_ctx ( ) , & health:: CheckRequest :: new ( ) ) ;
150- assert_eq ! ( "mock.0.1" , version. as_ref( ) . unwrap( ) . agent_version. as_str( ) ) ;
151- assert_eq ! ( "0.0.1" , version. as_ref( ) . unwrap( ) . grpc_version. as_str( ) ) ;
126+ let expected_version_resp = utils:: resp:: sync:: health_version ( ) ;
127+ assert_eq ! ( version, expected_version_resp) ;
128+
152129 println ! (
153130 "Main OS Thread - health.version() started: {:?}" ,
154131 now. elapsed( )
0 commit comments