• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Devin-Yeung / ailurus-kv / 15972795749

30 Jun 2025 12:23PM UTC coverage: 86.436% (-0.3%) from 86.702%
15972795749

push

github

web-flow
Chore(deps): Bump prost from 0.14.0 to 0.14.1 in the dependencies group (#68)

Bumps the dependencies group with 1 update: [prost](https://github.com/tokio-rs/prost).


Updates `prost` from 0.14.0 to 0.14.1
- [Release notes](https://github.com/tokio-rs/prost/releases)
- [Changelog](https://github.com/tokio-rs/prost/blob/master/CHANGELOG.md)
- [Commits](https://github.com/tokio-rs/prost/compare/v0.14.0...v0.14.1)

---
updated-dependencies:
- dependency-name: prost
  dependency-version: 0.14.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

325 of 376 relevant lines covered (86.44%)

1.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.73
/src/mock/engine_wrapper.rs
1
use crate::engine::Engine;
2
use crate::options::IndexType;
3
use lazy_static::lazy_static;
4
use std::fs;
5
use std::ops::{Deref, DerefMut};
6
use std::path::{Path, PathBuf};
7
use std::sync::Mutex;
8

9
const PREFIX: &str = "tmp/engine";
10

11
#[macro_export]
12
macro_rules! engine {
13
    ($([$key:expr, $value:expr]),* $(,)?) => {{
14
        #[allow(unused_mut)]
15
        let mut db = $crate::mock::engine_wrapper::EngineWrapper::default();
15✔
16
        $(db.put($key.into(),$value.into()).unwrap();)*
26✔
17
        db
15✔
18
    }};
19
}
20

21
lazy_static! {
22
    pub static ref ENGINEDISTRIBUTOR: EngineDistributor = EngineDistributor::new();
1✔
23
}
24
pub struct Inner {
25
    id: u32,
26
    count: u32,
27
}
28

29
pub struct EngineDistributor {
30
    inner: Mutex<Inner>,
31
}
32

33
impl EngineDistributor {
34
    pub fn new() -> Self {
1✔
35
        EngineDistributor {
36
            inner: Mutex::new(Inner { id: 0, count: 0 }),
1✔
37
        }
38
    }
39

40
    pub fn path(&self) -> PathBuf {
1✔
41
        let mut path = PathBuf::from(PREFIX);
1✔
42
        let mut inner = self.inner.lock().unwrap();
2✔
43
        path.push(inner.id.to_string());
2✔
44
        inner.id += 1;
1✔
45
        inner.count += 1;
2✔
46
        drop(inner);
1✔
47
        path
3✔
48
    }
49

50
    pub fn drop(&self) {
1✔
51
        let mut inner = self.inner.lock().unwrap();
1✔
52
        inner.count -= 1;
2✔
53
        if inner.count == 0 {
2✔
54
            fs::remove_dir(PREFIX).unwrap();
×
55
        }
56
        drop(inner);
1✔
57
    }
58
}
59

60
pub struct EngineWrapper {
61
    engine: Engine,
62
    path: PathBuf,
63
}
64

65
impl EngineWrapper {
66
    pub(crate) fn new(opts: crate::options::Options) -> EngineWrapper {
1✔
67
        // create dir if not exist
68
        if !opts.dir_path.is_dir() {
2✔
69
            fs::create_dir_all(&opts.dir_path).unwrap()
2✔
70
        }
71

72
        EngineWrapper {
73
            path: opts.dir_path.to_owned(),
3✔
74
            engine: Engine::new(opts).unwrap(),
3✔
75
        }
76
    }
77

78
    #[allow(dead_code)]
79
    pub(crate) fn reopen(mut self) -> EngineWrapper {
1✔
80
        // FIXME: The old engine is not dropped when the reopened engine is opened
81
        // so the `drop` method of the old engine may not be applied timely
82
        let engine = Engine::new(self.options.clone()).unwrap();
2✔
83
        let _ = std::mem::replace(&mut self.engine, engine);
1✔
84
        self
1✔
85
    }
86

87
    #[allow(dead_code)]
88
    pub(crate) fn path(&self) -> &Path {
1✔
89
        &self.path
1✔
90
    }
91
}
92

93
impl Default for EngineWrapper {
94
    fn default() -> Self {
1✔
95
        let opts = crate::options::OptionsBuilder::default()
7✔
96
            .dir_path(ENGINEDISTRIBUTOR.path())
2✔
97
            .data_file_size(8 * 1024) // 8 KB, easy to test
2✔
98
            .sync_writes(true)
99
            .index_type(IndexType::BTree)
1✔
100
            .build()
101
            .unwrap();
102
        EngineWrapper::new(opts)
2✔
103
    }
104
}
105

106
impl Deref for EngineWrapper {
107
    type Target = Engine;
108

109
    fn deref(&self) -> &Self::Target {
1✔
110
        &self.engine
111
    }
112
}
113

114
impl DerefMut for EngineWrapper {
115
    fn deref_mut(&mut self) -> &mut Self::Target {
1✔
116
        &mut self.engine
117
    }
118
}
119

120
impl Drop for EngineWrapper {
121
    fn drop(&mut self) {
1✔
122
        for entry in fs::read_dir(&self.path).unwrap().flatten() {
2✔
123
            fs::remove_file(entry.path()).unwrap()
2✔
124
        }
125
        fs::remove_dir(&self.path).unwrap();
1✔
126
        ENGINEDISTRIBUTOR.drop();
1✔
127
    }
128
}
129

130
#[cfg(test)]
131
mod tests {
132
    use crate::mock::engine_wrapper::{EngineWrapper, ENGINEDISTRIBUTOR};
133
    use std::collections::HashSet;
134
    use std::path::PathBuf;
135
    use std::sync::{Arc, Mutex};
136
    use std::thread::spawn;
137

138
    #[test]
139
    fn distribute_one_engine() {
140
        let engine = EngineWrapper::default();
141
        let path = engine.path.clone();
142
        assert!(path.is_dir());
143
        drop(engine);
144
        assert!(!path.is_dir());
145
    }
146

147
    #[test]
148
    fn path_never_collision() {
149
        let memo = Arc::new(Mutex::new(HashSet::<PathBuf>::new()));
150
        let mut handlers = Vec::new();
151

152
        for _ in 1..100 {
153
            let memo = memo.clone();
154
            let handler = spawn(move || {
155
                let generated = ENGINEDISTRIBUTOR.path();
156
                let mut guard = memo.lock().unwrap();
157
                assert!(!guard.contains(&generated));
158
                guard.insert(generated);
159
                drop(guard);
160
            });
161
            handlers.push(handler);
162
        }
163
        for handler in handlers {
164
            handler.join().unwrap();
165
        }
166
    }
167
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc