Skip to content

Commit

Permalink
Merge pull request #2125 from fermyon/outbound-redis-runtime-test
Browse files Browse the repository at this point in the history
Outbound Redis runtime test
  • Loading branch information
rylev authored Dec 4, 2023
2 parents ed0c6a2 + ce14ad7 commit 58d580b
Show file tree
Hide file tree
Showing 28 changed files with 272 additions and 853 deletions.
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,9 @@ vergen = { version = "^8.2.1", default-features = false, features = [

[features]
default = ["llm"]
all-tests = ["e2e-tests", "outbound-redis-tests", "config-provider-tests"]
all-tests = ["e2e-tests", "config-provider-tests"]
config-provider-tests = []
e2e-tests = []
outbound-redis-tests = []
llm = ["spin-trigger-http/llm"]
llm-metal = ["llm", "spin-trigger-http/llm-metal"]
llm-cublas = ["llm", "spin-trigger-http/llm-cublas"]
Expand All @@ -119,7 +118,7 @@ reqwest = { version = "0.11", features = ["stream"] }
tracing = { version = "0.1", features = ["log"] }

wasi-common-preview1 = { version = "15.0.0", package = "wasi-common" }
wasmtime = { version = "15.0.0" , features = ["component-model"] }
wasmtime = { version = "15.0.0", features = ["component-model"] }
wasmtime-wasi = { version = "15.0.0", features = ["tokio"] }
wasmtime-wasi-http = "15.0.0"

Expand Down
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,6 @@ test-kv: build
test-sqlite: build
PATH=$$(pwd)/target/release:$$PATH RUST_LOG=$(LOG_LEVEL) cargo test --test spinup_tests --features e2e-tests --no-fail-fast -- spinup_tests::sqlite --nocapture

.PHONY: test-outbound-redis
test-outbound-redis:
RUST_LOG=$(LOG_LEVEL) cargo test --test integration --features outbound-redis-tests --no-fail-fast -- --nocapture

.PHONY: test-config-provider
test-config-provider:
RUST_LOG=$(LOG_LEVEL) cargo test --test integration --features config-provider-tests --no-fail-fast -- integration_tests::config_provider_tests --nocapture
Expand Down
2 changes: 0 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use cargo_target_dep::build_target_dep;
const RUST_HTTP_INTEGRATION_TEST: &str = "tests/http/simple-spin-rust";
const RUST_HTTP_INTEGRATION_ENV_TEST: &str = "tests/http/headers-env-routes-test";
const RUST_HTTP_VAULT_VARIABLES_TEST: &str = "tests/http/vault-variables-test";
const RUST_OUTBOUND_REDIS_INTEGRATION_TEST: &str = "tests/outbound-redis/http-rust-outbound-redis";
const TIMER_TRIGGER_INTEGRATION_TEST: &str = "examples/spin-timer/app-example";
const WASI_HTTP_INTEGRATION_TEST: &str = "examples/wasi-http-rust-streaming-outgoing-body";
const OUTBOUND_HTTP_POST_INTEGRATION_TEST: &str = "examples/http-rust-outbound-post";
Expand Down Expand Up @@ -90,7 +89,6 @@ error: the `wasm32-wasi` target is not installed
cargo_build(RUST_HTTP_INTEGRATION_TEST);
cargo_build(RUST_HTTP_INTEGRATION_ENV_TEST);
cargo_build(RUST_HTTP_VAULT_VARIABLES_TEST);
cargo_build(RUST_OUTBOUND_REDIS_INTEGRATION_TEST);
cargo_build(TIMER_TRIGGER_INTEGRATION_TEST);
cargo_build(WASI_HTTP_INTEGRATION_TEST);
cargo_build(OUTBOUND_HTTP_POST_INTEGRATION_TEST);
Expand Down
9 changes: 8 additions & 1 deletion test-components/Cargo.lock

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

2 changes: 1 addition & 1 deletion test-components/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[workspace]
members = ["sqlite", "helper", "outbound-mysql"]
members = ["sqlite", "helper", "outbound-mysql", "outbound-redis"]
resolver = "2"
2 changes: 1 addition & 1 deletion test-components/helper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ macro_rules! ensure_some {
macro_rules! ensure_matches {
($expr:expr, $($arg:tt)*) => {
if !matches!($expr, $($arg)*) {
$crate::bail!("`{}` did not match `{}`", stringify!($expr), stringify!($($arg)*))
$crate::bail!("`{:?}` did not match `{}`", $expr, stringify!($($arg)*))
}
};
}
Expand Down
Binary file modified test-components/outbound-mysql/component.wasm
Binary file not shown.
10 changes: 10 additions & 0 deletions test-components/outbound-redis/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "outbound-redis"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib"]

[dependencies]
helper = { path = "../helper" }
Binary file added test-components/outbound-redis/component.wasm
Binary file not shown.
126 changes: 126 additions & 0 deletions test-components/outbound-redis/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
use helper::{ensure_eq, ensure_matches, ensure_ok, ensure_some};

const REDIS_ADDRESS_ENV: &str = "REDIS_ADDRESS";

use bindings::fermyon::spin2_0_0::redis;

helper::define_component!(Component);

impl Component {
fn main() -> Result<(), String> {
let address = ensure_ok!(std::env::var(REDIS_ADDRESS_ENV));
let connection = ensure_ok!(redis::Connection::open(&address));

ensure_ok!(connection.set("spin-example-get-set", &b"Eureka!".to_vec()));

let payload = ensure_some!(ensure_ok!(connection.get("spin-example-get-set")));

ensure_eq!(String::from_utf8_lossy(&payload), "Eureka!");

ensure_ok!(connection.set("spin-example-incr", &b"0".to_vec()));

let int_value = ensure_ok!(connection.incr("spin-example-incr"));

ensure_eq!(int_value, 1);

let keys = vec!["spin-example-get-set".into(), "spin-example-incr".into()];

let del_keys = ensure_ok!(connection.del(&keys));

ensure_eq!(del_keys, 2);

ensure_ok!(connection.execute(
"set",
&[
redis::RedisParameter::Binary(b"spin-example".to_vec()),
redis::RedisParameter::Binary(b"Eureka!".to_vec()),
],
));

ensure_ok!(connection.execute(
"append",
&[
redis::RedisParameter::Binary(b"spin-example".to_vec()),
redis::RedisParameter::Binary(b" I've got it!".to_vec()),
],
));

let values = ensure_ok!(connection.execute(
"get",
&[redis::RedisParameter::Binary(b"spin-example".to_vec())]
));

ensure_matches!(
values.as_slice(),
&[redis::RedisResult::Binary(ref b)] if b == b"Eureka! I've got it!"
);

ensure_ok!(connection.execute(
"set",
&[
redis::RedisParameter::Binary(b"int-key".to_vec()),
redis::RedisParameter::Int64(0),
],
));

let values = ensure_ok!(connection.execute(
"incr",
&[redis::RedisParameter::Binary(b"int-key".to_vec())]
));

ensure_matches!(values.as_slice(), &[redis::RedisResult::Int64(1)]);

let values = ensure_ok!(
connection.execute("get", &[redis::RedisParameter::Binary(b"int-key".to_vec())])
);

ensure_matches!(
values.as_slice(),
&[redis::RedisResult::Binary(ref b)] if b == b"1"
);

ensure_ok!(connection.execute("del", &[redis::RedisParameter::Binary(b"foo".to_vec())]));

ensure_ok!(connection.execute(
"sadd",
&[
redis::RedisParameter::Binary(b"foo".to_vec()),
redis::RedisParameter::Binary(b"bar".to_vec()),
redis::RedisParameter::Binary(b"baz".to_vec()),
],
));

let values = ensure_ok!(connection.execute(
"smembers",
&[redis::RedisParameter::Binary(b"foo".to_vec())],
));

ensure_matches!(
values.as_slice(),
&[
redis::RedisResult::Binary(ref bar),
redis::RedisResult::Binary(ref baz)
] if bar == b"bar" && baz == b"baz"
);

ensure_ok!(connection.execute(
"srem",
&[
redis::RedisParameter::Binary(b"foo".to_vec()),
redis::RedisParameter::Binary(b"baz".to_vec()),
],
));

let values = ensure_ok!(connection.execute(
"smembers",
&[redis::RedisParameter::Binary(b"foo".to_vec())]
));

ensure_matches!(
values.as_slice(),
&[redis::RedisResult::Binary(ref bar)] if bar == b"bar"
);

Ok(())
}
}
Binary file modified test-components/sqlite/component.wasm
Binary file not shown.
24 changes: 0 additions & 24 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,6 @@ mod integration_tests {
}
}

#[cfg(feature = "outbound-redis-tests")]
mod outbound_redis_tests {
use super::*;

const RUST_OUTBOUND_REDIS_INTEGRATION_TEST: &str =
"tests/outbound-redis/http-rust-outbound-redis";

#[tokio::test]
async fn test_outbound_redis_rust_local() -> Result<()> {
let s = SpinTestController::with_manifest(
&format!(
"{}/{}",
RUST_OUTBOUND_REDIS_INTEGRATION_TEST, DEFAULT_MANIFEST_LOCATION
),
&[],
&[],
)
.await?;

assert_status(&s, "/test", 204).await?;
Ok(())
}
}

#[tokio::test]
async fn test_simple_rust_local() -> Result<()> {
let s = SpinTestController::with_manifest(
Expand Down
Loading

0 comments on commit 58d580b

Please sign in to comment.