generated from amazon-archives/__template_Apache-2.0
-
Couldn't load subscription status.
- Fork 38
Add caching integration tests #138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
reyhankoyun
wants to merge
12
commits into
aws:main
Choose a base branch
from
reyhankoyun:caching-tests-clean
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+105
−3
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b63c4fc
Add comprehensive caching integration tests
reyhankoyun 3f073a4
Refactor integration tests: categorize and secure workflow
reyhankoyun 6cea869
Remove the safe-to-test label automatically (#141)
simonmarty 0b0e456
Merge branch 'main' into caching-tests-clean
simonmarty 34f8cd8
Remove the safe-to-test label automatically (#141)
simonmarty b9aa52a
Merge branch 'main' into caching-tests-clean
simonmarty de875e6
Remove the safe-to-test label automatically (#141)
simonmarty 3729be7
Merge branch 'main' into caching-tests-clean
simonmarty a9849c7
Update integration-tests.yml
simonmarty 019acf2
Merge branch 'main' into caching-tests-clean
simonmarty 796fb91
Merge branch 'main' into caching-tests-clean
simonmarty edfcb6f
Merge branch 'main' into caching-tests-clean
simonmarty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| mod common; | ||
|
|
||
| use common::*; | ||
| use std::time::Duration; | ||
|
|
||
| #[tokio::test] | ||
| async fn test_cache_after_secret_update() { | ||
| let secrets = TestSecrets::setup().await; | ||
| let secret_name = secrets.secret_name(SecretType::Basic); | ||
|
|
||
| let agent = AgentProcess::start().await; | ||
|
|
||
| // First request - populate cache with original value | ||
| let query = AgentQueryBuilder::default() | ||
| .secret_id(&secret_name) | ||
| .build() | ||
| .unwrap(); | ||
| let response1 = agent.make_request(&query).await; | ||
| let json1: serde_json::Value = serde_json::from_str(&response1).unwrap(); | ||
| let original_secret = json1["SecretString"].as_str().unwrap(); | ||
| assert!(original_secret.contains("testuser")); | ||
|
|
||
| // Update the secret in AWS | ||
| let config = aws_config::load_defaults(aws_config::BehaviorVersion::latest()).await; | ||
| let client = aws_sdk_secretsmanager::Client::new(&config); | ||
|
|
||
| let updated_secret_value = r#"{"username":"updateduser","password":"updatedpass456"}"#; | ||
| client | ||
| .update_secret() | ||
| .secret_id(&secret_name) | ||
| .secret_string(updated_secret_value) | ||
| .send() | ||
| .await | ||
| .expect("Failed to update secret"); | ||
|
|
||
| // Wait a moment for the update to propagate | ||
| tokio::time::sleep(Duration::from_secs(2)).await; | ||
|
|
||
| // Second request without refreshNow - should return stale cached value | ||
| let response2 = agent.make_request(&query).await; | ||
| let json2: serde_json::Value = serde_json::from_str(&response2).unwrap(); | ||
| let cached_secret = json2["SecretString"].as_str().unwrap(); | ||
|
|
||
| // Should still have the old value from cache | ||
| assert!(cached_secret.contains("testuser")); | ||
| assert!(!cached_secret.contains("updateduser")); | ||
|
|
||
| // Third request with refreshNow=true - should get fresh value | ||
| let refresh_query = AgentQueryBuilder::default() | ||
| .secret_id(&secret_name) | ||
| .refresh_now(true) | ||
| .build() | ||
| .unwrap(); | ||
| let response3 = agent.make_request(&refresh_query).await; | ||
| let json3: serde_json::Value = serde_json::from_str(&response3).unwrap(); | ||
| let fresh_secret = json3["SecretString"].as_str().unwrap(); | ||
|
|
||
| // Should now have the updated value | ||
| assert!(fresh_secret.contains("updateduser")); | ||
| assert!(!fresh_secret.contains("testuser")); | ||
|
|
||
| // Fourth request without refreshNow - cache should now have updated value | ||
| let response4 = agent.make_request(&query).await; | ||
| let json4: serde_json::Value = serde_json::from_str(&response4).unwrap(); | ||
| let updated_cached_secret = json4["SecretString"].as_str().unwrap(); | ||
|
|
||
| // Cache should now contain the updated value | ||
| assert!(updated_cached_secret.contains("updateduser")); | ||
| assert!(!updated_cached_secret.contains("testuser")); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_real_ttl_expiration_timing() { | ||
| let secrets = TestSecrets::setup().await; | ||
| let secret_name = secrets.secret_name(SecretType::Basic); | ||
|
|
||
| // Start agent with short TTL (3 seconds) for faster testing | ||
| let agent = AgentProcess::start_with_config(2775, 3).await; | ||
|
|
||
| let query = AgentQueryBuilder::default() | ||
| .secret_id(&secret_name) | ||
| .build() | ||
| .unwrap(); | ||
|
|
||
| // First request - populate cache | ||
| let response1 = agent.make_request(&query).await; | ||
| let json1: serde_json::Value = serde_json::from_str(&response1).unwrap(); | ||
| assert!(json1["SecretString"].as_str().unwrap().contains("testuser")); | ||
|
|
||
| // Second request immediately - should hit cache | ||
| let response2 = agent.make_request(&query).await; | ||
| let json2: serde_json::Value = serde_json::from_str(&response2).unwrap(); | ||
| assert_eq!(json1["VersionId"], json2["VersionId"]); | ||
|
|
||
| // Wait for TTL to expire (3 seconds + buffer) | ||
| tokio::time::sleep(Duration::from_secs(4)).await; | ||
|
|
||
| // Third request after TTL expiry - should fetch from AWS again | ||
| let response3 = agent.make_request(&query).await; | ||
| let json3: serde_json::Value = serde_json::from_str(&response3).unwrap(); | ||
|
|
||
| // Should still get valid response after TTL expiry | ||
| assert!(json3["SecretString"].as_str().unwrap().contains("testuser")); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How are we validating that SMA fetch the data from aws request and cache refreshed. |
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of creating the secrets with pre defined name. can we update the setup to take secrets name prefix as input.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are creating multiple secrets in setup, do we need that for all the integration test? or for most of the test we just need single secrets