Skip to content

Commit

Permalink
test: add resiliency test case
Browse files Browse the repository at this point in the history
Signed-off-by: mikeee <hey@mike.ee>
  • Loading branch information
mikeee committed Apr 19, 2024
1 parent 68e3238 commit d842272
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ path = "examples/query_state/query1.rs"
name = "query_state_q2"
path = "examples/query_state/query2.rs"

[[example]]
name = "resiliency"
path = "examples/resiliency/main.rs"

[[example]]
name = "secrets-bulk"
path = "examples/secrets-bulk/app.rs"
98 changes: 98 additions & 0 deletions examples/resiliency/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
This example validates the resiliency and does not demonstrate any extra
functionality. It is based off the configuration example to connect to the
sidecar and make a call for a configuration item stored in redis.

1. Insert a key with the value `hello` to redis using the following command:


<!-- STEP
name: Insert test configuration item
output_match_mode: substring
expected_stdout_lines:
- 'OK'
background: false
sleep: 5
timeout_seconds: 5
-->

```bash
docker exec dapr_redis redis-cli MSET hello "world"
```

<!-- END_STEP -->

2. Run the example without the sidecar using the following command:

<!-- STEP
name: Run configuration app (expecting a fail)
env:
DAPR_GRPC_PORT: "3500"
DAPR_API_MAX_RETRIES: "10"
DAPR_API_TIMEOUT_MILLISECONDS: "10000"
output_match_mode: substring
expected_stdout_lines:
- ''
expected_stderr_lines:
- 'TransportError'
expected_return_code: 101
background: false
sleep: 30
timeout_seconds: 30
-->

```bash
cargo run --example resiliency
```

<!-- END_STEP -->

The result should be that the request will fail.

3. Run the example without the sidecar (this time in the background)

<!-- STEP
name: Run configuration app (expecting a success eventually)
env:
DAPR_GRPC_PORT: "3500"
DAPR_API_MAX_RETRIES: "10"
DAPR_API_TIMEOUT_MILLISECONDS: "10000"
output_match_mode: substring
expected_stdout_lines:
- '== APP == Configuration value: ConfigurationItem { value: "world"'
background: true
sleep: 30
timeout_seconds: 30
-->

```bash
cargo run --example resiliency
```

<!-- END_STEP -->



4. Run the Dapr sidecar

<!-- STEP
name: Run Dapr sidecar
output_match_mode: substring
expected_stdout_lines:
- ''
background: true
sleep: 10
timeout_seconds: 10
-->

```bash
dapr run --app-id=rustapp --resources-path ../components --dapr-grpc-port 3500
```

<!-- END_STEP -->

The example app should make contact with the Dapr sidecar and the result should
be returned from the configuration request successfully.

```
Configuration value: ConfigurationItem { value: "world", version: "", metadata: {} }
```
31 changes: 31 additions & 0 deletions examples/resiliency/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const CONFIGSTORE_NAME: &str = "configstore";
type DaprClient = dapr::Client<dapr::client::TonicClient>;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Set the Dapr address
let addr = "https://127.0.0.1".to_string();

// Create the client
let mut client = match DaprClient::connect(addr).await {
Ok(client) => {
println!("connected to dapr sidecar");
client
}
Err(error) => {
panic!("failed to connect to dapr sidecar: {:?}", error)
}
};
println!("debug");

let key = String::from("hello");

// get key-value pair in the state store
let response = client
.get_configuration(CONFIGSTORE_NAME, vec![(&key)], None)
.await?;
let val = response.items.get("hello").unwrap();
println!("Configuration value: {val:?}");

Ok(())
}

0 comments on commit d842272

Please sign in to comment.