Skip to content

Commit

Permalink
Add two unit test cases
Browse files Browse the repository at this point in the history
Add two unit test cases for SubscriberId and remote endpoint.

Signed-off-by: Liu Jiang <[email protected]>
  • Loading branch information
jiangliu committed Jun 11, 2021
1 parent 49ba509 commit d9b51d4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion coverage_config_x86_64.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"coverage_score": 85.6,
"coverage_score": 87.0,
"exclude_path": "tests/,benches/,utilities/",
"crate_features": "remote_endpoint,test_utilities"
}
19 changes: 19 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,22 @@ impl<T: MutEventSubscriber + ?Sized> MutEventSubscriber for Box<T> {
self.deref_mut().init(ops);
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_subscriber_id_derives() {
let a = SubscriberId(1);
let b = SubscriberId(1);
let c = SubscriberId(2);

assert_eq!(a, b);
assert_ne!(a, c);
assert_ne!(c, b);

let d = c.clone();
assert_eq!(c, d);
}
}
27 changes: 27 additions & 0 deletions src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,4 +497,31 @@ mod tests {
Error::InvalidId
);
}

#[test]
#[cfg(feature = "remote_endpoint")]
fn test_endpoint() {
use std::thread;

let mut event_manager = EventManager::<DummySubscriber>::new().unwrap();
let dummy = DummySubscriber::new();
let endpoint = event_manager.remote_endpoint();
let kicker = event_manager.remote_endpoint();

let thread_handle = thread::spawn(move || {
event_manager.run().unwrap();
event_manager.run().unwrap();
});

dummy.event_fd_1.write(1).unwrap();

let token = endpoint
.call_blocking(|sub_ops| -> Result<SubscriberId> { Ok(sub_ops.add_subscriber(dummy)) })
.unwrap();
assert_eq!(token, SubscriberId(1));

kicker.kick().unwrap();

thread_handle.join().unwrap();
}
}

0 comments on commit d9b51d4

Please sign in to comment.