Skip to content

Commit 70e0bfa

Browse files
smf8bikeshedder
authored andcommitted
fix: Fix test issue with missing sentinel config values
1 parent df13238 commit 70e0bfa

File tree

4 files changed

+49
-24
lines changed

4 files changed

+49
-24
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ name: CI
22

33
on:
44
push:
5-
branches: ["master"]
6-
tags: ["deadpool-*"]
5+
branches: [ "master" ]
6+
tags: [ "deadpool-*" ]
77
pull_request:
8-
branches: ["master"]
8+
branches: [ "master" ]
99

1010
env:
1111
RUST_BACKTRACE: 1
@@ -87,8 +87,8 @@ jobs:
8787
toolchain: stable
8888

8989
- run: cargo check -p deadpool
90-
--no-default-features
91-
--features ${{ matrix.feature1 }},${{ matrix.feature2 }}
90+
--no-default-features
91+
--features ${{ matrix.feature1 }},${{ matrix.feature2 }}
9292

9393
check-integration:
9494
name: Check integration
@@ -105,7 +105,7 @@ jobs:
105105
- rt_tokio_1
106106
- rt_async-std_1
107107
- serde
108-
include: # additional inclusions for matrix
108+
include: # additional inclusions for matrix
109109
- crate: diesel
110110
feature: mysql
111111
- crate: diesel
@@ -123,7 +123,7 @@ jobs:
123123
# We don't use `--no-default-features` here as integration crates don't
124124
# work with it at all.
125125
- run: cargo check -p deadpool-${{ matrix.crate }}
126-
--features ${{ matrix.feature }}
126+
--features ${{ matrix.feature }}
127127

128128
check-integration-wasm:
129129
name: Check integration (WebAssembly)
@@ -145,9 +145,9 @@ jobs:
145145
target: wasm32-unknown-unknown
146146

147147
- run: cargo check -p deadpool-${{ matrix.crate }}
148-
--no-default-features
149-
${{ matrix.feature }}
150-
--target wasm32-unknown-unknown
148+
--no-default-features
149+
${{ matrix.feature }}
150+
--target wasm32-unknown-unknown
151151

152152
msrv:
153153
name: MSRV
@@ -210,6 +210,12 @@ jobs:
210210
--health-interval 10s
211211
--health-timeout 5s
212212
--health-retries 5
213+
redis-sentinel:
214+
image: 'bitnami/redis-sentinel:latest'
215+
env:
216+
ALLOW_EMPTY_PASSWORD: yes
217+
ports:
218+
- 26379:26379
213219
redis:
214220
image: redis:7.0-alpine
215221
ports:
@@ -241,6 +247,9 @@ jobs:
241247
PG__PASSWORD: deadpool
242248
PG__DBNAME: deadpool
243249
REDIS__URL: redis://127.0.0.1/
250+
REDIS_SENTINEL__URLS: redis://127.0.0.1:26379
251+
REDIS_SENTINEL__SERVER_TYPE: "master"
252+
REDIS_SENTINEL__MASTER_NAME: "mymaster"
244253
REDIS_CLUSTER__URLS: redis://127.0.0.1:7000,redis://127.0.0.1:7001
245254
AMQP__URL: amqp://deadpool:deadpool@127.0.0.1/deadpool
246255

redis/src/config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ impl From<redis::RedisConnectionInfo> for RedisConnectionInfo {
303303
/// This error is returned if the configuration contains an error
304304
#[derive(Debug)]
305305
pub enum ConfigError {
306+
NotEnoughInfo(String),
306307
/// Both url and connection were specified in the config
307308
UrlAndConnectionSpecified,
308309
/// The [`redis`] crate returned an error when parsing the config
@@ -323,6 +324,12 @@ impl fmt::Display for ConfigError {
323324
"url and connection must not be specified at the same time."
324325
),
325326
Self::Redis(e) => write!(f, "Redis: {}", e),
327+
Self::NotEnoughInfo(s) => {
328+
write!(
329+
f,
330+
"not enough config provided: {}", s
331+
)
332+
}
326333
}
327334
}
328335
}

redis/src/sentinel/config.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ pub struct Config {
5050
/// ServerType
5151
///
5252
/// [`SentinelServerType`]
53-
pub server_type: SentinelServerType,
53+
pub server_type: Option<SentinelServerType>,
5454
/// Sentinel setup master name. default value is `mymaster`
55-
pub master_name: String,
55+
pub master_name: Option<String>,
5656
/// [`redis::ConnectionInfo`] structures.
5757
pub connections: Option<Vec<ConnectionInfo>>,
5858
// SentinelNodeConnectionInfo doesn't implement debug, so we can't
@@ -100,24 +100,30 @@ impl Config {
100100
}
101101
});
102102

103+
if self.server_type.is_none() || self.server_type.is_none() {
104+
return Err(ConfigError::NotEnoughInfo(format!(
105+
"sentinel: client type '{:?}' or master name '{:?}' empty",
106+
self.server_type, self.master_name)))
107+
}
108+
103109
let manager = match (&self.urls, &self.connections) {
104110
(Some(urls), None) => super::Manager::new(
105111
urls.iter().map(|url| url.as_str()).collect(),
106-
self.master_name.clone(),
112+
self.master_name.clone().unwrap(),
107113
sentinel_node_connection_info,
108-
self.server_type,
114+
self.server_type.unwrap(),
109115
)?,
110116
(None, Some(connections)) => super::Manager::new(
111117
connections.clone(),
112-
self.master_name.clone(),
118+
self.master_name.clone().unwrap(),
113119
sentinel_node_connection_info,
114-
self.server_type,
120+
self.server_type.unwrap(),
115121
)?,
116122
(None, None) => super::Manager::new(
117123
vec![ConnectionInfo::default()],
118-
self.master_name.clone(),
124+
self.master_name.clone().unwrap(),
119125
sentinel_node_connection_info,
120-
self.server_type,
126+
self.server_type.unwrap(),
121127
)?,
122128
(Some(_), Some(_)) => return Err(ConfigError::UrlAndConnectionSpecified),
123129
};
@@ -143,8 +149,8 @@ impl Config {
143149
Config {
144150
urls: Some(urls.into()),
145151
connections: None,
146-
server_type,
147-
master_name,
152+
master_name: Some(master_name),
153+
server_type: Some(server_type),
148154
pool: None,
149155
sentinel_connection_info: None,
150156
}
@@ -161,8 +167,8 @@ impl Default for Config {
161167
Self {
162168
urls: None,
163169
connections: Some(vec![default_connection_info.clone()]),
164-
server_type: SentinelServerType::Master,
165-
master_name: String::from("mymaster"),
170+
server_type: Some(SentinelServerType::Master),
171+
master_name: Some(String::from("mymaster")),
166172
pool: None,
167173
sentinel_connection_info: Some(default_connection_info),
168174
}

redis/tests/redis_sentinel.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use deadpool_redis::Runtime;
99
#[derive(Debug, Default, Deserialize, Serialize)]
1010
struct Config {
1111
#[serde(default)]
12-
redis: deadpool_redis::sentinel::Config,
12+
redis_sentinel: deadpool_redis::sentinel::Config,
1313
}
1414

1515
impl Config {
@@ -25,7 +25,10 @@ impl Config {
2525

2626
fn create_pool() -> deadpool_redis::sentinel::Pool {
2727
let cfg = Config::from_env();
28-
cfg.redis.create_pool(Some(Runtime::Tokio1)).unwrap()
28+
29+
cfg.redis_sentinel
30+
.create_pool(Some(Runtime::Tokio1))
31+
.unwrap()
2932
}
3033

3134
#[tokio::test]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy