Skip to main content

adze_concurrency_init_classifier_core/
lib.rs

1//! Message classification helpers for Rayon global thread-pool initialization errors.
2
3#![forbid(unsafe_op_in_unsafe_fn)]
4#![deny(missing_docs)]
5#![cfg_attr(feature = "strict_api", deny(unreachable_pub))]
6#![cfg_attr(not(feature = "strict_api"), warn(unreachable_pub))]
7#![cfg_attr(feature = "strict_docs", deny(missing_docs))]
8#![cfg_attr(not(feature = "strict_docs"), allow(missing_docs))]
9
10/// Return whether the provided message represents a Rayon global-pool
11/// already-initialized error.
12#[must_use]
13pub fn is_already_initialized_error(message: &str) -> bool {
14    let message = message.to_ascii_lowercase();
15    message.contains("global") && message.contains("already")
16}
17
18#[cfg(test)]
19mod tests {
20    use super::is_already_initialized_error;
21
22    #[test]
23    fn already_initialized_error_classifier_is_case_insensitive() {
24        assert!(is_already_initialized_error(
25            "The GlObAl thread pool has AlReAdY been initialized"
26        ));
27    }
28
29    #[test]
30    fn already_initialized_error_classifier_requires_both_tokens() {
31        assert!(!is_already_initialized_error(
32            "thread pool already initialized"
33        ));
34        assert!(!is_already_initialized_error(
35            "global thread pool initialized"
36        ));
37    }
38
39    #[test]
40    fn empty_string_is_not_already_initialized_error() {
41        assert!(!is_already_initialized_error(""));
42    }
43
44    #[test]
45    fn unrelated_message_is_not_detected() {
46        assert!(!is_already_initialized_error("something went wrong"));
47    }
48
49    #[test]
50    fn reversed_token_order_is_still_detected() {
51        assert!(is_already_initialized_error(
52            "already set on the global pool"
53        ));
54    }
55
56    #[test]
57    fn adjacent_tokens_are_detected() {
58        assert!(is_already_initialized_error("globalalready"));
59    }
60
61    #[test]
62    fn only_global_token_is_not_detected() {
63        assert!(!is_already_initialized_error("global"));
64    }
65
66    #[test]
67    fn only_already_token_is_not_detected() {
68        assert!(!is_already_initialized_error("already"));
69    }
70}