Skip to content

Commit faa929c

Browse files
authored
fix: Flaky tests (#40)
## Description - Comments out a test that has `todo!()` and was `#[ignore]`d, but ran in the flaky test action. - Fixes the `Node` builder so it actually uses `self.node_discovery` and `self.secret_key` when set. ## Change checklist - [x] Self-review. - [x] Tests if relevant.
1 parent e52b9e0 commit faa929c

File tree

3 files changed

+78
-71
lines changed

3 files changed

+78
-71
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cli.rs

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,70 +1198,70 @@ impl ImportProgressBar {
11981198

11991199
#[cfg(test)]
12001200
mod tests {
1201-
use super::*;
1202-
1203-
#[tokio::test]
1204-
#[ignore]
1205-
#[allow(unused_variables, unreachable_code, clippy::diverging_sub_expression)]
1206-
async fn test_doc_import() -> Result<()> {
1207-
let temp_dir = tempfile::tempdir().context("tempdir")?;
1208-
1209-
tokio::fs::create_dir_all(temp_dir.path())
1210-
.await
1211-
.context("create dir all")?;
1212-
1213-
let foobar = temp_dir.path().join("foobar");
1214-
tokio::fs::write(foobar, "foobar")
1215-
.await
1216-
.context("write foobar")?;
1217-
let foo = temp_dir.path().join("foo");
1218-
tokio::fs::write(foo, "foo").await.context("write foo")?;
1219-
1220-
let data_dir = tempfile::tempdir()?;
1221-
1222-
// let node = crate::commands::start::start_node(data_dir.path(), None, None).await?;
1223-
// let node = todo!();
1224-
// let client = node.client();
1225-
let docs: docs::Client = todo!();
1226-
let authors = docs.authors();
1227-
let doc = docs.create().await.context("doc create")?;
1228-
let author = authors.create().await.context("author create")?;
1229-
1230-
// set up command, getting iroh node
1231-
let cli = ConsoleEnv::for_console(data_dir.path().to_owned(), &authors)
1232-
.await
1233-
.context("ConsoleEnv")?;
1234-
// let iroh = iroh::client::Iroh::connect_path(data_dir.path())
1235-
// .await
1236-
// .context("rpc connect")?;
1237-
// let iroh = todo!();
1238-
let docs = todo!();
1239-
let blobs = todo!();
1240-
1241-
let command = DocCommands::Import {
1242-
doc: Some(doc.id()),
1243-
author: Some(author),
1244-
prefix: None,
1245-
path: temp_dir.path().to_string_lossy().into(),
1246-
in_place: false,
1247-
no_prompt: true,
1248-
};
1249-
1250-
command
1251-
.run(&docs, &blobs, &cli)
1252-
.await
1253-
.context("DocCommands run")?;
1254-
1255-
let keys: Vec<_> = doc
1256-
.get_many(Query::all())
1257-
.await
1258-
.context("doc get many")?
1259-
.try_collect()
1260-
.await?;
1261-
assert_eq!(2, keys.len());
1262-
1263-
// todo
1264-
// iroh.shutdown(false).await?;
1265-
Ok(())
1266-
}
1201+
// use super::*;
1202+
1203+
// #[tokio::test]
1204+
// #[ignore]
1205+
// #[allow(unused_variables, unreachable_code, clippy::diverging_sub_expression)]
1206+
// async fn test_doc_import() -> Result<()> {
1207+
// let temp_dir = tempfile::tempdir().context("tempdir")?;
1208+
1209+
// tokio::fs::create_dir_all(temp_dir.path())
1210+
// .await
1211+
// .context("create dir all")?;
1212+
1213+
// let foobar = temp_dir.path().join("foobar");
1214+
// tokio::fs::write(foobar, "foobar")
1215+
// .await
1216+
// .context("write foobar")?;
1217+
// let foo = temp_dir.path().join("foo");
1218+
// tokio::fs::write(foo, "foo").await.context("write foo")?;
1219+
1220+
// let data_dir = tempfile::tempdir()?;
1221+
1222+
// // let node = crate::commands::start::start_node(data_dir.path(), None, None).await?;
1223+
// // let node = todo!();
1224+
// // let client = node.client();
1225+
// let docs: docs::Client = todo!();
1226+
// let authors = docs.authors();
1227+
// let doc = docs.create().await.context("doc create")?;
1228+
// let author = authors.create().await.context("author create")?;
1229+
1230+
// // set up command, getting iroh node
1231+
// let cli = ConsoleEnv::for_console(data_dir.path().to_owned(), &authors)
1232+
// .await
1233+
// .context("ConsoleEnv")?;
1234+
// // let iroh = iroh::client::Iroh::connect_path(data_dir.path())
1235+
// // .await
1236+
// // .context("rpc connect")?;
1237+
// // let iroh = todo!();
1238+
// let docs = todo!();
1239+
// let blobs = todo!();
1240+
1241+
// let command = DocCommands::Import {
1242+
// doc: Some(doc.id()),
1243+
// author: Some(author),
1244+
// prefix: None,
1245+
// path: temp_dir.path().to_string_lossy().into(),
1246+
// in_place: false,
1247+
// no_prompt: true,
1248+
// };
1249+
1250+
// command
1251+
// .run(&docs, &blobs, &cli)
1252+
// .await
1253+
// .context("DocCommands run")?;
1254+
1255+
// let keys: Vec<_> = doc
1256+
// .get_many(Query::all())
1257+
// .await
1258+
// .context("doc get many")?
1259+
// .try_collect()
1260+
// .await?;
1261+
// assert_eq!(2, keys.len());
1262+
1263+
// // todo
1264+
// // iroh.shutdown(false).await?;
1265+
// Ok(())
1266+
// }
12671267
}

tests/util.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,19 @@ impl<S: BlobStore> Builder<S> {
127127
let mut builder = iroh::Endpoint::builder()
128128
.bind_addr_v4(addr_v4)
129129
.bind_addr_v6(addr_v6)
130-
.discovery_n0()
131130
.relay_mode(self.relay_mode.clone())
132131
.insecure_skip_relay_cert_verify(self.insecure_skip_relay_cert_verify);
133132
if let Some(dns_resolver) = self.dns_resolver.clone() {
134133
builder = builder.dns_resolver(dns_resolver);
135134
}
135+
if let Some(secret_key) = self.secret_key {
136+
builder = builder.secret_key(secret_key);
137+
}
138+
if let Some(discovery) = self.node_discovery {
139+
builder = builder.discovery(discovery);
140+
} else {
141+
builder = builder.discovery_n0();
142+
}
136143
let endpoint = builder.bind().await?;
137144
let mut router = iroh::protocol::Router::builder(endpoint.clone());
138145
let blobs = Blobs::builder(store.clone()).build(&endpoint);

0 commit comments

Comments
 (0)