Skip to content

Commit 7fc22a0

Browse files
committed
Fix last remaining test
1 parent a2a8c64 commit 7fc22a0

File tree

4 files changed

+140
-119
lines changed

4 files changed

+140
-119
lines changed

tests/client.rs

Lines changed: 30 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::time::Duration;
2+
13
use anyhow::{Context, Result};
24
use futures_util::TryStreamExt;
35
use iroh_blobs::{
@@ -6,6 +8,7 @@ use iroh_blobs::{
68
};
79
use iroh_docs::store::Query;
810
use rand::RngCore;
11+
use testresult::TestResult;
912
use tokio::io::AsyncWriteExt;
1013
use util::Node;
1114

@@ -153,128 +156,86 @@ async fn test_default_author_memory() -> Result<()> {
153156
Ok(())
154157
}
155158

156-
#[cfg(feature = "fs-store")]
157159
#[tokio::test]
158-
async fn test_default_author_persist() -> Result<()> {
159-
use crate::util::path::IrohPaths;
160-
160+
async fn test_default_author_persist() -> TestResult<()> {
161161
let _guard = iroh_test::logging::setup();
162162

163163
let iroh_root_dir = tempfile::TempDir::new().unwrap();
164164
let iroh_root = iroh_root_dir.path();
165165

166166
// check that the default author exists and cannot be deleted.
167167
let default_author = {
168-
let iroh = Node::persistent(iroh_root)
169-
.await
170-
.unwrap()
171-
.enable_docs()
172-
.spawn()
173-
.await
174-
.unwrap();
175-
let author = iroh.authors().default().await.unwrap();
176-
assert!(iroh.authors().export(author).await.unwrap().is_some());
177-
assert!(iroh.authors().delete(author).await.is_err());
168+
let iroh = Node::persistent(iroh_root).spawn().await.unwrap();
169+
let author = iroh.docs().author_default().await.unwrap();
170+
assert!(iroh.docs().author_export(author).await.unwrap().is_some());
171+
assert!(iroh.docs().author_delete(author).await.is_err());
178172
iroh.shutdown().await.unwrap();
179173
author
180174
};
181175

182176
// check that the default author is persisted across restarts.
183177
{
184-
let iroh = Node::persistent(iroh_root)
185-
.await
186-
.unwrap()
187-
.enable_docs()
188-
.spawn()
189-
.await
190-
.unwrap();
191-
let author = iroh.authors().default().await.unwrap();
178+
let iroh = Node::persistent(iroh_root).spawn().await.unwrap();
179+
let author = iroh.docs().author_default().await.unwrap();
192180
assert_eq!(author, default_author);
193-
assert!(iroh.authors().export(author).await.unwrap().is_some());
194-
assert!(iroh.authors().delete(author).await.is_err());
181+
assert!(iroh.docs().author_export(author).await.unwrap().is_some());
182+
assert!(iroh.docs().author_delete(author).await.is_err());
195183
iroh.shutdown().await.unwrap();
196184
};
197185

198186
// check that a new default author is created if the default author file is deleted
199187
// manually.
200188
let default_author = {
201-
tokio::fs::remove_file(IrohPaths::DefaultAuthor.with_root(iroh_root))
189+
tokio::fs::remove_file(iroh_root.join("default-author"))
202190
.await
203191
.unwrap();
204-
let iroh = Node::persistent(iroh_root)
205-
.await
206-
.unwrap()
207-
.enable_docs()
208-
.spawn()
209-
.await
210-
.unwrap();
211-
let author = iroh.authors().default().await.unwrap();
192+
let iroh = Node::persistent(iroh_root).spawn().await.unwrap();
193+
let author = iroh.docs().author_default().await.unwrap();
212194
assert!(author != default_author);
213-
assert!(iroh.authors().export(author).await.unwrap().is_some());
214-
assert!(iroh.authors().delete(author).await.is_err());
195+
assert!(iroh.docs().author_export(author).await.unwrap().is_some());
196+
assert!(iroh.docs().author_delete(author).await.is_err());
215197
iroh.shutdown().await.unwrap();
216198
author
217199
};
218200

219201
// check that the node fails to start if the default author is missing from the docs store.
220202
{
221203
let mut docs_store =
222-
iroh_docs::store::fs::Store::persistent(IrohPaths::DocsDatabase.with_root(iroh_root))
223-
.unwrap();
204+
iroh_docs::store::fs::Store::persistent(iroh_root.join("docs.redb")).unwrap();
224205
docs_store.delete_author(default_author).unwrap();
225206
docs_store.flush().unwrap();
226207
drop(docs_store);
227-
let iroh = Node::persistent(iroh_root)
228-
.await
229-
.unwrap()
230-
.enable_docs()
231-
.spawn()
232-
.await;
208+
let iroh = Node::persistent(iroh_root).spawn().await;
233209
assert!(iroh.is_err());
234210

235211
// somehow the blob store is not shutdown correctly (yet?) on macos.
236212
// so we give it some time until we find a proper fix.
237213
#[cfg(target_os = "macos")]
238214
tokio::time::sleep(Duration::from_secs(1)).await;
239215

240-
tokio::fs::remove_file(IrohPaths::DefaultAuthor.with_root(iroh_root))
216+
tokio::fs::remove_file(iroh_root.join("default-author"))
241217
.await
242218
.unwrap();
243219
drop(iroh);
244-
let iroh = Node::persistent(iroh_root)
245-
.await
246-
.unwrap()
247-
.enable_docs()
248-
.spawn()
249-
.await;
250-
assert!(iroh.is_ok());
220+
let iroh = Node::persistent(iroh_root).spawn().await;
221+
if let Err(cause) = iroh.as_ref() {
222+
panic!("failed to start node: {:?}", cause);
223+
}
251224
iroh.unwrap().shutdown().await.unwrap();
252225
}
253226

254227
// check that the default author can be set manually and is persisted.
255228
let default_author = {
256-
let iroh = Node::persistent(iroh_root)
257-
.await
258-
.unwrap()
259-
.enable_docs()
260-
.spawn()
261-
.await
262-
.unwrap();
263-
let author = iroh.authors().create().await.unwrap();
264-
iroh.authors().set_default(author).await.unwrap();
265-
assert_eq!(iroh.authors().default().await.unwrap(), author);
229+
let iroh = Node::persistent(iroh_root).spawn().await.unwrap();
230+
let author = iroh.docs().author_create().await.unwrap();
231+
iroh.docs().author_set_default(author).await.unwrap();
232+
assert_eq!(iroh.docs().author_default().await.unwrap(), author);
266233
iroh.shutdown().await.unwrap();
267234
author
268235
};
269236
{
270-
let iroh = Node::persistent(iroh_root)
271-
.await
272-
.unwrap()
273-
.enable_docs()
274-
.spawn()
275-
.await
276-
.unwrap();
277-
assert_eq!(iroh.authors().default().await.unwrap(), default_author);
237+
let iroh = Node::persistent(iroh_root).spawn().await.unwrap();
238+
assert_eq!(iroh.docs().author_default().await.unwrap(), default_author);
278239
iroh.shutdown().await.unwrap();
279240
}
280241

tests/gc.rs

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![cfg(feature = "rpc")]
22
use std::{
33
io::{Cursor, Write},
4+
path::PathBuf,
45
time::Duration,
56
};
67

@@ -14,7 +15,7 @@ use iroh_blobs::{
1415
BlobFormat, HashAndFormat, IROH_BLOCK_SIZE,
1516
};
1617
use rand::RngCore;
17-
use util::{Builder, Node};
18+
use util::Node;
1819

1920
mod util;
2021

@@ -39,15 +40,34 @@ pub fn simulate_remote(data: &[u8]) -> (blake3::Hash, Cursor<Bytes>) {
3940
}
4041

4142
/// Wrap a bao store in a node that has gc enabled.
42-
async fn wrap_in_node<S>(
43-
bao_store: S,
43+
async fn mem_node(
4444
gc_period: Duration,
45-
) -> (Node<S>, async_channel::Receiver<()>)
46-
where
47-
S: iroh_blobs::store::Store,
48-
{
45+
) -> (
46+
Node<iroh_blobs::store::mem::Store>,
47+
async_channel::Receiver<()>,
48+
) {
4949
let (gc_send, gc_recv) = async_channel::unbounded();
50-
let node = Builder::new(bao_store)
50+
let node = Node::memory()
51+
.gc_interval(Some(gc_period))
52+
.register_gc_done_cb(Box::new(move || {
53+
gc_send.send_blocking(()).ok();
54+
}))
55+
.spawn()
56+
.await
57+
.unwrap();
58+
(node, gc_recv)
59+
}
60+
61+
/// Wrap a bao store in a node that has gc enabled.
62+
async fn persistent_node(
63+
path: PathBuf,
64+
gc_period: Duration,
65+
) -> (
66+
Node<iroh_blobs::store::fs::Store>,
67+
async_channel::Receiver<()>,
68+
) {
69+
let (gc_send, gc_recv) = async_channel::unbounded();
70+
let node = Node::persistent(path)
5171
.gc_interval(Some(gc_period))
5272
.register_gc_done_cb(Box::new(move || {
5373
gc_send.send_blocking(()).ok();
@@ -63,9 +83,9 @@ async fn gc_test_node() -> (
6383
iroh_blobs::store::mem::Store,
6484
async_channel::Receiver<()>,
6585
) {
66-
let bao_store = iroh_blobs::store::mem::Store::new();
67-
let (node, gc_recv) = wrap_in_node(bao_store.clone(), Duration::from_millis(500)).await;
68-
(node, bao_store, gc_recv)
86+
let (node, gc_recv) = mem_node(Duration::from_millis(500)).await;
87+
let store = node.blob_store().clone();
88+
(node, store, gc_recv)
6989
}
7090

7191
async fn step(evs: &async_channel::Receiver<()>) {
@@ -230,8 +250,8 @@ mod file {
230250
async fn redb_doc_import_stress() -> Result<()> {
231251
let _ = tracing_subscriber::fmt::try_init();
232252
let dir = testdir!();
233-
let bao_store = iroh_blobs::store::fs::Store::load(dir.join("store")).await?;
234-
let (node, _) = wrap_in_node(bao_store.clone(), Duration::from_secs(10)).await;
253+
let (node, _) = persistent_node(dir.join("store"), Duration::from_secs(10)).await;
254+
let bao_store = node.blob_store().clone();
235255
let client = node.client();
236256
let doc = client.docs().create().await?;
237257
let author = client.docs().author_create().await?;
@@ -272,9 +292,8 @@ mod file {
272292
let dir = testdir!();
273293
let path = data_path(dir.clone());
274294
let outboard_path = outboard_path(dir.clone());
275-
276-
let bao_store = iroh_blobs::store::fs::Store::load(dir.clone()).await?;
277-
let (node, evs) = wrap_in_node(bao_store.clone(), Duration::from_millis(100)).await;
295+
let (node, evs) = persistent_node(dir.clone(), Duration::from_millis(100)).await;
296+
let bao_store = node.blob_store().clone();
278297
let data1 = create_test_data(10000000);
279298
let tt1 = bao_store
280299
.import_bytes(data1.clone(), BlobFormat::Raw)
@@ -434,8 +453,8 @@ mod file {
434453
let path = data_path(dir.clone());
435454
let outboard_path = outboard_path(dir.clone());
436455

437-
let bao_store = iroh_blobs::store::fs::Store::load(dir.clone()).await?;
438-
let (node, evs) = wrap_in_node(bao_store.clone(), Duration::from_millis(10)).await;
456+
let (node, evs) = persistent_node(dir.clone(), Duration::from_millis(10)).await;
457+
let bao_store = node.blob_store().clone();
439458

440459
let data1: Bytes = create_test_data(10000000);
441460
let (_entry, tt1) = simulate_download_partial(&bao_store, data1.clone()).await?;
@@ -465,8 +484,8 @@ mod file {
465484
let _ = tracing_subscriber::fmt::try_init();
466485
let dir = testdir!();
467486

468-
let bao_store = iroh_blobs::store::fs::Store::load(dir.clone()).await?;
469-
let (node, evs) = wrap_in_node(bao_store.clone(), Duration::from_secs(1)).await;
487+
let (node, evs) = persistent_node(dir.clone(), Duration::from_secs(1)).await;
488+
let bao_store = node.blob_store().clone();
470489

471490
let mut deleted = Vec::new();
472491
let mut live = Vec::new();

tests/sync.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,6 @@ async fn sync_restart_node() -> Result<()> {
595595
let secret_key_1 = SecretKey::generate_with_rng(&mut rng);
596596

597597
let node1 = Node::persistent(&node1_dir)
598-
.await?
599598
.secret_key(secret_key_1.clone())
600599
.insecure_skip_relay_cert_verify(true)
601600
.relay_mode(RelayMode::Custom(relay_map.clone()))
@@ -662,7 +661,6 @@ async fn sync_restart_node() -> Result<()> {
662661

663662
info!(me = id1.fmt_short(), "node1 respawn");
664663
let node1 = Node::persistent(&node1_dir)
665-
.await?
666664
.secret_key(secret_key_1.clone())
667665
.insecure_skip_relay_cert_verify(true)
668666
.relay_mode(RelayMode::Custom(relay_map.clone()))

0 commit comments

Comments
 (0)