Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 37 additions & 26 deletions libdd-data-pipeline/src/agent_info/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub async fn fetch_info_with_state<C: HttpClientCapability + SleepCapability>(
/// let agent_info = libdd_data_pipeline::agent_info::fetch_info::<NativeCapabilities>(&endpoint)
/// .await
/// .unwrap();
/// println!("Agent version is {}", agent_info.info.version.unwrap());
/// println!("Agent version is {:?}", agent_info.info.version);
/// # Ok(())
/// # }
/// ```
Expand Down Expand Up @@ -180,10 +180,7 @@ async fn fetch_and_hash_response<C: HttpClientCapability + SleepCapability>(
///
/// // Access the info
/// if let Some(agent_info) = agent_info_arc.as_ref() {
/// println!(
/// "Agent version is {}",
/// agent_info.info.version.as_ref().unwrap()
/// );
/// println!("Agent version is {:?}", agent_info.info.version);
/// }
/// # Ok(())
/// # }
Expand Down Expand Up @@ -366,6 +363,7 @@ impl ResponseObserver {
mod single_threaded_tests {
use super::*;
use crate::agent_info;
use crate::agent_info::schema::AgentVersion;
use httpmock::prelude::*;
use libdd_capabilities_impl::NativeCapabilities;
use libdd_shared_runtime::SharedRuntime;
Expand Down Expand Up @@ -600,7 +598,7 @@ mod single_threaded_tests {
when.path("/info");
then.status(200)
.header("content-type", "application/json")
.body(r#"{"version":"1"}"#);
.body(r#"{"version":"7.65.0"}"#);
});
let endpoint = Endpoint::from_url(server.url("/info").parse().unwrap());
let (fetcher, _response_observer) = AgentInfoFetcher::<NativeCapabilities>::new(
Expand All @@ -626,17 +624,24 @@ mod single_threaded_tests {
.unwrap()
.info
.version
.clone()
.unwrap();
assert_eq!(version_1, "1");
.clone();
assert_eq!(
version_1,
Some(AgentVersion {
major: 7,
minor: 65,
patch: 0,
metadata: None,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you are testing metadata anywhere?

})
);

// Update the info endpoint
mock_v1.delete();
let mock_v2 = server.mock(|when, then| {
when.path("/info");
then.status(200)
.header("content-type", "application/json")
.body(r#"{"version":"2"}"#);
.body(r#"{"version":"7.66.0-rc.1+linux"}"#);
});

// Wait for second fetch
Expand All @@ -659,10 +664,17 @@ mod single_threaded_tests {
.unwrap()
.info
.version
.clone()
.unwrap();
.clone();
if version_2 != version_1 {
assert_eq!(version_2, "2");
assert_eq!(
version_2,
Some(AgentVersion {
major: 7,
minor: 66,
patch: 0,
metadata: Some("-rc.1+linux".to_string()),
})
);
break;
}
std::thread::sleep(Duration::from_millis(100));
Expand All @@ -677,13 +689,13 @@ mod single_threaded_tests {
when.path("/info");
then.status(200)
.header("content-type", "application/json")
.body(r#"{"version":"triggered"}"#);
.body(r#"{"version":"7.66.0"}"#);
});

// Populate the cache with initial state
AGENT_INFO_CACHE.store(Some(Arc::new(AgentInfo {
state_hash: "old_state".to_string(),
info: serde_json::from_str(r#"{"version":"old"}"#).unwrap(),
info: serde_json::from_str(r#"{"version":"7.65.0"}"#).unwrap(),
})));

let endpoint = Endpoint::from_url(server.url("/info").parse().unwrap());
Expand Down Expand Up @@ -719,7 +731,7 @@ mod single_threaded_tests {

// Wait for the cache to be updated with proper timeout
let mut attempts = 0;
let expected_hash = calculate_hash(r#"{"version":"triggered"}"#);
let expected_hash = calculate_hash(r#"{"version":"7.66.0"}"#);

while attempts < MAX_ATTEMPTS {
let updated_info = AGENT_INFO_CACHE.load();
Expand All @@ -737,14 +749,13 @@ mod single_threaded_tests {
assert!(updated_info.is_some());
assert_eq!(updated_info.as_ref().unwrap().state_hash, expected_hash);
assert_eq!(
updated_info
.as_ref()
.unwrap()
.info
.version
.as_ref()
.unwrap(),
"triggered"
updated_info.as_ref().unwrap().info.version,
Some(AgentVersion {
major: 7,
minor: 66,
patch: 0,
metadata: None,
})
);
}

Expand All @@ -756,10 +767,10 @@ mod single_threaded_tests {
when.path("/info");
then.status(200)
.header("content-type", "application/json")
.body(r#"{"version":"same"}"#);
.body(r#"{"version":"7.65.0"}"#);
});

let same_json = r#"{"version":"same"}"#;
let same_json = r#"{"version":"7.65.0"}"#;
let same_hash = calculate_hash(same_json);

// Populate the cache with the same state
Expand Down
Loading
Loading