Skip to content

Commit

Permalink
Channel subset test.
Browse files Browse the repository at this point in the history
  • Loading branch information
NotGyro committed Oct 2, 2024
1 parent ec4fb53 commit 2e3d27a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 12 deletions.
54 changes: 53 additions & 1 deletion gestalt-core/src/common/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,9 @@ impl<T> SubsetBuilder<T> where T: Sized {

#[cfg(test)]
pub mod test {
use crate::common::identity::IdentityKeyPair;
use gestalt_proc_macros::ChannelSet;

use crate::common::identity::IdentityKeyPair;

use super::*;

Expand Down Expand Up @@ -1420,4 +1422,54 @@ pub mod test {
assert_eq!(out_msg.msg, String::from("Hello, player2!"));
}
}
#[tokio::test(flavor = "multi_thread")]
async fn channel_set_subset() {
static_channel_atom!(EvenSpecialerString, MpscChannel<u32>, u32);
static_channel_atom!(SpecialStringGoesHere, BroadcastChannel<u32>, u32);

#[derive(ChannelSet)]
struct ChannelSetTestA {
#[channel(EvenSpecialerString)]
pub chan1: MpscChannel<u32>,
#[channel(SpecialStringGoesHere)]
pub chan2: BroadcastChannel<u32>,
}
#[derive(ChannelSet)]
struct ChannelSetTestB {
#[channel(EvenSpecialerString)]
pub foo: MpscChannel<u32>,
#[channel(SpecialStringGoesHere)]
pub bar: BroadcastReceiver<u32>,
}
#[derive(ChannelSet)]
struct ChannelSetTestC {
#[channel(EvenSpecialerString)]
pub foo: MpscSender<u32>,
}

let foo_channel: MpscChannel<u32> = MpscChannel::new(12);
let bar_channel: BroadcastChannel<u32> = BroadcastChannel::new(20);

let top_level = ChannelSetTestA {
chan1: foo_channel,
chan2: bar_channel,
};

let mut middle_level: ChannelSetTestB = top_level.to_subset();
let bottom_level: ChannelSetTestC = middle_level.to_subset();

let mut foo_receiver = top_level.chan1.take_receiver().unwrap();

let testnum = 42;
tokio::spawn(async move {
bottom_level.foo.send(testnum).await.unwrap();
});
let number = foo_receiver.recv_wait().await.unwrap();
assert_eq!(testnum, number);

let testnum = 13;
top_level.chan2.send(testnum).unwrap();
let number = middle_level.bar.recv_wait().await.unwrap();
assert_eq!(testnum, number);
}
}
11 changes: 0 additions & 11 deletions gestalt-core/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,6 @@ use crate::{

pub const ENGINE_VERSION: Version = Version::new(0,0,1);

static_channel_atom!(EvenSpecialerString, MpscChannel<u32>, u32);
static_channel_atom!(SpecialStringGoesHere, BroadcastChannel<u32>, u32);

#[derive(ChannelSet)]
struct ChannelSetTest {
#[channel(EvenSpecialerString)]
chan1: MpscChannel<u32>,
#[channel(SpecialStringGoesHere)]
chan2: BroadcastReceiver<u32>,
}

// For command-line argument parsing
enum OneOrTwo {
One(String),
Expand Down

0 comments on commit 2e3d27a

Please sign in to comment.