haubur commented on code in PR #3953:
URL: https://github.com/apache/iggy/pull/3953#discussion_r3854466994
##########
core/sdk/src/clients/producer_dispatcher.rs:
##########
@@ -432,4 +422,52 @@ mod tests {
assert_eq!(sharding_called.load(Ordering::SeqCst), 1);
assert_eq!(error_called.load(Ordering::SeqCst), 1);
}
+
+ #[tokio::test]
+ async fn test_shutdown_reports_errors_from_final_flush() {
+ let mut mock = MockProducerCoreBackend::new();
+ // mock a failed send to be caught by the error callback
+ mock.expect_send_internal()
+ .times(1)
+ .returning(|_, _, _, _| {
+ Box::pin(async {
+ Err(IggyError::ProducerSendFailed {
+ cause: Box::new(IggyError::Error),
+ failed: Arc::new(vec![dummy_message(10)]),
+ committed: Arc::new(Vec::new()),
+ stream_name: "1".to_string(),
+ topic_name: "1".to_string(),
+ })
+ })
+ });
+
+ let error_called = Arc::new(AtomicUsize::new(0));
+
+ let config = BackgroundConfig::builder()
+ .num_shards(1)
+ .linger_time(Duration::from_secs(60).into()) // block/ wait so
shutdown triggers the flush
+ .error_callback(Arc::new(Box::new(TestErrorCallback {
+ called: error_called.clone(),
+ })))
+ .build();
+
+ let dispatcher = ProducerDispatcher::new(Arc::new(mock), config);
+
+ dispatcher
+ .dispatch(
+ vec![dummy_message(10)],
+ dummy_identifier(),
+ dummy_identifier(),
+ None,
+ )
+ .await
+ .unwrap();
+
+ // trigger the final flush
+ dispatcher.shutdown().await;
+
+ // Passes, if the error callback is hit once after final
+ // flush from shutdown.
+ assert_eq!(error_called.load(Ordering::SeqCst), 1);
Review Comment:
makes sense, thanks
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]