feat(protocol): client-message channel and rsync partial exit 23 (2.30.0)
This commit is contained in:
@@ -117,6 +117,54 @@ static void test_log_stderr_mode_all() {
|
||||
log_set_stderr_mode(LOG_STDERR_ERRORS);
|
||||
}
|
||||
|
||||
/* --stderr=client: an installed sink takes the message body and suppresses the
|
||||
* local write; a declining sink (or no sink) falls back to stderr. */
|
||||
static char g_client_msg_capture[256];
|
||||
|
||||
static bool client_msg_capture_sink(const char* message) {
|
||||
snprintf(g_client_msg_capture, sizeof(g_client_msg_capture), "%s", message);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool client_msg_decline_sink(const char* message) {
|
||||
(void)message;
|
||||
return false;
|
||||
}
|
||||
|
||||
static void test_log_stderr_mode_client() {
|
||||
int pipe_fds[2];
|
||||
EXPECT_EQ_INT(pipe(pipe_fds), 0);
|
||||
int saved_stderr = dup(STDERR_FILENO);
|
||||
EXPECT_TRUE(saved_stderr >= 0);
|
||||
EXPECT_TRUE(dup2(pipe_fds[1], STDERR_FILENO) >= 0);
|
||||
close(pipe_fds[1]);
|
||||
|
||||
set_log_level(LOG_LEVEL_WARNING);
|
||||
log_set_stderr_mode(LOG_STDERR_CLIENT);
|
||||
|
||||
g_client_msg_capture[0] = '\0';
|
||||
log_set_client_msg_sink(client_msg_capture_sink);
|
||||
log_message(LOG_LEVEL_ERROR, "routed to peer %d", 7);
|
||||
fflush(stderr);
|
||||
EXPECT_EQ_STR(g_client_msg_capture, "routed to peer 7");
|
||||
|
||||
/* A sink that declines makes the message fall back to local stderr. */
|
||||
log_set_client_msg_sink(client_msg_decline_sink);
|
||||
log_message(LOG_LEVEL_ERROR, "fallback local");
|
||||
fflush(stderr);
|
||||
|
||||
log_set_client_msg_sink(NULL);
|
||||
log_set_stderr_mode(LOG_STDERR_ERRORS);
|
||||
EXPECT_TRUE(dup2(saved_stderr, STDERR_FILENO) >= 0);
|
||||
close(saved_stderr);
|
||||
char output[256] = {0};
|
||||
ssize_t length = read(pipe_fds[0], output, sizeof(output) - 1);
|
||||
close(pipe_fds[0]);
|
||||
EXPECT_TRUE(length > 0);
|
||||
EXPECT_TRUE(strstr(output, "fallback local") != NULL);
|
||||
EXPECT_TRUE(strstr(output, "routed to peer") == NULL);
|
||||
}
|
||||
|
||||
/* Test that log_message handles various format strings */
|
||||
static void test_log_message_formats() {
|
||||
set_log_level(LOG_LEVEL_DEBUG);
|
||||
@@ -271,6 +319,7 @@ void test_log() {
|
||||
test_log_set_level_error();
|
||||
test_log_filtering();
|
||||
test_log_stderr_mode_all();
|
||||
test_log_stderr_mode_client();
|
||||
test_log_message_formats();
|
||||
test_log_debug_enabled_matches_gate();
|
||||
test_log_concurrent_no_torn_lines();
|
||||
|
||||
Reference in New Issue
Block a user