Skip to content

Commit

Permalink
test restore of state when implementing wasi:http/incoming-handler
Browse files Browse the repository at this point in the history
  • Loading branch information
mschuwalow committed Jan 20, 2025
1 parent 14105cb commit 5b5e821
Show file tree
Hide file tree
Showing 43 changed files with 11,062 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ exclude = [
"test-components/variant-service",
"test-components/wasi-http-incoming-request-handler",
"test-components/wasi-http-incoming-request-handler-echo",
"test-components/wasi-http-incoming-request-handler-state",
"test-components/write-stderr",
"test-components/write-stdout",
]
Expand Down
130 changes: 130 additions & 0 deletions golem-worker-executor-base/tests/wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2032,3 +2032,133 @@ async fn wasi_incoming_request_handler_echo(
])
);
}

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

let component_id = executor
.store_component("wasi-http-incoming-request-handler-state")
.await;

let worker_id = executor
.start_worker(&component_id, "wasi-http-incoming-request-handler-state-1")
.await;

let args_put: Value = Value::Record(vec![
Value::String("http://localhost:8000".to_string()),
Value::Variant {
case_idx: 3,
case_value: None,
},
Value::List(vec![]),
Value::Option(Some(Box::new(Value::Record(vec![
Value::List(
"1".to_string()
.into_bytes()
.into_iter()
.map(Value::U8)
.collect(),
),
Value::Option(None),
])))),
]);

let args_get: Value = Value::Record(vec![
Value::String("http://localhost:8000".to_string()),
Value::Variant {
case_idx: 0,
case_value: None,
},
Value::List(vec![]),
Value::Option(None),
]);

let result1 = executor
.invoke_and_await(
&worker_id,
"golem:http/incoming-handler.{handle}",
vec![args_put],
)
.await
.unwrap();

let result2 = executor
.invoke_and_await(
&worker_id,
"golem:http/incoming-handler.{handle}",
vec![args_get.clone()],
)
.await
.unwrap();

drop(executor);

check!(result1.len() == 1);
check!(
result1[0]
== Value::Record(vec![
Value::U16(200),
Value::List(vec![]),
Value::Option(None)
])
);

check!(result2.len() == 1);
check!(
result2[0]
== Value::Record(vec![
Value::U16(200),
Value::List(vec![]),
Value::Option(Some(Box::new(Value::Record(vec![
Value::List(
"1".to_string()
.into_bytes()
.into_iter()
.map(Value::U8)
.collect()
),
Value::Option(None)
]))))
])
);

// restart executor and check whether we are restoring the state
let executor = start(deps, &context).await.unwrap();

let result3 = executor
.invoke_and_await(
&worker_id,
"golem:http/incoming-handler.{handle}",
vec![args_get.clone()],
)
.await
.unwrap();

drop(executor);

check!(result3.len() == 1);
check!(
result3[0]
== Value::Record(vec![
Value::U16(200),
Value::List(vec![]),
Value::Option(Some(Box::new(Value::Record(vec![
Value::List(
"1".to_string()
.into_bytes()
.into_iter()
.map(Value::U8)
.collect()
),
Value::Option(None)
]))))
])
);
}
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "wasi-http-incoming-request-handler-state"
version = "0.1.0"
edition = "2021"
publish = false

[lib]
path = "src/lib.rs"
crate-type = ["cdylib"]

[dependencies]
wit-bindgen-rt = { version = "0.37.0", features = ["bitflags"] }

[package.metadata.component]
package = "golem:handler"
proxy = true

[package.metadata.component.target.dependencies]
"wasi:cli" = { path = "wit/deps/cli" }
"wasi:clocks" = { path = "wit/deps/clocks" }
"wasi:filesystem" = { path = "wit/deps/filesystem" }
"wasi:http" = { path = "wit/deps/http" }
"wasi:io" = { path = "wit/deps/io" }
"wasi:random" = { path = "wit/deps/random" }
"wasi:sockets" = { path = "wit/deps/sockets" }
Loading

0 comments on commit 5b5e821

Please sign in to comment.