@@ -223,10 +223,48 @@ TEST(test_slowlog_statsd) {
223223 PASS (NULL );
224224}
225225
226+ TEST (test_failed_command_slowlog ) {
227+ struct mbuf buf ;
228+ struct command cmd ;
229+ memset (& cmd , 0 , sizeof (struct command ));
230+ STAILQ_INIT (& cmd .sub_cmds );
231+
232+ struct reader r = {0 };
233+ const char cmd_data [] = "*2\r\n$4\r\nMGET\r\n$4\r\nkey1\r\n" ;
234+ buf .pos = (uint8_t * )cmd_data ;
235+ buf .last = (uint8_t * )cmd_data + strlen (cmd_data );
236+ reader_init (& r );
237+ reader_feed (& r , & buf );
238+ ASSERT (parse (& r , MODE_REQ ) != -1 );
239+ cmd .data = r .data ;
240+ cmd .prefix = NULL ;
241+
242+ struct command sub_cmd ;
243+ sub_cmd .parent = & cmd ;
244+ STAILQ_INSERT_TAIL (& cmd .sub_cmds , & sub_cmd , sub_cmd_next );
245+
246+ // When corvus fails to redirect command, these two fields may be zero.
247+ cmd .rep_time [0 ] = 0 ;
248+ cmd .rep_time [1 ] = 0 ;
249+ sub_cmd .rep_time [0 ] = 0 ;
250+ sub_cmd .rep_time [1 ] = 0 ;
251+
252+ struct slowlog_entry * entry = slowlog_create_entry (& cmd , 0 , 666233 );
253+ ASSERT (entry -> remote_latency == 0 );
254+ ASSERT (entry -> total_latency == 666233 );
255+ slowlog_dec_ref (entry );
256+ entry = slowlog_create_sub_entry (& cmd , 666233 );
257+ ASSERT (NULL == entry );
258+
259+ redis_data_free (& cmd .data );
260+ PASS (NULL );
261+ }
262+
226263TEST_CASE (test_slowlog ) {
227264 RUN_TEST (test_slowlog_create_entry );
228265 RUN_TEST (test_slowlog_create_entry_with_prefix );
229266 RUN_TEST (test_slowlog_create_entry_with_long_arg );
230267 RUN_TEST (test_slowlog_statsd );
231268 RUN_TEST (test_entry_get_set );
269+ RUN_TEST (test_failed_command_slowlog );
232270}
0 commit comments