Skip to content

Commit 80d4032

Browse files
committed
cancellable: Avoid using unneeded channel to run tests
There's no need to use a channel, we can just block on the spawning future
1 parent 9c70eb3 commit 80d4032

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

gio/src/cancellable.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,11 @@ mod tests {
214214
fn cancellable_future_delayed() {
215215
let ctx = glib::MainContext::new();
216216
let c = Cancellable::new();
217-
let (tx, rx) = oneshot::channel();
218-
{
217+
let future = {
219218
let c = c.clone();
220-
ctx.spawn_local(async move {
221-
c.future().await;
222-
tx.send(()).unwrap();
223-
});
224-
}
219+
ctx.spawn_local(c.future())
220+
};
225221
std::thread::spawn(move || c.cancel()).join().unwrap();
226-
ctx.block_on(rx).unwrap();
222+
ctx.block_on(future).unwrap();
227223
}
228224
}

gio/src/cancellable_future.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -141,52 +141,46 @@ impl Display for Cancelled {
141141

142142
#[cfg(test)]
143143
mod tests {
144-
use futures_channel::oneshot;
144+
use std::time::Duration;
145145

146146
use super::{Cancellable, CancellableFuture, Cancelled};
147-
use crate::prelude::*;
147+
use crate::{prelude::*, spawn_blocking};
148148

149149
#[test]
150150
fn cancellable_future_ok() {
151151
let ctx = glib::MainContext::new();
152152
let c = Cancellable::new();
153-
let (tx, rx) = oneshot::channel();
154153

155-
{
154+
let future = {
156155
ctx.spawn_local(async {
157156
let cancellable_future = CancellableFuture::new(async { 42 }, c);
158157
assert!(!cancellable_future.is_cancelled());
159158

160159
let result = cancellable_future.await;
161160
assert!(matches!(result, Ok(42)));
161+
})
162+
};
162163

163-
tx.send(()).unwrap();
164-
});
165-
}
166-
167-
ctx.block_on(rx).unwrap()
164+
ctx.block_on(future).unwrap()
168165
}
169166

170167
#[test]
171168
fn cancellable_future_cancel() {
172169
let ctx = glib::MainContext::new();
173170
let c = Cancellable::new();
174-
let (tx, rx) = oneshot::channel();
175171

176-
{
172+
let future = {
177173
let c = c.clone();
178174
ctx.spawn_local(async move {
179175
let cancellable_future = CancellableFuture::new(std::future::pending::<()>(), c);
180176

181177
let result = cancellable_future.await;
182178
assert!(matches!(result, Err(Cancelled)));
183-
184-
tx.send(()).unwrap();
185-
});
186-
}
179+
})
180+
};
187181

188182
std::thread::spawn(move || c.cancel()).join().unwrap();
189183

190-
ctx.block_on(rx).unwrap();
184+
ctx.block_on(future).unwrap();
191185
}
192186
}

0 commit comments

Comments
 (0)