Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1265 #1277

Merged
merged 3 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
62 changes: 62 additions & 0 deletions golem-worker-executor-base/tests/rust_rpc_stubless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1143,3 +1143,65 @@ async fn ephemeral_worker_invocation_via_rpc1(
_ => panic!("Unexpected result value"),
}
}

#[test]
#[tracing::instrument]
async fn golem_bug_1265_test(
last_unique_id: &LastUniqueId,
deps: &WorkerExecutorTestDependencies,
_tracing: &Tracing,
) {
let context = TestContext::new(last_unique_id);
let executor = start(deps, &context).await.unwrap();

let counters_component_id = executor.store_component("counters").await;
let caller_component_id = executor
.store_component_with_dynamic_linking(
"caller",
&[
(
"rpc:counters-client/counters-client",
DynamicLinkedInstance::WasmRpc(DynamicLinkedWasmRpc {
target_interface_name: HashMap::from_iter(vec![
("api".to_string(), "rpc:counters-exports/api".to_string()),
(
"counter".to_string(),
"rpc:counters-exports/api".to_string(),
),
]),
}),
),
(
"rpc:ephemeral-client/ephemeral-client",
DynamicLinkedInstance::WasmRpc(DynamicLinkedWasmRpc {
target_interface_name: HashMap::from_iter(vec![(
"api".to_string(),
"rpc:ephemeral-exports/api".to_string(),
)]),
}),
),
],
)
.await;

let mut env = HashMap::new();
env.insert(
"COUNTERS_COMPONENT_ID".to_string(),
counters_component_id.to_string(),
);
let caller_worker_id = executor
.start_worker_with(&caller_component_id, "rpc-counters-bug1265", vec![], env)
.await;

let result = executor
.invoke_and_await(
&caller_worker_id,
"rpc:caller-exports/caller-inline-functions.{bug-golem1265}",
vec![Value::String("test".to_string())],
)
.await;

drop(executor);

check!(result == Ok(vec![Value::Result(Ok(None))]));
}
Binary file modified test-components/caller.wasm
Binary file not shown.
Binary file modified test-components/caller_composed.wasm
Binary file not shown.
Binary file modified test-components/counters.wasm
Binary file not shown.
Binary file modified test-components/ephemeral.wasm
Binary file not shown.
11 changes: 11 additions & 0 deletions test-components/rpc/caller/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ impl Guest for Component {

vec![(name1, key1), (name2, key2), (name3, key3)]
}

fn bug_golem1265(s: String) -> Result<(), String> {
println!("Reproducer for golem issue #1265");
let component_id =
env::var("COUNTERS_COMPONENT_ID").expect("COUNTERS_COMPONENT_ID not set");
let counters_uri = Uri {
value: format!("urn:worker:{component_id}/bug1265"),
};
let api = Api::new(&counters_uri);
api.blocking_bug_golem1265(&s)
}
}

fn create_use_and_drop_counters(counters_uri: &Uri) {
Expand Down
2 changes: 2 additions & 0 deletions test-components/rpc/caller/wit/caller.wit
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ world caller {
export bug-wasm-rpc-i32: func(in: timeline-node) -> timeline-node;

export ephemeral-test1: func() -> list<tuple<string, string>>;

export bug-golem1265: func(s: string) -> result<_, string>;
}
5 changes: 5 additions & 0 deletions test-components/rpc/counters/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ impl Guest for Component {
fn bug_wasm_rpc_i32(in_: TimelineNode) -> TimelineNode {
in_
}

fn bug_golem1265(s: String) -> Result<(), String> {
eprintln!("Got {s}");
Ok(())
}
}

pub struct Counter {
Expand Down
2 changes: 2 additions & 0 deletions test-components/rpc/counters/wit/counters.wit
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ interface api {
}

bug-wasm-rpc-i32: func(in: timeline-node) -> timeline-node;

bug-golem1265: func(s: string) -> result<_, string>;
}

world counters {
Expand Down
43 changes: 26 additions & 17 deletions wasm-rpc/src/wasmtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,14 +348,21 @@ async fn decode_param_impl(
Type::Result(ty) => match param {
Value::Result(result) => match result {
Ok(value) => {
let ok_ty = ty.ok().ok_or(EncodingError::ValueMismatch {
details: format!("in {context} could not get ok type"),
})?;
let decoded_value = match value {
Some(v) => Some(
decode_param_impl(v, &ok_ty, resource_store, &format!("{context}.ok"))
Some(v) => {
let ok_ty = ty.ok().ok_or(EncodingError::ValueMismatch {
details: format!("in {context} could not get ok type"),
})?;
Some(
decode_param_impl(
v,
&ok_ty,
resource_store,
&format!("{context}.ok"),
)
.await?,
),
)
}
None => None,
};
match decoded_value {
Expand All @@ -367,19 +374,21 @@ async fn decode_param_impl(
}
}
Err(value) => {
let err_ty = ty.err().ok_or(EncodingError::ValueMismatch {
details: format!("in {context} could not get err type"),
})?;
let decoded_value = match value {
Some(v) => Some(
decode_param_impl(
v,
&err_ty,
resource_store,
&format!("{context}.err"),
Some(v) => {
let err_ty = ty.err().ok_or(EncodingError::ValueMismatch {
details: format!("in {context} could not get err type"),
})?;
Some(
decode_param_impl(
v,
&err_ty,
resource_store,
&format!("{context}.err"),
)
.await?,
)
.await?,
),
}
None => None,
};

Expand Down
Loading