Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
[#3] Finalize service tests
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Eltzschig <[email protected]>
  • Loading branch information
elfenpiff committed Oct 31, 2023
1 parent 3e6bdeb commit 8ef93d1
Showing 1 changed file with 130 additions and 2 deletions.
132 changes: 130 additions & 2 deletions elkodon/tests/service_event_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,20 +157,148 @@ mod service_event {
#[test]
fn simple_communication_works_listener_created_first<Sut: Service>() {
let service_name = generate_name();
let event_id = EventId::new(432);

let sut = Sut::new(&service_name).event().create().unwrap();

let sut2 = Sut::new(&service_name).event().open().unwrap();

let listener = sut.listener().create().unwrap();
let mut listener = sut.listener().create().unwrap();
let notifier = sut2
.notifier()
.default_trigger_id(EventId::new(432))
.default_trigger_id(event_id)
.create()
.unwrap();

assert_that!(notifier.notify(), is_ok);

let mut received_events = 0;
for event in listener.try_wait().unwrap().iter() {
assert_that!(*event, eq event_id);
received_events += 1;
}
assert_that!(received_events, eq 1);
}

#[test]
fn simple_communication_works_notifier_created_first<Sut: Service>() {
let service_name = generate_name();
let event_id = EventId::new(43212);

let sut = Sut::new(&service_name).event().create().unwrap();

let sut2 = Sut::new(&service_name).event().open().unwrap();

let notifier = sut2
.notifier()
.default_trigger_id(event_id)
.create()
.unwrap();
let mut listener = sut.listener().create().unwrap();

assert_that!(notifier.notify(), is_ok);

let mut received_events = 0;
for event in listener.try_wait().unwrap().iter() {
assert_that!(*event, eq event_id);
received_events += 1;
}
assert_that!(received_events, eq 1);
}

#[test]
fn communication_with_max_notifiers_and_listeners_single_notification<Sut: Service>() {
const MAX_LISTENERS: usize = 4;
const MAX_NOTIFIERS: usize = 6;
const NUMBER_OF_ITERATIONS: u64 = 128;
let service_name = generate_name();

let sut = Sut::new(&service_name)
.event()
.max_notifiers(MAX_NOTIFIERS)
.max_listeners(MAX_LISTENERS)
.create()
.unwrap();

let mut listeners = vec![];
let mut notifiers = vec![];

for _ in 0..MAX_LISTENERS {
listeners.push(sut.listener().create().unwrap());
}

for i in 0..MAX_NOTIFIERS {
notifiers.push(
sut.notifier()
.default_trigger_id(EventId::new((4 * i + 3) as u64))
.create()
.unwrap(),
);
}

for _ in 0..NUMBER_OF_ITERATIONS {
for (i, notifier) in notifiers.iter().enumerate() {
assert_that!(notifier.notify(), is_ok);

for listener in &mut listeners {
let mut received_events = 0;
for event in listener.try_wait().unwrap().iter() {
assert_that!(*event, eq EventId::new((4*i + 3) as u64));
received_events += 1;
}
assert_that!(received_events, eq 1);
}
}
}
}

#[test]
fn communication_with_max_notifiers_and_listeners_multi_notification<Sut: Service>() {
const MAX_LISTENERS: usize = 5;
const MAX_NOTIFIERS: usize = 7;
const NUMBER_OF_ITERATIONS: u64 = 128;
let service_name = generate_name();

let sut = Sut::new(&service_name)
.event()
.max_notifiers(MAX_NOTIFIERS)
.max_listeners(MAX_LISTENERS)
.create()
.unwrap();

let mut listeners = vec![];
let mut notifiers = vec![];

for _ in 0..MAX_LISTENERS {
listeners.push(sut.listener().create().unwrap());
}

for i in 0..MAX_NOTIFIERS {
notifiers.push(
sut.notifier()
.default_trigger_id(EventId::new((i) as u64))
.create()
.unwrap(),
);
}

for _ in 0..NUMBER_OF_ITERATIONS {
for notifier in &notifiers {
assert_that!(notifier.notify(), is_ok);
}

for listener in &mut listeners {
let mut received_events = 0;

let mut received_event_ids = [false; MAX_NOTIFIERS];
for event in listener.try_wait().unwrap().iter() {
assert_that!(received_event_ids[event.as_u64() as usize], eq false);
received_event_ids[event.as_u64() as usize] = true;
received_events += 1;
}
assert_that!(received_events, eq MAX_NOTIFIERS);
}
}
}

#[instantiate_tests(<elkodon::service::zero_copy::Service>)]
Expand Down

0 comments on commit 8ef93d1

Please sign in to comment.