Skip to content

Commit 39a711c

Browse files
gl-puptanji
authored andcommitted
test(redis sink): add tests for Channel publish with 0 subscribers
1 parent 6c5afd8 commit 39a711c

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Fixed an issue where the `redis` sink using `data_type: channel` would enter an infinite retry
2+
loop when a `PUBLISH` command returned `0` (no subscribers currently connected). Redis pub/sub
3+
`PUBLISH` returns the number of subscribers that received the message; zero subscribers is a
4+
valid transient state (e.g. the consumer momentarily dropped its subscription) and should not
5+
be treated as a failure.

src/sinks/redis/tests.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ use vector_lib::{
66
request_metadata::GroupedCountByteSize,
77
};
88

9-
use super::{config::RedisSinkConfig, request_builder::encode_event};
9+
use super::{
10+
DataType,
11+
config::{ListMethod, RedisSinkConfig, SortedSetMethod},
12+
request_builder::encode_event,
13+
service::RedisResponse,
14+
};
1015
use crate::{
1116
codecs::{Encoder, Transformer},
1217
config::log_schema,
@@ -124,3 +129,39 @@ fn redis_log_scoring() {
124129

125130
assert_eq!(result, Some(64));
126131
}
132+
133+
// Redis PUBLISH returns the number of subscribers that received the message as an integer.
134+
// redis-rs deserializes integer 0 as bool false, which would cause is_successful() to return
135+
// false and trigger an infinite retry loop when no subscribers are connected.
136+
#[test]
137+
fn redis_channel_publish_zero_subscribers_is_successful() {
138+
let response = RedisResponse {
139+
event_status: vec![false], // 0 subscribers → redis-rs deserializes as false
140+
data_type: DataType::Channel,
141+
events_byte_size: GroupedCountByteSize::new_untagged(),
142+
byte_size: 0,
143+
};
144+
assert!(
145+
response.is_successful(),
146+
"Channel publish with 0 subscribers should be treated as success"
147+
);
148+
}
149+
150+
#[test]
151+
fn redis_list_and_sorted_set_still_check_event_status() {
152+
for data_type in [
153+
DataType::List(ListMethod::RPush),
154+
DataType::SortedSet(SortedSetMethod::ZAdd),
155+
] {
156+
let response = RedisResponse {
157+
event_status: vec![false],
158+
data_type,
159+
events_byte_size: GroupedCountByteSize::new_untagged(),
160+
byte_size: 0,
161+
};
162+
assert!(
163+
!response.is_successful(),
164+
"{data_type:?} with false event_status should not be successful"
165+
);
166+
}
167+
}

0 commit comments

Comments
 (0)