Skip to content

Commit f022ba0

Browse files
committed
assert grpc call errors
Signed-off-by: Eguzki Astiz Lezaun <[email protected]>
1 parent 1bdc4d2 commit f022ba0

File tree

4 files changed

+39
-27
lines changed

4 files changed

+39
-27
lines changed

src/expect_interface.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
use crate::tester::Tester;
16+
use crate::types::Status;
1617

1718
// As of now, the following expectations do not require "fn returning()" implementations and hence
1819
// no structure is provided for them. Setting of these expectations are built directly into tester.rs:
@@ -182,15 +183,15 @@ impl<'a> ExpectGrpcCall<'a> {
182183
}
183184
}
184185

185-
pub fn returning(&mut self, token_id: Option<u32>) -> &mut Tester {
186+
pub fn returning(&mut self, res: Result<u32, Status>) -> &mut Tester {
186187
self.tester.get_expect_handle().staged.set_expect_grpc_call(
187188
self.service,
188189
self.service_name,
189190
self.method_name,
190191
self.initial_metadata,
191192
self.request,
192193
self.timeout,
193-
token_id,
194+
res,
194195
);
195196
self.tester
196197
}

src/expectations.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub struct Expect {
9696
Option<Bytes>,
9797
Option<Bytes>,
9898
Option<Duration>,
99-
Option<u32>,
99+
Result<u32, Status>,
100100
)>,
101101
get_property_value: Vec<(Option<Bytes>, Option<Bytes>)>,
102102
}
@@ -593,7 +593,7 @@ impl Expect {
593593
initial_metadata: Option<&[u8]>,
594594
request: Option<&[u8]>,
595595
timeout: Option<u64>,
596-
token_id: Option<u32>,
596+
res: Result<u32, Status>,
597597
) {
598598
self.expect_count += 1;
599599
self.grpc_call.push((
@@ -603,7 +603,7 @@ impl Expect {
603603
initial_metadata.map(|s| s.to_vec()),
604604
request.map(|s| s.to_vec()),
605605
timeout.map(Duration::from_millis),
606-
token_id,
606+
res,
607607
));
608608
}
609609

@@ -615,7 +615,7 @@ impl Expect {
615615
initial_metadata: &[u8],
616616
request: &[u8],
617617
timeout: i32,
618-
) -> Option<u32> {
618+
) -> Option<Result<u32, Status>> {
619619
match self.grpc_call.len() {
620620
0 => {
621621
if !self.allow_unexpected {
@@ -649,7 +649,7 @@ impl Expect {
649649
.map(|e| e.as_millis() as i32 == timeout)
650650
.unwrap_or(true);
651651
set_expect_status(expected);
652-
return result;
652+
return Some(result);
653653
}
654654
}
655655
}

src/hostcalls.rs

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,9 +1485,9 @@ fn get_hostfunc(
14851485
let mem = match caller.get_export("memory") {
14861486
Some(Extern::Memory(mem)) => mem,
14871487
_ => {
1488-
println!("Error: proxy_http_call cannot get export \"memory\"");
1488+
println!("Error: proxy_grpc_call cannot get export \"memory\"");
14891489
println!(
1490-
"[vm<-host] proxy_http_call(...) -> (return_token) return: {:?}",
1490+
"[vm<-host] proxy_grpc_call(...) -> (return_token) return: {:?}",
14911491
Status::InternalFailure
14921492
);
14931493
return Status::InternalFailure as i32;
@@ -1506,25 +1506,34 @@ fn get_hostfunc(
15061506
println!(
15071507
"[vm->host] proxy_grpc_call(service={service}, service_name={service_name}, method_name={method_name}, initial_metadata={initial_metadata:?}, request={request:?}, timeout={timeout_milliseconds}");
15081508

1509-
let token_id = match EXPECT.lock().unwrap().staged.get_expect_grpc_call(
1510-
service,
1511-
service_name,
1512-
method_name,
1513-
initial_metadata,
1514-
request,
1515-
timeout_milliseconds,
1516-
) {
1517-
Some(expect_token) => expect_token,
1518-
None => 0,
1519-
};
1520-
1521-
unsafe {
1522-
let return_token_add = mem.data_mut(&mut caller).get_unchecked_mut(
1523-
token_ptr as u32 as usize..token_ptr as u32 as usize + 4,
1524-
);
1525-
return_token_add.copy_from_slice(&token_id.to_le_bytes());
1509+
let call_result = EXPECT
1510+
.lock()
1511+
.unwrap()
1512+
.staged
1513+
.get_expect_grpc_call(
1514+
service,
1515+
service_name,
1516+
method_name,
1517+
initial_metadata,
1518+
request,
1519+
timeout_milliseconds,
1520+
)
1521+
.unwrap_or(Ok(0));
1522+
1523+
if let Ok(token_id) = call_result {
1524+
unsafe {
1525+
let return_token_add = mem.data_mut(&mut caller).get_unchecked_mut(
1526+
token_ptr as u32 as usize..token_ptr as u32 as usize + 4,
1527+
);
1528+
return_token_add.copy_from_slice(&token_id.to_le_bytes());
1529+
}
15261530
}
15271531

1532+
let call_status = match call_result {
1533+
Ok(_) => Status::Ok,
1534+
Err(s) => s,
1535+
};
1536+
15281537
// Default Function:
15291538
// Expectation:
15301539
println!(
@@ -1536,7 +1545,7 @@ fn get_hostfunc(
15361545
Status::Ok
15371546
);
15381547
assert_ne!(get_status(), ExpectStatus::Failed);
1539-
return Status::Ok as i32;
1548+
return call_status as i32;
15401549
},
15411550
))
15421551
}

src/types.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ pub enum Status {
5959
Ok = 0,
6060
NotFound = 1,
6161
BadArgument = 2,
62+
SerializationFailure = 3,
63+
ParseFailure = 4,
6264
Empty = 7,
6365
CasMismatch = 8,
6466
InternalFailure = 10,

0 commit comments

Comments
 (0)