about summary refs log tree commit diff
path: root/src/database/redis
diff options
context:
space:
mode:
Diffstat (limited to 'src/database/redis')
-rw-r--r--src/database/redis/mod.rs25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/database/redis/mod.rs b/src/database/redis/mod.rs
index ccbf831..a3b4bf8 100644
--- a/src/database/redis/mod.rs
+++ b/src/database/redis/mod.rs
@@ -249,11 +249,28 @@ impl RedisStorage {
 
 #[cfg(test)]
 pub mod tests {
-    use std::{process};
+    use std::process;
     use std::time::Duration;
     use mobc_redis::redis;
 
-    pub async fn get_redis_instance() -> (tempdir::TempDir, process::Child, String) {
+    pub struct RedisInstance {
+        // We just need to hold on to it so it won't get dropped and remove the socket
+        _tempdir: tempdir::TempDir,
+        uri: String,
+        child: std::process::Child
+    }
+    impl Drop for RedisInstance {
+        fn drop(&mut self) {
+            self.child.kill().expect("Failed to kill the child!");
+        }
+    }
+    impl RedisInstance {
+        pub fn uri(&self) -> &str {
+            &self.uri
+        }
+    }
+
+    pub async fn get_redis_instance() -> RedisInstance {
         let tempdir = tempdir::TempDir::new("redis").expect("failed to create tempdir");
         let socket = tempdir.path().join("redis.sock");
         let redis_child = process::Command::new("redis-server")
@@ -282,6 +299,8 @@ pub mod tests {
             }
         }
 
-        return (tempdir, redis_child, uri)
+        return RedisInstance {
+            uri, child: redis_child, _tempdir: tempdir
+        }
     }
 }
\ No newline at end of file