@@ -20,8 +20,6 @@ use protocols::sync::{agent, agent_ttrpc, health, health_ttrpc};
20
20
use std:: thread;
21
21
use std:: time:: Duration ;
22
22
use ttrpc:: context:: { self , Context } ;
23
- use ttrpc:: error:: Error ;
24
- use ttrpc:: proto:: Code ;
25
23
use ttrpc:: Client ;
26
24
27
25
#[ cfg( not( target_os = "linux" ) ) ]
@@ -45,6 +43,8 @@ fn main() {
45
43
thread:: sleep ( Duration :: from_secs ( 1 ) ) ;
46
44
let current_fd_count = get_fd_count ( ) ;
47
45
assert_eq ! ( current_fd_count, expected_fd_count, "check fd count" ) ;
46
+
47
+ println ! ( "***** Sync test is OK! *****" ) ;
48
48
}
49
49
50
50
fn connect_once ( ) {
@@ -67,26 +67,22 @@ fn connect_once() {
67
67
now. elapsed( ) ,
68
68
) ;
69
69
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
+
86
82
println ! (
87
83
"OS Thread {:?} - health.check() -> {:?} ended: {:?}" ,
88
84
std:: thread:: current( ) . id( ) ,
89
- rsp ,
85
+ resp ,
90
86
now. elapsed( ) ,
91
87
) ;
92
88
} ) ;
@@ -98,21 +94,14 @@ fn connect_once() {
98
94
now. elapsed( ) ,
99
95
) ;
100
96
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) ;
111
100
112
101
println ! (
113
102
"OS Thread {:?} - agent.list_interfaces() -> {} ended: {:?}" ,
114
103
std:: thread:: current( ) . id( ) ,
115
- show ,
104
+ "{resp:?}" ,
116
105
now. elapsed( ) ,
117
106
) ;
118
107
} ) ;
@@ -121,34 +110,22 @@ fn connect_once() {
121
110
"Main OS Thread - agent.online_cpu_mem() started: {:?}" ,
122
111
now. elapsed( )
123
112
) ;
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
+
143
119
println ! (
144
- "Main OS Thread - agent.online_cpu_mem() -> {} ended: {:?}" ,
145
- show ,
120
+ "Main OS Thread - agent.online_cpu_mem() -> {:? } ended: {:?}" ,
121
+ resp ,
146
122
now. elapsed( )
147
123
) ;
148
124
149
125
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
+
152
129
println ! (
153
130
"Main OS Thread - health.version() started: {:?}" ,
154
131
now. elapsed( )
0 commit comments