rocketmq-transport 1.0.0

Bounded TCP/TLS transport for RocketMQ Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
// Copyright 2026 The RocketMQ Rust Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! request processor and response-write observation contracts.

use std::time::Duration;

use crate::dispatch::DeferredTerminalReason;
use crate::dispatch::IngressRequestView;
use crate::dispatch::RemotingRequest;
use crate::dispatch::RemotingResponse;
use crate::dispatch::RequestId;
use crate::dispatch::ResponseAction;
use crate::dispatch::ResponseBodyKind;
use crate::dispatch::ResponseCompletionOutcome;
use crate::dispatch::ResponseOperationalFailure;
use crate::dispatch::ResponseReceipt;
use crate::dispatch::WriteProgress;
use crate::request_ordering::RequestOrdering;

/// Decision returned before a request enters processor execution.
///
/// A rejection owns its remoting response. The decision is affine because cloning
/// it would duplicate response ownership.
///
/// ```compile_fail
/// use rocketmq_transport::api::RejectRequestDecision;
///
/// fn decisions_are_affine(decision: &RejectRequestDecision) {
///     let _: RejectRequestDecision = decision.clone();
/// }
/// ```
#[must_use]
#[derive(Debug, Default)]
#[allow(
    clippy::large_enum_variant,
    reason = "the public contract requires direct affine RemotingResponse ownership without indirection"
)]
pub enum RejectRequestDecision {
    /// Continue with normal request processing.
    #[default]
    Proceed,
    /// Reject processing and deliver the owned remoting response.
    Reject(RemotingResponse),
}

/// Response lifecycle path observed at the canonical write boundary.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum ResponseWritePath {
    /// The handler completed its response during inline dispatch.
    Inline,
    /// A deferred registration completed the response later.
    Deferred,
}

/// Lifecycle mode for a body-free response observation.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum ResponseObservationMode {
    /// The request completed during inline dispatch.
    Inline,
    /// The request transferred response ownership and completed later.
    Deferred,
    /// The request intentionally produced no response frame.
    NoResponse,
}

/// One typed response lifecycle event.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum ResponseObservationOutcome {
    /// The canonical response owner reached its transport disposition.
    Written(ResponseReceipt),
    /// The immutable ingress request was one-way.
    Oneway,
    /// Protocol policy explicitly permits no response.
    ProtocolNoResponse,
    /// A deferred response ended without attempting a remoting response.
    Cancelled(DeferredTerminalReason),
    /// Response processing or delivery failed with redacted metadata.
    Failed {
        /// Source-free completion state when the failure was a normal rejection.
        completion: Option<ResponseCompletionOutcome>,
        /// Socket-write progress, when known.
        progress: Option<WriteProgress>,
    },
}

/// Body-free metadata for one response lifecycle observation.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ResponseMetadata {
    request_id: RequestId,
    original_code: i32,
    response_code: Option<i32>,
    body_kind: Option<ResponseBodyKind>,
    mode: ResponseObservationMode,
    outcome: ResponseObservationOutcome,
}

impl ResponseMetadata {
    pub(crate) const fn new(
        request_id: RequestId,
        original_code: i32,
        response_code: Option<i32>,
        body_kind: Option<ResponseBodyKind>,
        mode: ResponseObservationMode,
        outcome: ResponseObservationOutcome,
    ) -> Self {
        Self {
            request_id,
            original_code,
            response_code,
            body_kind,
            mode,
            outcome,
        }
    }

    /// Returns the immutable process-local request identity.
    #[must_use]
    pub const fn request_id(self) -> RequestId {
        self.request_id
    }

    /// Returns the original raw request code captured at ingress.
    #[must_use]
    pub const fn original_code(self) -> i32 {
        self.original_code
    }

    /// Returns the response code without exposing a response command.
    #[must_use]
    pub const fn response_code(self) -> Option<i32> {
        self.response_code
    }

    /// Returns the remoting response's storage category without exposing its body.
    #[must_use]
    pub const fn body_kind(self) -> Option<ResponseBodyKind> {
        self.body_kind
    }

    /// Returns the response lifecycle mode.
    #[must_use]
    pub const fn mode(self) -> ResponseObservationMode {
        self.mode
    }

    /// Returns the typed response lifecycle outcome.
    #[must_use]
    pub const fn outcome(self) -> ResponseObservationOutcome {
        self.outcome
    }
}

/// Body-free  response observation correlated to one request span.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ResponseObservation {
    metadata: ResponseMetadata,
    write_elapsed: Option<Duration>,
    end_to_end_elapsed: Duration,
}

impl ResponseObservation {
    pub(crate) const fn new(
        metadata: ResponseMetadata,
        write_elapsed: Option<Duration>,
        end_to_end_elapsed: Duration,
    ) -> Self {
        Self {
            metadata,
            write_elapsed,
            end_to_end_elapsed,
        }
    }

    /// Returns body-free response metadata.
    #[must_use]
    pub const fn metadata(self) -> ResponseMetadata {
        self.metadata
    }

    /// Returns canonical delivery time when a write was attempted.
    #[must_use]
    pub const fn write_elapsed(self) -> Option<Duration> {
        self.write_elapsed
    }

    /// Returns elapsed time from trusted ingress to this observation.
    #[must_use]
    pub const fn end_to_end_elapsed(self) -> Duration {
        self.end_to_end_elapsed
    }

    /// Projects write-specific metadata when this lifecycle event attempted a response write.
    #[must_use]
    pub fn write_projection(self) -> Option<ResponseWriteObservation> {
        let response_code = self.metadata.response_code?;
        let body_kind = self.metadata.body_kind?;
        let path = match self.metadata.mode {
            ResponseObservationMode::Inline => ResponseWritePath::Inline,
            ResponseObservationMode::Deferred => ResponseWritePath::Deferred,
            ResponseObservationMode::NoResponse => return None,
        };
        let outcome = match self.metadata.outcome {
            ResponseObservationOutcome::Written(receipt) => ResponseWriteOutcome::Written(receipt),
            ResponseObservationOutcome::Failed { completion, progress } => {
                ResponseWriteOutcome::Failed { completion, progress }
            }
            ResponseObservationOutcome::Oneway
            | ResponseObservationOutcome::ProtocolNoResponse
            | ResponseObservationOutcome::Cancelled(_) => return None,
        };
        Some(ResponseWriteObservation {
            request_id: self.metadata.request_id,
            original_code: self.metadata.original_code,
            response_code,
            body_kind,
            path,
            write_elapsed: self.write_elapsed.unwrap_or(Duration::ZERO),
            end_to_end_elapsed: self.end_to_end_elapsed,
            outcome,
        })
    }

    pub(crate) fn from_write_result(
        request_id: RequestId,
        original_code: i32,
        response_code: i32,
        body_kind: ResponseBodyKind,
        path: ResponseWritePath,
        write_elapsed: Duration,
        end_to_end_elapsed: Duration,
        result: &Result<ResponseCompletionOutcome, ResponseOperationalFailure>,
    ) -> Self {
        let mode = match path {
            ResponseWritePath::Inline => ResponseObservationMode::Inline,
            ResponseWritePath::Deferred => ResponseObservationMode::Deferred,
        };
        let outcome = match result {
            Ok(ResponseCompletionOutcome::Completed(receipt)) => ResponseObservationOutcome::Written(*receipt),
            Ok(outcome) => ResponseObservationOutcome::Failed {
                completion: Some(*outcome),
                progress: response_completion_progress(*outcome),
            },
            Err(error) => ResponseObservationOutcome::Failed {
                completion: None,
                progress: Some(error.write_progress()),
            },
        };
        Self::new(
            ResponseMetadata::new(
                request_id,
                original_code,
                Some(response_code),
                Some(body_kind),
                mode,
                outcome,
            ),
            Some(write_elapsed),
            end_to_end_elapsed,
        )
    }
}

/// Typed result recorded at the canonical response-write boundary.
///
/// Failure values retain only a stable error category and optional write
/// progress. Source errors and their messages are discarded before an
/// observation is created.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum ResponseWriteOutcome {
    /// The canonical response path reached its transport-specific disposition.
    Written(ResponseReceipt),
    /// Response delivery failed with stable, body-free metadata.
    Failed {
        /// Source-free completion state when the failure was a normal rejection.
        completion: Option<ResponseCompletionOutcome>,
        /// Socket-write progress, when the failure describes a write attempt.
        progress: Option<WriteProgress>,
    },
}

impl ResponseWriteOutcome {
    #[cfg(test)]
    fn from_result(result: Result<ResponseCompletionOutcome, ResponseOperationalFailure>) -> Self {
        match result {
            Ok(ResponseCompletionOutcome::Completed(receipt)) => Self::Written(receipt),
            Ok(outcome) => Self::Failed {
                completion: Some(outcome),
                progress: response_completion_progress(outcome),
            },
            Err(error) => Self::Failed {
                completion: None,
                progress: Some(error.write_progress()),
            },
        }
    }
}

const fn response_completion_progress(outcome: ResponseCompletionOutcome) -> Option<WriteProgress> {
    match outcome {
        ResponseCompletionOutcome::Completed(_) | ResponseCompletionOutcome::AlreadyCompleted(_) => None,
        ResponseCompletionOutcome::DeadlineExpired
        | ResponseCompletionOutcome::Cancelled
        | ResponseCompletionOutcome::SessionClosed
        | ResponseCompletionOutcome::QueueSaturated => Some(WriteProgress::NotStarted),
    }
}

/// Body-free metadata for one completed response write.
///
/// The observation identifies the immutable ingress request and response
/// metadata without retaining the response body, source error, channel,
/// connection context, or response sink.
///
/// ```compile_fail
/// use rocketmq_transport::api::ResponseWriteObservation;
///
/// fn bodies_are_not_observable(observation: &ResponseWriteObservation) {
///     let _ = observation.body();
/// }
/// ```
///
/// ```compile_fail
/// use rocketmq_transport::api::{
///    RequestId, ResponseBodyKind, ResponseWriteObservation, ResponseWriteOutcome,
///     ResponseWritePath,
/// };
/// use std::time::Duration;
///
/// fn observations_cannot_be_forged(
///     request_id: RequestId,
///    outcome: ResponseWriteOutcome,
/// ) -> ResponseWriteObservation {
///    ResponseWriteObservation {
///         request_id,
///         original_code: 39,
///         response_code: 0,
///         body_kind: ResponseBodyKind::Empty,
///         path: ResponseWritePath::Inline,
///         write_elapsed: Duration::ZERO,
///         end_to_end_elapsed: Duration::ZERO,
///         outcome,
///     }
/// }
/// ```
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ResponseWriteObservation {
    request_id: RequestId,
    original_code: i32,
    response_code: i32,
    body_kind: ResponseBodyKind,
    path: ResponseWritePath,
    write_elapsed: Duration,
    end_to_end_elapsed: Duration,
    outcome: ResponseWriteOutcome,
}

impl ResponseWriteObservation {
    #[cfg(test)]
    pub(crate) fn from_result(
        request_id: RequestId,
        original_code: i32,
        response_code: i32,
        body_kind: ResponseBodyKind,
        path: ResponseWritePath,
        write_elapsed: Duration,
        end_to_end_elapsed: Duration,
        result: Result<ResponseCompletionOutcome, ResponseOperationalFailure>,
    ) -> Self {
        Self {
            request_id,
            original_code,
            response_code,
            body_kind,
            path,
            write_elapsed,
            end_to_end_elapsed,
            outcome: ResponseWriteOutcome::from_result(result),
        }
    }

    /// Returns the exact process-local request identity captured at ingress.
    #[must_use]
    pub const fn request_id(&self) -> RequestId {
        self.request_id
    }

    /// Returns the original raw request code captured at ingress.
    #[must_use]
    pub const fn original_code(&self) -> i32 {
        self.original_code
    }

    /// Returns the response code that was written or attempted.
    #[must_use]
    pub const fn response_code(&self) -> i32 {
        self.response_code
    }

    /// Returns the storage category of the response body without exposing it.
    #[must_use]
    pub const fn body_kind(&self) -> ResponseBodyKind {
        self.body_kind
    }

    /// Returns the response lifecycle path that reached the write boundary.
    #[must_use]
    pub const fn path(&self) -> ResponseWritePath {
        self.path
    }

    /// Returns the time spent awaiting canonical response delivery.
    #[must_use]
    pub const fn write_elapsed(&self) -> Duration {
        self.write_elapsed
    }

    /// Returns elapsed time from request ingress through response completion.
    #[must_use]
    pub const fn end_to_end_elapsed(&self) -> Duration {
        self.end_to_end_elapsed
    }

    /// Returns the typed, body-free response-write result.
    #[must_use]
    pub const fn outcome(&self) -> ResponseWriteOutcome {
        self.outcome
    }
}

const fn default_request_ordering() -> RequestOrdering {
    RequestOrdering::Concurrent
}

/// Local and production-send variants of the request processor contract.
///
/// The generated [`RequestProcessor`] trait requires both the processor and
/// the future returned by [`RequestProcessor::process`] to be `Send`.
/// [`LocalRequestProcessor`] permits a local future for embedded or test
/// environments that do not cross executor threads.
///
/// ```
/// use rocketmq_transport::api::{
///    ResponseAction, LocalRequestProcessor, RemotingRequest,
/// };
///
/// struct Processor;
///
/// impl LocalRequestProcessor for Processor {
///     async fn process(
///         &mut self,
///         _request: &mut RemotingRequest,
///     ) -> Result<ResponseAction, rocketmq_error::SharedError> {
///         Err(std::sync::Arc::new(
///             rocketmq_error::Error::new(&rocketmq_error::CORE_ARGUMENT_INVALID).with_context(
///                 rocketmq_error::ErrorContext::new()
///                     .with_secret_presence(rocketmq_error::fields::MESSAGE_PRESENT),
///             ),
///         ))
///     }
/// }
/// ```
///
/// ```compile_fail
/// use std::rc::Rc;
///
/// use rocketmq_transport::api::{
///    ResponseAction, RemotingRequest, RequestProcessor,
/// };
///
/// struct NonSendFutureProcessor;
///
/// impl RequestProcessor for NonSendFutureProcessor {
///     async fn process(
///         &mut self,
///         _request: &mut RemotingRequest,
///     ) -> Result<ResponseAction, rocketmq_error::SharedError> {
///         let local = Rc::new(());
///         std::future::ready(()).await;
///         drop(local);
///         Err(std::sync::Arc::new(
///             rocketmq_error::Error::new(&rocketmq_error::CORE_ARGUMENT_INVALID).with_context(
///                 rocketmq_error::ErrorContext::new()
///                     .with_secret_presence(rocketmq_error::fields::MESSAGE_PRESENT),
///             ),
///         ))
///     }
/// }
/// ```
#[trait_variant::make(RequestProcessor: Send)]
pub trait LocalRequestProcessor {
    /// Asynchronously processes one owned mutable request aggregate.
    ///
    /// This method does not block the calling thread. The returned
    /// [`ResponseAction`] is the only handler response contract.
    ///
    /// # Errors
    ///
    /// Returns [`rocketmq_error::SharedError`] when request processing
    /// cannot produce a terminal handler outcome.
    async fn process(&mut self, request: &mut RemotingRequest) -> Result<ResponseAction, rocketmq_error::SharedError>;

    /// Decides whether a raw request code should enter processor execution.
    ///
    /// The default permits processing.
    fn reject_request(&self, _code: i32) -> RejectRequestDecision {
        RejectRequestDecision::Proceed
    }

    /// Declares per-session ordering from immutable ingress metadata.
    ///
    /// The default permits concurrent execution. The borrowed ingress view
    /// contains no request body.
    fn request_ordering(&self, _ingress: IngressRequestView<'_>) -> RequestOrdering {
        default_request_ordering()
    }

    /// Observes response lifecycle metadata without access to request or response bodies.
    ///
    /// The default performs no work.
    fn observe_response(&self, _observation: ResponseObservation) {}
}

#[cfg(test)]
mod tests {
    use std::rc::Rc;

    use super::*;
    use crate::dispatch::ResponseBody;
    use crate::dispatch::ResponseDisposition;
    use crate::dispatch::ResponseTerminalState;

    struct LocalFutureProcessor;

    impl LocalRequestProcessor for LocalFutureProcessor {
        async fn process(
            &mut self,
            _request: &mut RemotingRequest,
        ) -> Result<ResponseAction, rocketmq_error::SharedError> {
            let local = Rc::new(());
            std::future::ready(()).await;
            drop(local);
            Err(crate::error_helpers::argument_invalid())
        }
    }

    fn assert_local_processor<T: LocalRequestProcessor>() {}

    #[test]
    fn local_processor_accepts_a_non_send_future_and_defaults_are_low_cost() {
        assert_local_processor::<LocalFutureProcessor>();
        let processor = LocalFutureProcessor;

        assert!(matches!(processor.reject_request(39), RejectRequestDecision::Proceed));
        assert_eq!(default_request_ordering(), RequestOrdering::Concurrent);

        let request_id = RequestId::real(7, 9).expect("real request identity");
        let observation = ResponseObservation::from_write_result(
            request_id,
            39,
            0,
            ResponseBodyKind::Empty,
            ResponseWritePath::Inline,
            Duration::from_millis(2),
            Duration::from_millis(5),
            &Ok(ResponseCompletionOutcome::Completed(ResponseReceipt::new(
                request_id,
                ResponseDisposition::TransportWritten,
            ))),
        );
        processor.observe_response(observation);
    }

    #[test]
    fn rejection_moves_the_owned_remoting_response() {
        let response = RemotingResponse::bytes(
            rocketmq_protocol::protocol::remoting_command::RemotingCommand::create_response_command_with_code(7),
            bytes::Bytes::from_static(b"owned response"),
        )
        .expect("remoting response");
        let ResponseBody::Bytes(body) = response.test_body() else {
            panic!("byte response should retain contiguous storage");
        };
        let pointer = body.as_ptr();

        let decision = RejectRequestDecision::Reject(response);
        let RejectRequestDecision::Reject(response) = decision else {
            panic!("rejection should retain its response");
        };
        let ResponseBody::Bytes(body) = response.test_body() else {
            panic!("rejection should retain contiguous storage");
        };
        assert_eq!(body.as_ptr(), pointer);
        assert_eq!(response.body_kind(), ResponseBodyKind::Bytes);
        assert_eq!(response.body_len(), 14);
    }

    #[test]
    fn observation_maps_written_receipts_without_retaining_response_payloads() {
        let request_id = RequestId::real(11, 13).expect("real request identity");
        let receipt = ResponseReceipt::new(request_id, ResponseDisposition::InProcessAccepted);
        let observation = ResponseWriteObservation::from_result(
            request_id,
            220,
            17,
            ResponseBodyKind::Segments,
            ResponseWritePath::Deferred,
            Duration::from_millis(3),
            Duration::from_millis(8),
            Ok(ResponseCompletionOutcome::Completed(receipt)),
        );

        assert_eq!(observation.request_id(), request_id);
        assert_eq!(observation.original_code(), 220);
        assert_eq!(observation.response_code(), 17);
        assert_eq!(observation.body_kind(), ResponseBodyKind::Segments);
        assert_eq!(observation.path(), ResponseWritePath::Deferred);
        assert_eq!(observation.write_elapsed(), Duration::from_millis(3));
        assert_eq!(observation.end_to_end_elapsed(), Duration::from_millis(8));
        assert_eq!(observation.outcome(), ResponseWriteOutcome::Written(receipt));
    }

    #[test]
    fn observation_maps_failure_kind_and_progress_without_the_source_error() {
        let request_id = RequestId::real(17, 19).expect("real request identity");
        let observation = ResponseWriteObservation::from_result(
            request_id,
            40,
            1,
            ResponseBodyKind::FileRegions,
            ResponseWritePath::Inline,
            Duration::from_micros(7),
            Duration::from_micros(11),
            Err(ResponseOperationalFailure::Transport {
                progress: WriteProgress::PossiblyPartial,
                source: crate::error_helpers::connection_failed(
                    crate::error_helpers::TransportStage::Write,
                    std::io::Error::other("transport source must not be retained"),
                ),
            }),
        );
        assert_eq!(
            observation.outcome(),
            ResponseWriteOutcome::Failed {
                completion: None,
                progress: Some(WriteProgress::PossiblyPartial),
            }
        );
        assert!(!format!("{observation:?}").contains("transport source must not be retained"));

        let already_completed = ResponseWriteObservation::from_result(
            request_id,
            40,
            1,
            ResponseBodyKind::Empty,
            ResponseWritePath::Inline,
            Duration::ZERO,
            Duration::ZERO,
            Ok(ResponseCompletionOutcome::AlreadyCompleted(
                ResponseTerminalState::Completed,
            )),
        );
        assert_eq!(
            already_completed.outcome(),
            ResponseWriteOutcome::Failed {
                completion: Some(ResponseCompletionOutcome::AlreadyCompleted(
                    ResponseTerminalState::Completed,
                )),
                progress: None,
            }
        );
    }
}