Skip to content

Commit 0168705

Browse files
committed
fix: Unbreak test
1 parent 0313dc8 commit 0168705

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

tests/mdns.rs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ use wot_td::extend::ExtendableThing;
1212
async fn run_servient() {
1313
let servient = Servient::builder("TestThing")
1414
.finish_extend()
15-
.http_bind("127.0.0.1:8080".parse().unwrap())
15+
.http_bind("0.0.0.0:8080".parse().unwrap())
1616
.build_servient()
1717
.unwrap();
1818

19-
eprintln!("Listening to 127.0.0.1:8080");
19+
eprintln!("Listening to 0.0.0.0:8080");
2020

2121
let _ = tokio::time::timeout(Duration::from_secs(30), async {
2222
servient.serve().await.unwrap()
@@ -43,37 +43,42 @@ impl ExtendableThing for A {
4343
async fn discoverer() -> Result<(), Box<dyn std::error::Error>> {
4444
let local = task::LocalSet::new();
4545

46+
std::thread::spawn(move || {
47+
let rt = tokio::runtime::Builder::new_current_thread()
48+
.enable_all()
49+
.build()
50+
.unwrap();
51+
52+
rt.block_on(run_servient());
53+
});
54+
4655
local
4756
.run_until(async {
48-
task::spawn_local(async {
49-
run_servient().await;
50-
});
51-
5257
task::spawn_local(async {
5358
let d = Discoverer::new().unwrap();
5459

55-
let t = std::pin::pin!(d.stream().unwrap())
56-
.next()
57-
.await
58-
.unwrap()
59-
.unwrap();
60+
let t = std::pin::pin!(d.stream().unwrap()).next().await.unwrap()?;
6061

6162
assert_eq!("TestThing", t.title);
62-
});
63+
println!("Found {}", t.title);
64+
Result::<(), Box<dyn std::error::Error>>::Ok(())
65+
})
66+
.await??;
6367

6468
task::spawn_local(async {
6569
let d = Discoverer::new().unwrap().ext::<A>();
6670

67-
let t = std::pin::pin!(d.stream().unwrap())
68-
.next()
69-
.await
70-
.unwrap()
71-
.unwrap();
71+
let t = std::pin::pin!(d.stream().unwrap()).next().await.unwrap()?;
7272

7373
assert_eq!("TestThing", t.title);
74-
});
74+
println!("Found {}", t.title);
75+
Result::<(), Box<dyn std::error::Error>>::Ok(())
76+
})
77+
.await??;
78+
79+
Result::<(), Box<dyn std::error::Error>>::Ok(())
7580
})
76-
.await;
81+
.await?;
7782

7883
Ok(())
7984
}

0 commit comments

Comments
 (0)