Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #67 from golemcloud/rpc-test
Browse files Browse the repository at this point in the history
WASM RPC test case and minor fixes
  • Loading branch information
vigoo committed Feb 16, 2024
2 parents ae58848 + 545f6c1 commit 89526d6
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 18 deletions.
Binary file added test-templates/auction.wasm
Binary file not shown.
Binary file added test-templates/auction_registry_composed.wasm
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct EnvConfig {
pub on_ci: bool,
pub quiet: bool,
pub redis_key_prefix: String,
pub wasi_root: PathBuf,
pub wasm_root: PathBuf,
pub local_golem: bool,
pub db_type: DbType,
}
Expand Down Expand Up @@ -53,7 +53,7 @@ impl EnvConfig {
on_ci: std::env::var("CI").is_ok(),
quiet: std::env::var("QUIET").is_ok(),
redis_key_prefix: std::env::var("REDIS_KEY_PREFIX").unwrap_or("".to_string()),
wasi_root: PathBuf::from(
wasm_root: PathBuf::from(
std::env::var("GOLEM_TEST_TEMPLATES").unwrap_or("../test-templates".to_string()),
),
local_golem: std::env::var("GOLEM_DOCKER_SERVICES").is_err(),
Expand Down
4 changes: 4 additions & 0 deletions tests/context/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ impl<'docker_client> Redis<'docker_client> {
let mut child = Command::new("redis-server")
.arg("--port")
.arg(port.to_string())
.arg("--save")
.arg("")
.arg("--appendonly")
.arg("no")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
Expand Down
3 changes: 3 additions & 0 deletions tests/context/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ impl<'docker_client> WorkerExecutor<'docker_client> {
("GOLEM__REDIS__HOST" , &redis.host),
("GOLEM__REDIS__PORT" , &redis.port.to_string()),
("GOLEM__REDIS__KEY_PREFIX" , &env_config.redis_key_prefix),
("GOLEM__PUBLIC_WORKER_API__HOST" , &golem.host),
("GOLEM__PUBLIC_WORKER_API__PORT" , &golem.grpc_port.to_string()),
("GOLEM__PUBLIC_WORKER_API__ACCESS_TOKEN" , "2A354594-7A63-4091-A46B-CC58D379F677"),
("GOLEM__TEMPLATE_SERVICE__CONFIG__HOST" , &golem.host),
("GOLEM__TEMPLATE_SERVICE__CONFIG__PORT" , &golem.grpc_port.to_string()),
("GOLEM__TEMPLATE_SERVICE__CONFIG__ACCESS_TOKEN" , "2A354594-7A63-4091-A46B-CC58D379F677"),
Expand Down
6 changes: 3 additions & 3 deletions tests/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn template_add_and_find_all(
(context, name, cli): (Arc<ContextInfo>, String, CliLive),
) -> Result<(), Failed> {
let template_name = format!("{name} template add and find all");
let env_service = context.env.wasi_root.join("environment-service.wasm");
let env_service = context.env.wasm_root.join("environment-service.wasm");
let cfg = &cli.config;
let template: TemplateView = cli.run(&[
"template",
Expand All @@ -72,7 +72,7 @@ fn template_add_and_find_by_name(
) -> Result<(), Failed> {
let template_name_other = format!("{name} template add and find by name other");
let template_name = format!("{name} template add and find by name");
let env_service = context.env.wasi_root.join("environment-service.wasm");
let env_service = context.env.wasm_root.join("environment-service.wasm");
let cfg = &cli.config;
let _: TemplateView = cli.run(&[
"template",
Expand Down Expand Up @@ -103,7 +103,7 @@ fn template_update(
(context, name, cli): (Arc<ContextInfo>, String, CliLive),
) -> Result<(), Failed> {
let template_name = format!("{name} template update");
let env_service = context.env.wasi_root.join("environment-service.wasm");
let env_service = context.env.wasm_root.join("environment-service.wasm");
let cfg = &cli.config;
let template: TemplateView = cli.run(&[
"template",
Expand Down
104 changes: 91 additions & 13 deletions tests/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,10 @@ fn make(suffix: &str, name: &str, cli: CliLive, context: Arc<ContextInfo>) -> Ve
}

pub fn all(context: Arc<ContextInfo>) -> Vec<Trial> {
let mut short_args = make(
"_short",
"CLI_short",
CliLive::make(&context.golem_service)
.unwrap()
.with_short_args(),
context.clone(),
);
let short_cli = CliLive::make(&context.golem_service)
.unwrap()
.with_short_args();
let mut short_args = make("_short", "CLI_short", short_cli.clone(), context.clone());

let mut long_args = make(
"_long",
Expand All @@ -72,6 +68,12 @@ pub fn all(context: Arc<ContextInfo>) -> Vec<Trial> {

short_args.append(&mut long_args);

short_args.push(Trial::test_in_context(
"auction_example".to_string(),
(context.clone(), "".to_string(), short_cli),
auction_example,
));

short_args
}

Expand All @@ -80,7 +82,7 @@ fn make_template(
template_name: &str,
cli: &CliLive,
) -> Result<TemplateView, Failed> {
let env_service = context.env.wasi_root.join("environment-service.wasm");
let env_service = context.env.wasm_root.join("environment-service.wasm");
let cfg = &cli.config;
Ok(cli.run(&[
"template",
Expand Down Expand Up @@ -252,7 +254,7 @@ fn worker_invoke((context, name, cli): (Arc<ContextInfo>, String, CliLive)) -> R
fn worker_connect((context, name, cli): (Arc<ContextInfo>, String, CliLive)) -> Result<(), Failed> {
let cfg = &cli.config;

let stdout_service = context.env.wasi_root.join("write-stdout.wasm");
let stdout_service = context.env.wasm_root.join("write-stdout.wasm");
let template: TemplateView = cli.run(&[
"template",
"add",
Expand Down Expand Up @@ -321,7 +323,7 @@ fn worker_connect_failed(
) -> Result<(), Failed> {
let cfg = &cli.config;

let stdout_service = context.env.wasi_root.join("write-stdout.wasm");
let stdout_service = context.env.wasm_root.join("write-stdout.wasm");
let template: TemplateView = cli.run(&[
"template",
"add",
Expand Down Expand Up @@ -353,7 +355,7 @@ fn worker_interrupt(
) -> Result<(), Failed> {
let cfg = &cli.config;

let interruption_service = context.env.wasi_root.join("interruption.wasm");
let interruption_service = context.env.wasm_root.join("interruption.wasm");
let template: TemplateView = cli.run(&[
"template",
"add",
Expand Down Expand Up @@ -388,7 +390,7 @@ fn worker_simulated_crash(
) -> Result<(), Failed> {
let cfg = &cli.config;

let interruption_service = context.env.wasi_root.join("interruption.wasm");
let interruption_service = context.env.wasm_root.join("interruption.wasm");
let template: TemplateView = cli.run(&[
"template",
"add",
Expand Down Expand Up @@ -417,3 +419,79 @@ fn worker_simulated_crash(

Ok(())
}

fn auction_example(
(context, name, cli): (Arc<ContextInfo>, String, CliLive),
) -> Result<(), Failed> {
let auction_registry_wasm = context.env.wasm_root.join("auction_registry_composed.wasm");
let auction_wasm = context.env.wasm_root.join("auction.wasm");
let cfg = &cli.config;

let auction_registry_template_name = format!("{name}_auction_registry");
let auction_template_name = format!("{name}_auction");

let auction_registry = cli
.run::<TemplateView, &str>(&[
"template",
"add",
&cfg.arg('t', "template-name"),
&auction_registry_template_name,
auction_registry_wasm.to_str().unwrap(),
])?
.template_id;

let auction = cli
.run::<TemplateView, &str>(&[
"template",
"add",
&cfg.arg('t', "template-name"),
&auction_template_name,
auction_wasm.to_str().unwrap(),
])?
.template_id;

let worker_name = format!("{name}_auction_registry_1");

let _: VersionedWorkerId = cli.run(&[
"worker",
"add",
&cfg.arg('w', "worker-name"),
&worker_name,
&cfg.arg('T', "template-id"),
&auction_registry,
&cfg.arg('e', "env"),
&format!("AUCTION_TEMPLATE_ID={auction}"),
"",
])?;
let args_key: InvocationKey = cli.run(&[
"worker",
"invocation-key",
&cfg.arg('T', "template-id"),
&auction_registry,
&cfg.arg('w', "worker-name"),
&worker_name,
])?;

for _ in 1..100 {
let args = cli.run_json(&[
"worker",
"invoke-and-await",
&cfg.arg('T', "template-id"),
&auction_registry,
&cfg.arg('w', "worker-name"),
&worker_name,
&cfg.arg('f', "function"),
"auction:registry/api/create-auction",
&cfg.arg('j', "parameters"),
"[\"test-auction\", \"this is a test\", 100.0, 600]",
&cfg.arg('k', "invocation-key"),
&args_key.0,
])?;
assert!(args
.as_array()
.and_then(|arr| arr[0].as_object().map(|obj| obj.contains_key("auction-id")))
.unwrap_or(false));
}

Ok(())
}

0 comments on commit 89526d6

Please sign in to comment.