Skip to content

Commit

Permalink
Use nextest to run tests on CI.
Browse files Browse the repository at this point in the history
  • Loading branch information
wmedrano committed Sep 9, 2024
1 parent 21268f3 commit fb51f94
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ jobs:
# take a while to initialize.
- name: Start dummy JACK server
run: jackd -r -ddummy -r44100 -p1024 &
- name: Install Cargo Nextest
uses: taiki-e/install-action@nextest
- name: Build (No Features)
run: cargo build --verbose --no-default-features
- name: Build (metadata)
run: cargo build --verbose --no-default-features --features metadata
- name: Run Tests
run: cargo test --verbose --all-features
run: cargo nextest run --all-features --test-threads 1
env:
RUST_TEST_THREADS: 1
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ crossbeam-channel = "0.5"
[features]
default = ["dynamic_loading"]
metadata = []
dynamic_loading = ["jack-sys/dynamic_loading"]
dynamic_loading = ["jack-sys/dynamic_loading"]
17 changes: 9 additions & 8 deletions examples/show_midi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,26 @@ impl std::fmt::Debug for MidiCopy {
}

fn main() {
// open client
// Open the client.
let (client, _status) =
jack::Client::new("rust_jack_show_midi", jack::ClientOptions::NO_START_SERVER).unwrap();

//create a sync channel to send back copies of midi messages we get
// Create a sync channel to send back copies of midi messages we get.
let (sender, receiver) = sync_channel(64);

// process logic
// Define process logic.
let mut maker = client
.register_port("rust_midi_maker", jack::MidiOut)
.unwrap();
let shower = client
.register_port("rust_midi_shower", jack::MidiIn)
.unwrap();

let cback = move |_: &jack::Client, ps: &jack::ProcessScope| -> jack::Control {
let show_p = shower.iter(ps);
for e in show_p {
let c: MidiCopy = e.into();
// Prefer try send to not block the audio thread. Blocking the audio thread may crash
// the program.
let _ = sender.try_send(c);
}
let mut put_p = maker.writer(ps);
Expand All @@ -86,23 +87,23 @@ fn main() {
jack::Control::Continue
};

// activate
// Activate
let active_client = client
.activate_async((), jack::ClosureProcessHandler::new(cback))
.unwrap();

//spawn a non-real-time thread that prints out the midi messages we get
// Spawn a non-real-time thread that prints out the midi messages we get.
std::thread::spawn(move || {
while let Ok(m) = receiver.recv() {
println!("{m:?}");
}
});

// wait
// Wait
println!("Press any key to quit");
let mut user_input = String::new();
io::stdin().read_line(&mut user_input).ok();

// optional deactivation
// Optional deactivation.
active_client.deactivate().unwrap();
}
22 changes: 11 additions & 11 deletions src/port/midi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ mod test {
let mut out_b = c.register_port("ob", MidiOut).unwrap();

// set callback routine
let (signal_succeed, did_succeed) = std::sync::mpsc::sync_channel(1_000);
let (signal_succeed, did_succeed) = std::sync::mpsc::sync_channel(1);
let process_callback = move |_: &Client, ps: &ProcessScope| -> Control {
let exp_a = RawMidi {
time: 0,
Expand All @@ -332,7 +332,7 @@ mod test {
&& in_a.clone().all(|m| m == exp_a)
&& in_b.clone().all(|m| m == exp_b)
{
signal_succeed.send(true).unwrap();
_ = signal_succeed.try_send(true);
}
Control::Continue
};
Expand All @@ -353,7 +353,7 @@ mod test {
// check correctness
assert!(did_succeed
.recv_timeout(std::time::Duration::from_secs(1))
.unwrap(),);
.unwrap());
ac.deactivate().unwrap();
}

Expand Down Expand Up @@ -386,27 +386,27 @@ mod test {

#[test]
fn port_midi_cant_exceed_max_event_size() {
// open clients and ports
// Open clients and ports.
let c = open_test_client("port_midi_cemes");
let mut out_p = c.register_port("midi_out", MidiOut).unwrap();

// set callback routine
// Set callback routine.
let (result_sender, result_receiver) = std::sync::mpsc::sync_channel(1);
let process_callback = move |_: &Client, ps: &ProcessScope| -> Control {
let mut out_p = out_p.writer(ps);
let bytes: Vec<u8> = (0..=out_p.max_event_size()).map(|_| 0).collect();
let msg = RawMidi {
time: 0,
bytes: &bytes,
bytes: &[0xF6],
};

let res = out_p.write(&msg);
_ = result_sender.try_send(res);
for _ in 0..out_p.max_event_size() {
_ = out_p.write(&msg);
}
_ = result_sender.try_send(out_p.write(&msg));

Control::Continue
};

// check correctness
// Check correctness.
let ac = c
.activate_async((), ClosureProcessHandler::new(process_callback))
.unwrap();
Expand Down

0 comments on commit fb51f94

Please sign in to comment.