Skip to content

Commit 46810ef

Browse files
test(k8s): Increase GC period (#1073)
1 parent ce5f20c commit 46810ef

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

agent-control/tests/common/agent_control.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ use newrelic_agent_control::values::file::YAMLConfigRepositoryFile;
1111
use std::sync::Arc;
1212
use std::time::Duration;
1313

14+
pub const K8S_GC_INTERVAL: Duration = Duration::from_secs(5);
15+
1416
/// Starts the agent-control in a separate thread. The agent-control will be stopped when the `StartedAgentControl` is dropped.
1517
/// Take into account that some of the logic from main is not present here.
1618
pub fn start_agent_control_with_custom_config(base_paths: BasePaths) -> StartedAgentControl {
@@ -30,8 +32,8 @@ pub fn start_agent_control_with_custom_config(base_paths: BasePaths) -> StartedA
3032

3133
let agent_control_config = config_storer.load().unwrap();
3234

33-
let opamp_poll_interval = Duration::from_secs(2);
34-
let garbage_collector_interval = Duration::from_secs(1);
35+
let opamp_poll_interval = Duration::from_secs(10);
36+
let garbage_collector_interval = K8S_GC_INTERVAL;
3537
// TODO - Temporal solution until https://new-relic.atlassian.net/browse/NR-343594 is done.
3638
// There is a current issue with the diff computation the GC does in order to collect agents. If a new agent is added and removed
3739
// before the GC process it, the resources will never be collected.

agent-control/tests/k8s/scenarios/cr_based_agents.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::common::agent_control::K8S_GC_INTERVAL;
12
use crate::k8s::tools::agent_control::BAR_CR_AGENT_TYPE_PATH;
23
use crate::k8s::tools::k8s_api::check_config_map_exist;
34
use crate::k8s::tools::test_crd::{create_crd, delete_crd, Foo};
@@ -20,6 +21,7 @@ use kube::{Api, CustomResource, CustomResourceExt};
2021
use newrelic_agent_control::agent_control::config::AgentID;
2122
use schemars::JsonSchema;
2223
use serde::{Deserialize, Serialize};
24+
use std::ops::Add;
2325
use std::time::Duration;
2426
use tempfile::tempdir;
2527

@@ -77,8 +79,12 @@ agents:
7779
Ok(())
7880
});
7981

80-
// Asserts the agent resources are garbage collected
82+
// This function is used to wait for the k8s garbage collector to run.
83+
// It is used in tests to ensure that the garbage collector has run before checking the state of the system.
84+
// This is a HACK until we address the GC refactor.
85+
std::thread::sleep(K8S_GC_INTERVAL.add(Duration::from_millis(100)));
8186

87+
// Asserts the agent resources are garbage collected
8288
server.set_config_response(
8389
instance_id.clone(),
8490
ConfigResponse::from(

0 commit comments

Comments
 (0)