Skip to content

Commit

Permalink
Remove SharedLocalKubernetesNetTestingConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
ndr-ds committed Dec 3, 2024
1 parent e582750 commit 62e263f
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 137 deletions.
110 changes: 0 additions & 110 deletions linera-service/src/cli_wrappers/local_kubernetes_net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ use linera_base::{
use linera_execution::ResourceControlPolicy;
use tempfile::{tempdir, TempDir};
use tokio::process::Command;
#[cfg(with_testing)]
use {
crate::cli_wrappers::wallet::FaucetOption, linera_base::command::current_binary_parent,
tokio::sync::OnceCell,
};

use crate::cli_wrappers::{
docker::{BuildArg, DockerImage},
Expand All @@ -31,12 +26,6 @@ use crate::cli_wrappers::{
ClientWrapper, LineraNet, LineraNetConfig, Network, OnClientDrop,
};

#[cfg(with_testing)]
static SHARED_LOCAL_KUBERNETES_TESTING_NET: OnceCell<(
Arc<Mutex<LocalKubernetesNet>>,
ClientWrapper,
)> = OnceCell::const_new();

/// The information needed to start a [`LocalKubernetesNet`].
pub struct LocalKubernetesNetConfig {
pub network: Network,
Expand All @@ -51,11 +40,6 @@ pub struct LocalKubernetesNetConfig {
pub policy: ResourceControlPolicy,
}

/// A wrapper of [`LocalKubernetesNetConfig`] to create a shared local Kubernetes network
/// or use an existing one.
#[cfg(with_testing)]
pub struct SharedLocalKubernetesNetTestingConfig(LocalKubernetesNetConfig);

/// A set of Linera validators running locally as native processes.
#[derive(Clone)]
pub struct LocalKubernetesNet {
Expand All @@ -72,41 +56,6 @@ pub struct LocalKubernetesNet {
num_shards: usize,
}

#[cfg(with_testing)]
impl SharedLocalKubernetesNetTestingConfig {
// The second argument is sometimes used locally to use specific binaries for tests.
pub fn new(network: Network, mut binaries: BuildArg) -> Self {
if std::env::var("LINERA_TRY_RELEASE_BINARIES").unwrap_or_default() == "true"
&& matches!(binaries, BuildArg::Build)
{
// For cargo test, current binary should be in debug mode
let current_binary_parent =
current_binary_parent().expect("Fetching current binaries path should not fail");
// But binaries for cluster should be release mode
let binaries_dir = current_binary_parent
.parent()
.expect("Getting parent should not fail")
.join("release");
if binaries_dir.exists() {
// If release exists, use those binaries
binaries = BuildArg::Directory(binaries_dir);
}
}
Self(LocalKubernetesNetConfig {
network,
testing_prng_seed: Some(37),
num_other_initial_chains: 2,
initial_amount: Amount::from_tokens(2000),
num_initial_validators: 4,
num_shards: 4,
binaries,
no_build: false,
docker_image_name: String::from("linera:latest"),
policy: ResourceControlPolicy::devnet(),
})
}
}

#[async_trait]
impl LineraNetConfig for LocalKubernetesNetConfig {
type Net = LocalKubernetesNet;
Expand Down Expand Up @@ -156,65 +105,6 @@ impl LineraNetConfig for LocalKubernetesNetConfig {
}
}

#[cfg(with_testing)]
#[async_trait]
impl LineraNetConfig for SharedLocalKubernetesNetTestingConfig {
type Net = Arc<Mutex<LocalKubernetesNet>>;

async fn instantiate(self) -> Result<(Self::Net, ClientWrapper)> {
let (net, initial_client) = SHARED_LOCAL_KUBERNETES_TESTING_NET
.get_or_init(|| async {
let (net, initial_client) = self
.0
.instantiate()
.await
.expect("Instantiating LocalKubernetesNetConfig should not fail");
(Arc::new(Mutex::new(net)), initial_client)
})
.await;

let mut net = net.clone();
let client = net.make_client().await;
// The tests assume we've created a genesis config with 2
// chains with 10 tokens each.
client.wallet_init(&[], FaucetOption::None).await.unwrap();
for _ in 0..2 {
initial_client
.open_and_assign(&client, Amount::from_tokens(10))
.await
.unwrap();
}

Ok((net, client))
}

async fn policy(&self) -> ResourceControlPolicy {
self.0.policy().await
}
}

#[async_trait]
impl LineraNet for Arc<Mutex<LocalKubernetesNet>> {
async fn ensure_is_running(&mut self) -> Result<()> {
let self_clone = self.clone();
let mut self_lock = self_clone.lock().await;

self_lock.ensure_is_running().await
}

async fn make_client(&mut self) -> ClientWrapper {
let self_clone = self.clone();
let mut self_lock = self_clone.lock().await;

self_lock.make_client().await
}

async fn terminate(&mut self) -> Result<()> {
// Users are responsible for killing the clusters if they want to
Ok(())
}
}

#[async_trait]
impl LineraNet for LocalKubernetesNet {
async fn ensure_is_running(&mut self) -> Result<()> {
Expand Down
Loading

0 comments on commit 62e263f

Please sign in to comment.