Skip to content

Commit 8dcc07d

Browse files
authored
Refactor testing (#210)
* Overhaul testing.
1 parent ecfc3ef commit 8dcc07d

38 files changed

+722
-2075
lines changed

.config/nextest.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[profile.default]
22
test-threads = 1
33
fail-fast = false
4-
slow-timeout = { period = "30s", terminate-after = 4 }
5-
retries = { backoff = "fixed", count = 2, delay = "1s" }
4+
slow-timeout = { period = "2s", terminate-after = 2 }
5+
retries = { backoff = "fixed", count = 3, delay = "1s" }

Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ libc = "0.2"
1818
log = { version = "0.4", optional = true}
1919

2020
[dev-dependencies]
21+
approx = "0.5"
2122
crossbeam-channel = "0.5"
23+
ctor = "0.2"
2224

2325
[features]
2426
default = ["dynamic_loading", "log"]
25-
dynamic_loading = ["jack-sys/dynamic_loading"]
27+
dynamic_loading = ["jack-sys/dynamic_loading"]

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ Rust bindings for [JACK Audio Connection Kit](<https://jackaudio.org>).
1212

1313
The JACK server is usually started by the user or system. Clients can request
1414
that the JACK server is started on demand when they connect, but this can be
15-
disabled by creating a client with the `NO_START_SERVER` option.
15+
disabled by creating a client with the `NO_START_SERVER` option or
16+
`ClientOptions::default()`.
1617

1718
- Linux and BSD users may install JACK1, JACK2 (preferred for low latency), or
1819
Pipewire JACK (preferred for ease of use) from their system package manager.

docs/contrib/closure_callbacks.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ contains captures the required state and then activating it.
1818
```rust
1919
// 1. Create the client.
2020
let (client, _status) =
21-
jack::Client::new("silence", jack::ClientOptions::NO_START_SERVER).unwrap();
21+
jack::Client::new("silence", jack::ClientOptions::default()).unwrap();
2222

2323
// 2. Define the state.
2424
let mut output = client.register_port("out", jack::AudioOut::default());
@@ -45,7 +45,7 @@ buffer size.
4545
```rust
4646
// 1. Create the client.
4747
let (client, _status) =
48-
jack::Client::new("silence", jack::ClientOptions::NO_START_SERVER).unwrap();
48+
jack::Client::new("silence", jack::ClientOptions::default()).unwrap();
4949

5050
// 2. Define the state.
5151
struct State {

docs/features.md

-7
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,3 @@ Default: Yes
3737
Load `libjack` at runtime as opposed to the standard dynamic linking. This is
3838
preferred as it allows `pw-jack` to intercept the loading at runtime to provide
3939
the Pipewire JACK server implementation.
40-
41-
## `metadata`
42-
43-
Default: No
44-
45-
Provides access to the metadata API. This is experimental. Details on the JACK
46-
metadata API can be found at <https://jackaudio.org/metadata/>.

docs/logging.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@ enabled by default. The `log` crate provides a *facade* for logging; it provides
2727
macros to perform logging, but another mechanism or crate is required to
2828
actually perform the logging.
2929

30-
In the example below, we use the [`env_logger` crate]() to display logging for
31-
info and error severity level messages.
30+
In the example below, we use the [`env_logger`
31+
crate](https://crates.io/crates/env_logger) to display logging for info and
32+
error severity level messages.
3233

3334
```rust
3435
env_logger::builder().filter(None, log::LevelFilter::Info).init();
3536

3637
// JACK may log things to `info!` or `error!`.
3738
let (client, _status) =
38-
jack::Client::new("rust_jack_simple", jack::ClientOptions::NO_START_SERVER).unwrap();
39+
jack::Client::new("rust_jack_simple", jack::ClientOptions::default()).unwrap();
3940
```
4041

4142

docs/quickstart.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ program that can take inputs and forward them to outputs.
5555
fn main() {
5656
// 1. Create client
5757
let (client, _status) =
58-
jack::Client::new("rust_jack_simple", jack::ClientOptions::NO_START_SERVER).unwrap();
58+
jack::Client::new("rust_jack_simple", jack::ClientOptions::default()).unwrap();
5959

6060
// 2. Register ports. They will be used in a callback that will be
6161
// called when new data is available.

examples/internal_client.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ fn main() {
66
// Create client
77
let (client, _status) = jack::Client::new(
88
"rust_jack_internal_client_tester",
9-
jack::ClientOptions::NO_START_SERVER,
9+
jack::ClientOptions::default(),
1010
)
1111
.unwrap();
1212

examples/playback_capture.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ fn main() {
66
// Create client
77
jack::set_logger(jack::LoggerType::Stdio);
88
let (client, _status) =
9-
jack::Client::new("rust_jack_simple", jack::ClientOptions::NO_START_SERVER).unwrap();
9+
jack::Client::new("rust_jack_simple", jack::ClientOptions::default()).unwrap();
1010

1111
// Register ports. They will be used in a callback that will be
1212
// called when new data is available.

examples/set_transport.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::env;
22

33
fn main() {
44
let (client, _status) =
5-
jack::Client::new("rust_jack_trans", jack::ClientOptions::NO_START_SERVER).unwrap();
5+
jack::Client::new("rust_jack_trans", jack::ClientOptions::default()).unwrap();
66

77
let transport = client.transport();
88

examples/show_midi.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@ impl std::fmt::Debug for MidiCopy {
4343
fn main() {
4444
// Open the client.
4545
let (client, _status) =
46-
jack::Client::new("rust_jack_show_midi", jack::ClientOptions::NO_START_SERVER).unwrap();
46+
jack::Client::new("rust_jack_show_midi", jack::ClientOptions::default()).unwrap();
4747

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

5151
// Define process logic.
5252
let mut maker = client
53-
.register_port("rust_midi_maker", jack::MidiOut)
53+
.register_port("rust_midi_maker", jack::MidiOut::default())
5454
.unwrap();
5555
let shower = client
56-
.register_port("rust_midi_shower", jack::MidiIn)
56+
.register_port("rust_midi_shower", jack::MidiIn::default())
5757
.unwrap();
5858
let cback = move |_: &jack::Client, ps: &jack::ProcessScope| -> jack::Control {
5959
let show_p = shower.iter(ps);

examples/show_transport.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::sync::{
77
fn main() {
88
// Create client
99
let (client, _status) =
10-
jack::Client::new("rust_jack_trans", jack::ClientOptions::NO_START_SERVER).unwrap();
10+
jack::Client::new("rust_jack_trans", jack::ClientOptions::default()).unwrap();
1111

1212
let transport = client.transport();
1313
let stop = Arc::new(AtomicBool::new(false));

examples/sine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::str::FromStr;
88
fn main() {
99
// 1. open a client
1010
let (client, _status) =
11-
jack::Client::new("rust_jack_sine", jack::ClientOptions::NO_START_SERVER).unwrap();
11+
jack::Client::new("rust_jack_sine", jack::ClientOptions::default()).unwrap();
1212

1313
// 2. register port
1414
let out_port = client

src/client/async_client.rs

+11-19
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::sync::atomic::AtomicBool;
77
use super::callbacks::clear_callbacks;
88
use super::callbacks::{CallbackContext, NotificationHandler, ProcessHandler};
99
use crate::client::client_impl::Client;
10-
use crate::client::common::{sleep_on_test, CREATE_OR_DESTROY_CLIENT_MUTEX};
10+
use crate::client::common::CREATE_OR_DESTROY_CLIENT_MUTEX;
1111
use crate::Error;
1212

1313
/// A JACK client that is processing data asynchronously, in real-time.
@@ -20,7 +20,7 @@ use crate::Error;
2020
/// ```
2121
/// // Create a client and a handler
2222
/// let (client, _status) =
23-
/// jack::Client::new("my_client", jack::ClientOptions::NO_START_SERVER).unwrap();
23+
/// jack::Client::new("my_client", jack::ClientOptions::default()).unwrap();
2424
/// let process_handler = jack::contrib::ClosureProcessHandler::new(
2525
/// move |_: &jack::Client, _: &jack::ProcessScope| jack::Control::Continue,
2626
/// );
@@ -56,19 +56,15 @@ where
5656
pub fn new(client: Client, notification_handler: N, process_handler: P) -> Result<Self, Error> {
5757
let _m = CREATE_OR_DESTROY_CLIENT_MUTEX.lock().ok();
5858
unsafe {
59-
sleep_on_test();
6059
let mut callback_context = Box::new(CallbackContext {
6160
client,
6261
notification: notification_handler,
6362
process: process_handler,
64-
is_valid: AtomicBool::new(true),
63+
is_valid_for_callback: AtomicBool::new(true),
64+
has_panic: AtomicBool::new(false),
6565
});
6666
CallbackContext::register_callbacks(&mut callback_context)?;
67-
sleep_on_test();
6867
let res = j::jack_activate(callback_context.client.raw());
69-
for _ in 0..4 {
70-
sleep_on_test();
71-
}
7268
match res {
7369
0 => Ok(AsyncClient {
7470
callback: Some(callback_context),
@@ -114,25 +110,21 @@ impl<N, P> AsyncClient<N, P> {
114110
return Err(Error::ClientIsNoLongerAlive);
115111
}
116112
let cb = self.callback.take().ok_or(Error::ClientIsNoLongerAlive)?;
117-
let client = cb.client.raw();
113+
let client_ptr = cb.client.raw();
118114

119115
// deactivate
120-
sleep_on_test();
121-
if j::jack_deactivate(client) != 0 {
116+
if j::jack_deactivate(client_ptr) != 0 {
122117
return Err(Error::ClientDeactivationError);
123118
}
124119

125120
// clear the callbacks
126-
sleep_on_test();
127-
clear_callbacks(client)?;
121+
clear_callbacks(client_ptr)?;
128122
// done, take ownership of callback
129-
if cb.is_valid.load(std::sync::atomic::Ordering::Relaxed) {
130-
Ok(cb)
131-
} else {
132-
std::mem::forget(cb.notification);
133-
std::mem::forget(cb.process);
134-
Err(Error::ClientIsNoLongerAlive)
123+
if cb.has_panic.load(std::sync::atomic::Ordering::Relaxed) {
124+
std::mem::forget(cb);
125+
return Err(Error::ClientPanicked);
135126
}
127+
Ok(cb)
136128
}
137129
}
138130

0 commit comments

Comments
 (0)