diff --git a/test-templates/auction.wasm b/test-templates/auction.wasm new file mode 100755 index 0000000..fec0f38 Binary files /dev/null and b/test-templates/auction.wasm differ diff --git a/test-templates/auction_registry_composed.wasm b/test-templates/auction_registry_composed.wasm new file mode 100644 index 0000000..b1d2604 Binary files /dev/null and b/test-templates/auction_registry_composed.wasm differ diff --git a/tests/context.rs b/tests/context.rs index f041507..a0bb76c 100644 --- a/tests/context.rs +++ b/tests/context.rs @@ -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, } @@ -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(), diff --git a/tests/context/redis.rs b/tests/context/redis.rs index 10a3f37..ebb2364 100644 --- a/tests/context/redis.rs +++ b/tests/context/redis.rs @@ -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()) diff --git a/tests/context/worker.rs b/tests/context/worker.rs index 810516f..9eed7bb 100644 --- a/tests/context/worker.rs +++ b/tests/context/worker.rs @@ -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"), diff --git a/tests/template.rs b/tests/template.rs index 91bef18..7d3c560 100644 --- a/tests/template.rs +++ b/tests/template.rs @@ -53,7 +53,7 @@ fn template_add_and_find_all( (context, name, cli): (Arc, 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", @@ -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", @@ -103,7 +103,7 @@ fn template_update( (context, name, cli): (Arc, 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", diff --git a/tests/worker.rs b/tests/worker.rs index e48c976..282d9b1 100644 --- a/tests/worker.rs +++ b/tests/worker.rs @@ -52,14 +52,10 @@ fn make(suffix: &str, name: &str, cli: CliLive, context: Arc) -> Ve } pub fn all(context: Arc) -> Vec { - 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", @@ -72,6 +68,12 @@ pub fn all(context: Arc) -> Vec { 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 } @@ -80,7 +82,7 @@ fn make_template( template_name: &str, cli: &CliLive, ) -> Result { - 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", @@ -252,7 +254,7 @@ fn worker_invoke((context, name, cli): (Arc, String, CliLive)) -> R fn worker_connect((context, name, cli): (Arc, 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", @@ -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", @@ -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", @@ -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", @@ -417,3 +419,79 @@ fn worker_simulated_crash( Ok(()) } + +fn auction_example( + (context, name, cli): (Arc, 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::(&[ + "template", + "add", + &cfg.arg('t', "template-name"), + &auction_registry_template_name, + auction_registry_wasm.to_str().unwrap(), + ])? + .template_id; + + let auction = cli + .run::(&[ + "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(()) +}