Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/expect_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

use crate::tester::Tester;
use crate::types::Status;

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

pub fn returning(&mut self, token_id: Option<u32>) -> &mut Tester {
pub fn returning(&mut self, res: Result<u32, Status>) -> &mut Tester {
self.tester.get_expect_handle().staged.set_expect_grpc_call(
self.service,
self.service_name,
self.method_name,
self.initial_metadata,
self.request,
self.timeout,
token_id,
res,
);
self.tester
}
Expand Down
10 changes: 5 additions & 5 deletions src/expectations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub struct Expect {
Option<Bytes>,
Option<Bytes>,
Option<Duration>,
Option<u32>,
Result<u32, Status>,
)>,
get_property_value: Vec<(Option<Bytes>, Option<Bytes>)>,
}
Expand Down Expand Up @@ -593,7 +593,7 @@ impl Expect {
initial_metadata: Option<&[u8]>,
request: Option<&[u8]>,
timeout: Option<u64>,
token_id: Option<u32>,
res: Result<u32, Status>,
) {
self.expect_count += 1;
self.grpc_call.push((
Expand All @@ -603,7 +603,7 @@ impl Expect {
initial_metadata.map(|s| s.to_vec()),
request.map(|s| s.to_vec()),
timeout.map(Duration::from_millis),
token_id,
res,
));
}

Expand All @@ -615,7 +615,7 @@ impl Expect {
initial_metadata: &[u8],
request: &[u8],
timeout: i32,
) -> Option<u32> {
) -> Option<Result<u32, Status>> {
match self.grpc_call.len() {
0 => {
if !self.allow_unexpected {
Expand Down Expand Up @@ -649,7 +649,7 @@ impl Expect {
.map(|e| e.as_millis() as i32 == timeout)
.unwrap_or(true);
set_expect_status(expected);
return result;
return Some(result);
}
}
}
Expand Down
49 changes: 29 additions & 20 deletions src/hostcalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1485,9 +1485,9 @@ fn get_hostfunc(
let mem = match caller.get_export("memory") {
Some(Extern::Memory(mem)) => mem,
_ => {
println!("Error: proxy_http_call cannot get export \"memory\"");
println!("Error: proxy_grpc_call cannot get export \"memory\"");
println!(
"[vm<-host] proxy_http_call(...) -> (return_token) return: {:?}",
"[vm<-host] proxy_grpc_call(...) -> (return_token) return: {:?}",
Status::InternalFailure
);
return Status::InternalFailure as i32;
Expand All @@ -1506,25 +1506,34 @@ fn get_hostfunc(
println!(
"[vm->host] proxy_grpc_call(service={service}, service_name={service_name}, method_name={method_name}, initial_metadata={initial_metadata:?}, request={request:?}, timeout={timeout_milliseconds}");

let token_id = match EXPECT.lock().unwrap().staged.get_expect_grpc_call(
service,
service_name,
method_name,
initial_metadata,
request,
timeout_milliseconds,
) {
Some(expect_token) => expect_token,
None => 0,
};

unsafe {
let return_token_add = mem.data_mut(&mut caller).get_unchecked_mut(
token_ptr as u32 as usize..token_ptr as u32 as usize + 4,
);
return_token_add.copy_from_slice(&token_id.to_le_bytes());
let call_result = EXPECT
.lock()
.unwrap()
.staged
.get_expect_grpc_call(
service,
service_name,
method_name,
initial_metadata,
request,
timeout_milliseconds,
)
.unwrap_or(Ok(0));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You seem to change this for a Err now, to get the previous behavior... that was already confusing, but that's now a new pattern, I don't think this makes sense...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So why the Result here? if the Err path gets dropped on the floor?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It get rewrapped in an Option::Some always... Now I get it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... other than when it isn't expected...


if let Ok(token_id) = call_result {
unsafe {
let return_token_add = mem.data_mut(&mut caller).get_unchecked_mut(
token_ptr as u32 as usize..token_ptr as u32 as usize + 4,
);
return_token_add.copy_from_slice(&token_id.to_le_bytes());
}
}

let call_status = match call_result {
Ok(_) => Status::Ok,
Err(s) => s,
};

// Default Function:
// Expectation:
println!(
Expand All @@ -1536,7 +1545,7 @@ fn get_hostfunc(
Status::Ok
);
assert_ne!(get_status(), ExpectStatus::Failed);
return Status::Ok as i32;
return call_status as i32;
},
))
}
Expand Down
2 changes: 2 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ pub enum Status {
Ok = 0,
NotFound = 1,
BadArgument = 2,
SerializationFailure = 3,
ParseFailure = 4,
Empty = 7,
CasMismatch = 8,
InternalFailure = 10,
Expand Down