summaryrefslogtreecommitdiffstats
path: root/tests/current_thread.rs
diff options
context:
space:
mode:
authorRoman <humbug@deeptown.org>2018-02-28 20:00:25 +0300
committerCarl Lerche <me@carllerche.com>2018-02-28 09:00:25 -0800
commit1190176be7912db327f5e2784e51ce87c385201b (patch)
tree72b69dce409a851b67fbe01907c8ffdaf37cc4f5 /tests/current_thread.rs
parent8e1a9101f098f56692978bb2d4985238359891fa (diff)
Improve current thread tests (#161)
* Create variables as closer as possible to their usage * Check that no message is lost in test current_thread::hammer_turn
Diffstat (limited to 'tests/current_thread.rs')
-rw-r--r--tests/current_thread.rs46
1 files changed, 27 insertions, 19 deletions
diff --git a/tests/current_thread.rs b/tests/current_thread.rs
index 51695f40..dfc80334 100644
--- a/tests/current_thread.rs
+++ b/tests/current_thread.rs
@@ -38,9 +38,6 @@ fn spawn_from_block_on_all() {
#[test]
fn block_waits() {
- let cnt = Rc::new(Cell::new(0));
- let cnt2 = cnt.clone();
-
let (tx, rx) = oneshot::channel();
thread::spawn(|| {
@@ -48,6 +45,9 @@ fn block_waits() {
tx.send(()).unwrap();
});
+ let cnt = Rc::new(Cell::new(0));
+ let cnt2 = cnt.clone();
+
block_on_all(rx.then(move |_| {
cnt.set(1 + cnt.get());
Ok::<_, ()>(())
@@ -300,28 +300,28 @@ fn spawn_in_drop() {
let (tx, rx) = oneshot::channel();
- struct OnDrop<F: FnOnce()>(Option<F>);
+ current_thread.spawn({
+ struct OnDrop<F: FnOnce()>(Option<F>);
- impl<F: FnOnce()> Drop for OnDrop<F> {
- fn drop(&mut self) {
- (self.0.take().unwrap())();
+ impl<F: FnOnce()> Drop for OnDrop<F> {
+ fn drop(&mut self) {
+ (self.0.take().unwrap())();
+ }
}
- }
- struct MyFuture {
- _data: Box<Any>,
- }
+ struct MyFuture {
+ _data: Box<Any>,
+ }
- impl Future for MyFuture {
- type Item = ();
- type Error = ();
+ impl Future for MyFuture {
+ type Item = ();
+ type Error = ();
- fn poll(&mut self) -> Poll<(), ()> {
- Ok(().into())
+ fn poll(&mut self) -> Poll<(), ()> {
+ Ok(().into())
+ }
}
- }
- current_thread.spawn({
MyFuture {
_data: Box::new(OnDrop(Some(move || {
current_thread::spawn(lazy(move || {
@@ -355,10 +355,18 @@ fn hammer_turn() {
let (tx, rx) = mpsc::unbounded();
current_thread.spawn({
- rx.for_each(|_| {
+ let cnt = Rc::new(Cell::new(0));
+ let c = cnt.clone();
+
+ rx.for_each(move |_| {
+ c.set(1 + c.get());
Ok(())
})
.map_err(|e| panic!("err={:?}", e))
+ .map(move |v| {
+ assert_eq!(N, cnt.get());
+ v
+ })
});
thread::spawn(move || {