Skip to content
This repository was archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
Merge pull request #629 from thomastaylor312/fix/multiple_nats
Browse files Browse the repository at this point in the history
fix(up): Allows multiple hosts to run without sharing data
  • Loading branch information
thomastaylor312 authored Jul 5, 2023
2 parents b03b21d + d47f2b4 commit 389a702
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/wash-lib/src/start/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub async fn wait_for_server(url: &str, service: &str) -> Result<()> {
loop {
// Magic number: 10 + 1, since we are starting at 1 for humans
if wait_count >= 11 {
anyhow::bail!("Ran out of retries waiting for host to start");
anyhow::bail!("Ran out of retries waiting for {service} to start");
}
match tokio::net::TcpStream::connect(url).await {
Ok(_) => break,
Expand Down
10 changes: 9 additions & 1 deletion crates/wash-lib/src/start/nats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ where
pub struct NatsConfig {
pub host: String,
pub port: u16,
/// The path where the NATS server will store its jetstream data. This must be different for
/// each NATS server you spin up, otherwise they will share stream data
pub store_dir: PathBuf,
pub js_domain: Option<String>,
pub remote_url: Option<String>,
pub credentials: Option<PathBuf>,
Expand All @@ -131,6 +134,7 @@ impl Default for NatsConfig {
NatsConfig {
host: "127.0.0.1".to_string(),
port: 4222,
store_dir: std::env::temp_dir().join("wash-jetstream-4222"),
js_domain: Some("core".to_string()),
remote_url: None,
credentials: None,
Expand Down Expand Up @@ -160,6 +164,7 @@ impl NatsConfig {
NatsConfig {
host: host.to_owned(),
port,
store_dir: std::env::temp_dir().join(format!("wash-jetstream-{}", port)),
js_domain,
remote_url: Some(remote_url),
credentials: Some(credentials),
Expand All @@ -179,6 +184,7 @@ impl NatsConfig {
NatsConfig {
host: host.to_owned(),
port,
store_dir: std::env::temp_dir().join(format!("wash-jetstream-{}", port)),
js_domain,
..Default::default()
}
Expand Down Expand Up @@ -209,10 +215,12 @@ leafnodes {{
r#"
jetstream {{
domain={}
store_dir={:?}
}}
{}
"#,
self.js_domain.unwrap_or_else(|| "core".to_string()),
self.store_dir.as_os_str().to_string_lossy(),
leafnode_section
);
write(path, config).await.map_err(anyhow::Error::from)
Expand Down Expand Up @@ -417,7 +425,7 @@ mod test {
let mut contents = String::new();
credsfile.read_to_string(&mut contents).await?;

assert_eq!(contents, format!("\njetstream {{\n domain={}\n}}\n\nleafnodes {{\n remotes = [\n {{\n url: \"{}\"\n credentials: {:?}\n }}\n ]\n}}\n \n", "core", "connect.ngs.global", creds.to_string_lossy()));
assert_eq!(contents, format!("\njetstream {{\n domain={}\n store_dir={:?}\n}}\n\nleafnodes {{\n remotes = [\n {{\n url: \"{}\"\n credentials: {:?}\n }}\n ]\n}}\n \n", "core", std::env::temp_dir().join("wash-jetstream-4243").display(), "connect.ngs.global", creds.to_string_lossy()));
// A simple check to ensure we are properly escaping quotes, this is unescaped and checks for "\\"
#[cfg(target_family = "windows")]
assert!(creds.to_string_lossy().contains("\\"));
Expand Down
1 change: 1 addition & 0 deletions src/up/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ impl From<NatsOpts> for NatsConfig {
NatsConfig {
host: other.nats_host,
port: other.nats_port,
store_dir: std::env::temp_dir().join(format!("wash-jetstream-{}", other.nats_port)),
js_domain: other.nats_js_domain,
remote_url: other.nats_remote_url,
credentials: other.nats_credsfile,
Expand Down

0 comments on commit 389a702

Please sign in to comment.