1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use std::ops::RangeInclusive;
use cs_utils::{random_number, traits::Random};

/// Options for `test_framed_stream`/`test_async_stream` utilities.
#[derive(Debug, Clone)]
pub struct TestOptions {
    /// Number of `messages` or `bytes` to send.
    data_len: usize,
    /// Latency value(min..=max) for each stream message transfer in milliseconds.
    latency_range: RangeInclusive<u64>,
}

impl TestOptions {
    /// Sets the `latency_range` value.
    pub fn with_latency(
        self,
        latency_range: RangeInclusive<u64>,
    ) -> TestOptions {
        return TestOptions {
            latency_range,
            ..self
        }
    }

    /// Sets the  `data_len` value.
    pub fn with_data_len(
        self,
        items_count: usize,
    ) -> TestOptions {
        return TestOptions {
            data_len: items_count,
            ..self
        }
    }

    /// Gets the `items_count` value.
    pub fn data_len(&self) -> usize {
        return self.data_len;
    }

    /// Gets the `latency_range` value.
    pub fn latency_range(&self) -> RangeInclusive<u64> {
        return self.latency_range.clone();
    }
}

impl Default for TestOptions {
    fn default() -> TestOptions {
        return TestOptions {
            data_len: 128,
            latency_range: (0..=0),
        };
    }
}

impl Random for TestOptions {
    fn random() -> TestOptions {
        let min: u64 = random_number(0..5);
        let max: u64 = random_number(5..50);
    
        return TestOptions {
            data_len: random_number(128..=256),
            latency_range: (min..=max),
        };
    }
}