Skip to content

Commit 6ec0cd5

Browse files
cursoragentjoepio
andcommitted
Fix Iroh wait_for runtime and isolate the two-process sync test.
start_peer is process-global; a prior in-memory start stole the node from the P2P test. wait_for must construct timeout inside block_on. Co-authored-by: joepmeindertsma <joepmeindertsma@gmail.com>
1 parent 1fda3ac commit 6ec0cd5

3 files changed

Lines changed: 8 additions & 12 deletions

File tree

python/src/peer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ async fn recv_change(db: &Db, target: Subject) -> String {
145145
pub(crate) fn wait_for(db: &Db, subject: &str, timeout: f64) -> PyResult<String> {
146146
let target = Subject::from_raw(subject, db.get_base_domain().as_deref()).without_params();
147147
let dur = Duration::from_secs_f64(timeout.max(0.0));
148-
match block_on(tokio::time::timeout(dur, recv_change(db, target))) {
148+
match block_on(async { tokio::time::timeout(dur, recv_change(db, target)).await }) {
149149
Ok(s) => Ok(s),
150150
Err(_) => Err(PyTimeoutError::new_err(format!(
151151
"timed out waiting for {subject}"

python/tests/iroh_peer_child.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ def main() -> None:
2323
"ok": bool(got) and got["name"] == hs["name"],
2424
"imported": report.imported,
2525
"pushed": report.pushed,
26+
"in_sync": report.in_sync,
27+
"peer_name": report.peer_name,
2628
"name": got["name"] if got else None,
2729
"has_drive": store.has(hs["drive"]),
30+
"child_peer": store.peer_id,
2831
}
2932
)
3033
)

python/tests/test_iroh.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,9 @@ def test_wait_for_times_out():
4040
store.wait_for("did:ad:does-not-change", timeout=0.2)
4141

4242

43-
def test_start_peer_returns_node_uri():
44-
store = Store.in_memory()
45-
store.setup("Ada")
46-
store.device_name = "pytest-a"
47-
node = store.start_peer()
48-
assert node.startswith("did:ad:node:")
49-
assert store.peer_id == node
50-
# Idempotent.
51-
assert store.start_peer() == node
52-
53-
5443
def test_two_process_iroh_sync(tmp_path):
44+
# `start_peer` is process-global. This must be the only test in this
45+
# process that starts Iroh, and it must own the store the node serves.
5546
path_a = tmp_path / "a"
5647
path_b = tmp_path / "b"
5748
handshake = tmp_path / "handshake.json"
@@ -61,6 +52,8 @@ def test_two_process_iroh_sync(tmp_path):
6152
setup = store.setup("Ada")
6253
store.device_name = "pytest-parent"
6354
node = store.start_peer()
55+
assert node.startswith("did:ad:node:")
56+
assert store.peer_id == node
6457
note = store.create(urls.FOLDER, name="From A")
6558
store.flush()
6659
handshake.write_text(

0 commit comments

Comments
 (0)