-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SpyMetricSink and Mutex poisoning #124
Comments
Oof, yeah I ran into that when trying to write tests for the sinks themselves. Thanks for reporting it. Since the Do you have a minimal test case to reproduce this? I'm wondering if this can be worked around with some copying of the contents of the buffer and extra documentation to avoid holding the lock while any assertions are made. |
Yes, it can also be avoided with copying. One of the things I wanted to do initially was to avoid copying, and the mutex should (in theory) provide that capability. Another design could use a channel (copying). We can always change the code on our side that holds a I'm sure I could come up with a minimal test case for this... |
Ooh, that's a neat idea for changing the sink. It would be a breaking change but it seems like a much cleaner API and it can use Roughly something like: let (rx, sink) = SpyMetricSink::new();
let client = StatsdClient::from_sink("prefix", sink);
// etc...
let metric1 = rx.recv().unwrap();
let metric2 = rx.recv().unwrap();
assert_eq!("prefix.my.metric:4|c", metric1);
assert_eq!("prefix.other.metric:42|c", metric2); WDYT? |
It needs a contingency plan for back pressure (what happens when the reader isn't consuming messages fast enough?) but yeah, channels are a great way to separate concerns like this. This is just a FWIW, but the |
👍 The channels from |
Rewrite `SpyMetricSink` and `BufferedSpyMetricSink` to use channels to share metrics emited with callers instead of a shared `Write` impl protected by a `Mutex`. This avoids poisoning the mutex if a test assertion fails while the mutex is held (which is common for something meant to be used for testing). Examples of how tests can be written against the new spy sinks can be found in the cadence/examples/spy-sink.rs example as well as the integration tests for cadence-macros. Fixes #124
Rewrite `SpyMetricSink` and `BufferedSpyMetricSink` to use channels to share metrics emited with callers instead of a shared `Write` impl protected by a `Mutex`. This avoids poisoning the mutex if a test assertion fails while the mutex is held (which is common for something meant to be used for testing). Examples of how tests can be written against the new spy sinks can be found in the cadence/examples/spy-sink.rs example as well as the integration tests for cadence-macros. Fixes #124
Rewrite `SpyMetricSink` and `BufferedSpyMetricSink` to use channels to share metrics emited with callers instead of a shared `Write` impl protected by a `Mutex`. This avoids poisoning the mutex if a test assertion fails while the mutex is held (which is common for something meant to be used for testing). Examples of how tests can be written against the new spy sinks can be found in the cadence/examples/spy-sink.rs example as well as the integration tests for cadence-macros. Fixes #124
Rewrite `SpyMetricSink` and `BufferedSpyMetricSink` to use channels to share metrics emitted with callers instead of a shared `Write` impl protected by a `Mutex`. This avoids poisoning the mutex if a test assertion fails while the mutex is held (which is common for something meant to be used for testing). Examples of how tests can be written against the new spy sinks can be found in the cadence/examples/spy-sink.rs example as well as the integration tests for cadence-macros. Fixes #124
We ran into a situation where running unit tests with
SpyMetricSink
/BufferedSpyMetricsSink
would poison the mutex when assertions failed during tests. This leads to spooky action at a distance with these types unwrapping the mutex lock result and panicking in a different code path.Using
parking_lot::Mutex
can avoid poisoning.The text was updated successfully, but these errors were encountered: