saddle-runtime 0.3.6

Saddle managed asynchronous runtime and lifecycle
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
//! Runtime consumption of the App::run-only ProfuseGW Admission profile.

use std::{
    future::{Future, poll_fn},
    panic::{AssertUnwindSafe, catch_unwind},
    pin::Pin,
    sync::{Arc, Mutex},
    task::{Context, Poll},
    time::{Duration, SystemTime, UNIX_EPOCH},
};

use saddle_admission::{
    AdmissionError, DeploymentResourceBudget, ProfuseGwLightweightAdmissionOutcome,
    ProfuseGwLightweightDbFinalizationOwner, ProfuseGwLightweightExecutionOwner,
    ProfuseGwLightweightProcessOwner, ProfuseGwLightweightStartupFailure,
    prepare_profusegw_lightweight_profile,
};
use saddle_core::{
    DbPhysicalDisposition, DbPhysicalDispositionIssuer, DbPhysicalDispositionOwner,
    DbPhysicalExecutionHalf, DbPhysicalRequestHalf, DbPhysicalRequestIssuer, DbPhysicalStartupHalf,
    pair_db_physical_disposition, seal_db_request_not_used,
};

use crate::Application;
use crate::alpha1_ingress::{
    AbsoluteDeadlineError, AbsoluteDeadlineOwner, verify_absolute_deadline,
};
use crate::application::{ShutdownSignal, claim_owned_runtime};

const PROFUSEGW_DEFAULT_REQUEST_TIMEOUT: Duration = Duration::from_millis(5_000);

#[doc(hidden)]
pub struct ProfuseGwManagedDeadline {
    unix_ms: i64,
    timer: Pin<Box<tokio::time::Sleep>>,
}

/// Sole process owner accepted by the framework-private coordinator.
#[doc(hidden)]
pub struct ProfuseGwRuntimeProcess {
    admission: ProfuseGwLightweightProcessOwner,
    db_requests: DbPhysicalRequestIssuer,
    db_startup: Option<DbPhysicalStartupHalf>,
}

struct SharedRuntimeProcess {
    process: Mutex<Option<ProfuseGwRuntimeProcess>>,
}

/// Non-cloneable access passed to the one Facade process component. The
/// authority remains owned by Runtime and is removed after terminal shutdown.
///
/// ```compile_fail
/// use saddle_runtime::profusegw::ProfuseGwProcessLease;
/// fn duplicate(lease: ProfuseGwProcessLease) {
///     let _copy = lease.clone();
/// }
/// ```
#[doc(hidden)]
pub struct ProfuseGwProcessLease {
    shared: Arc<SharedRuntimeProcess>,
}

/// The original process authority after Application terminal and owned-runtime
/// finalization. The lifecycle result cannot be discarded by the coordinator.
#[doc(hidden)]
pub struct ProfuseGwTerminalProcess {
    process: Option<ProfuseGwRuntimeProcess>,
    lifecycle: saddle_core::Result<()>,
}

/// One admitted request retaining all four credits and its Runtime deadline.
#[doc(hidden)]
pub struct ProfuseGwManagedDispatch {
    execution: ProfuseGwLightweightExecutionOwner,
    deadline: ProfuseGwManagedDeadline,
    db_request: DbPhysicalRequestHalf,
    db_execution: DbPhysicalExecutionHalf,
}

/// Concrete request lease retaining the exact Admission permit, Core request
/// pair, and Runtime's one absolute deadline while Database work is polled.
///
/// ```compile_fail
/// use saddle_runtime::profusegw::ProfuseGwConcreteDbRequestLease;
/// fn duplicate(lease: ProfuseGwConcreteDbRequestLease) {
///     let _copy = lease.clone();
/// }
/// ```
#[doc(hidden)]
pub struct ProfuseGwConcreteDbRequestLease {
    execution: ProfuseGwLightweightExecutionOwner,
    deadline: ProfuseGwManagedDeadline,
    db_request: DbPhysicalRequestHalf,
    db_execution: DbPhysicalExecutionHalf,
}

/// Runtime half retained while Database owns the paired execution half.
#[doc(hidden)]
pub struct ProfuseGwDatabaseFinalizationCompletion {
    finalization: ProfuseGwLightweightDbFinalizationOwner,
    deadline: ProfuseGwManagedDeadline,
    db_request: DbPhysicalRequestHalf,
}

impl ProfuseGwDatabaseFinalizationCompletion {
    /// Polls the request's original absolute deadline while Database attempts
    /// physical return. The completion remains intact when the deadline wins,
    /// so Database can discard the return future, detach the connection, and
    /// seal `Discarded` with the paired execution half.
    #[doc(hidden)]
    pub fn poll_physical_deadline(&mut self, context: &mut Context<'_>) -> Poll<()> {
        self.deadline.timer.as_mut().poll(context)
    }
}

/// Linear handoff split exactly once between Runtime completion and Database.
#[doc(hidden)]
pub struct ProfuseGwDatabasePhysicalFinalizationHandoff {
    completion: ProfuseGwDatabaseFinalizationCompletion,
    execution: DbPhysicalExecutionHalf,
}

/// Operation result that always returns the same request lease.
#[doc(hidden)]
pub enum ProfuseGwDatabaseOperationOutcome<T> {
    Ready(ProfuseGwConcreteDbRequestLease, T),
    TimedOut(ProfuseGwConcreteDbRequestLease),
    Cancelled(ProfuseGwConcreteDbRequestLease),
}

/// Foreign physical proof. Both owners remain available for their original
/// pairing; no Admission resource is released on this path.
#[doc(hidden)]
pub struct ProfuseGwDatabaseDispositionFailure<T> {
    completion: ProfuseGwDatabaseFinalizationCompletion,
    physical: DbPhysicalDispositionOwner<T>,
}

/// Recoverable inputs when untouched request halves do not belong together.
#[doc(hidden)]
pub struct ProfuseGwUnusedDatabaseFailure<T> {
    dispatch: ProfuseGwManagedDispatch,
    value: T,
}

#[doc(hidden)]
pub enum ProfuseGwCoordinatorAdmissionOutcome {
    Ready(ProfuseGwManagedDispatch),
    CapacityRejected,
    Stop(AdmissionError),
    DeadlineUnavailable(AbsoluteDeadlineError),
}

#[doc(hidden)]
pub enum ProfuseGwCoordinatorFailure {
    Startup(ProfuseGwLightweightStartupFailure),
    Lifecycle(saddle_core::SaddleError),
    Finalization(AdmissionError),
}

impl ProfuseGwRuntimeProcess {
    fn new(admission: ProfuseGwLightweightProcessOwner) -> Self {
        let (db_startup, db_requests) =
            DbPhysicalDispositionIssuer::issue().into_startup_and_request_issuer();
        Self {
            admission,
            db_requests,
            db_startup: Some(db_startup),
        }
    }

    /// Formal App::run request admission. Runtime creates the deadline; the
    /// adapter cannot provide a timer or enter the low-level lifecycle.
    #[doc(hidden)]
    pub fn try_admit(&self) -> ProfuseGwCoordinatorAdmissionOutcome {
        let deadline = match default_profusegw_deadline() {
            Ok((unix_ms, deadline)) => ProfuseGwManagedDeadline {
                unix_ms,
                timer: deadline.into_sleep(),
            },
            Err(error) => {
                return ProfuseGwCoordinatorAdmissionOutcome::DeadlineUnavailable(error);
            }
        };
        match self.admission.verified_profile().try_admit() {
            ProfuseGwLightweightAdmissionOutcome::Ready(permit) => {
                let Some((db_request, db_execution)) = self.db_requests.issue_request() else {
                    return ProfuseGwCoordinatorAdmissionOutcome::Stop(
                        AdmissionError::InvalidConfiguration,
                    );
                };
                ProfuseGwCoordinatorAdmissionOutcome::Ready(ProfuseGwManagedDispatch {
                    execution: permit.into_execution(),
                    deadline,
                    db_request,
                    db_execution,
                })
            }
            ProfuseGwLightweightAdmissionOutcome::CapacityRejected => {
                ProfuseGwCoordinatorAdmissionOutcome::CapacityRejected
            }
            ProfuseGwLightweightAdmissionOutcome::Stop(error) => {
                ProfuseGwCoordinatorAdmissionOutcome::Stop(error)
            }
        }
    }

    fn finish(self) -> Result<(), AdmissionError> {
        let startup_consumed = self.db_startup.is_none();
        let result = self.admission.finish();
        if !startup_consumed {
            return Err(AdmissionError::InvalidConfiguration);
        }
        result
    }
}

impl ProfuseGwProcessLease {
    /// Moves the unique Core startup half to the Facade process factory. The
    /// factory can only hand it to the one started Database owner.
    #[doc(hidden)]
    pub fn take_database_startup_half(&self) -> Option<DbPhysicalStartupHalf> {
        self.shared
            .process
            .lock()
            .unwrap_or_else(|poisoned| poisoned.into_inner())
            .as_mut()?
            .db_startup
            .take()
    }

    /// Zero-wait admission while the Application is accepting requests.
    #[doc(hidden)]
    pub fn try_admit(&self) -> ProfuseGwCoordinatorAdmissionOutcome {
        let process = self
            .shared
            .process
            .lock()
            .unwrap_or_else(|poisoned| poisoned.into_inner());
        match process.as_ref() {
            Some(process) => process.try_admit(),
            None => ProfuseGwCoordinatorAdmissionOutcome::Stop(AdmissionError::AccountClosed),
        }
    }
}

impl ProfuseGwTerminalProcess {
    fn finish(self) -> Result<(), ProfuseGwCoordinatorFailure> {
        let finalization = match self.process {
            Some(process) => process
                .finish()
                .map_err(ProfuseGwCoordinatorFailure::Finalization),
            None => Err(ProfuseGwCoordinatorFailure::Lifecycle(
                lifecycle_recovery_error(),
            )),
        };
        match self.lifecycle {
            Ok(()) => finalization,
            Err(error) => {
                let _finalization = finalization;
                Err(ProfuseGwCoordinatorFailure::Lifecycle(error))
            }
        }
    }
}

impl ProfuseGwManagedDispatch {
    /// Returns the one Runtime-created absolute deadline carried into ingress
    /// identity and every routed outbound operation.
    #[doc(hidden)]
    pub fn deadline_unix_ms(&self) -> i64 {
        self.deadline.unix_ms
    }

    /// Waits on the same Runtime timer owned by this admitted request.
    #[doc(hidden)]
    pub async fn deadline_elapsed(&mut self) {
        self.deadline.timer.as_mut().await;
    }

    #[doc(hidden)]
    pub fn cancel(self) {
        self.execution.cancel();
    }

    #[doc(hidden)]
    pub fn timeout(self) {
        self.execution.timeout();
    }

    /// Moves the whole admitted request into Database operation polling.
    #[doc(hidden)]
    pub fn into_database_request(self) -> ProfuseGwConcreteDbRequestLease {
        ProfuseGwConcreteDbRequestLease {
            execution: self.execution,
            deadline: self.deadline,
            db_request: self.db_request,
            db_execution: self.db_execution,
        }
    }
}

impl<T> ProfuseGwUnusedDatabaseFailure<T> {
    #[doc(hidden)]
    pub fn into_inputs(self) -> (ProfuseGwManagedDispatch, T) {
        (self.dispatch, self.value)
    }
}

/// Completes an admitted request that never entered Database operation polling
/// or physical finalization. The function accepts only the untouched dispatch;
/// a begun `ProfuseGwConcreteDbRequestLease` cannot enter this terminal.
///
/// ```compile_fail
/// use saddle_runtime::profusegw::{
///     ProfuseGwConcreteDbRequestLease, finish_profusegw_without_database,
/// };
/// fn cannot_release_begun(lease: ProfuseGwConcreteDbRequestLease) {
///     let _ = finish_profusegw_without_database(lease, ());
/// }
/// ```
#[doc(hidden)]
pub fn finish_profusegw_without_database<T>(
    dispatch: ProfuseGwManagedDispatch,
    value: T,
) -> Result<T, ProfuseGwUnusedDatabaseFailure<T>> {
    let ProfuseGwManagedDispatch {
        execution,
        deadline,
        db_request,
        db_execution,
    } = dispatch;
    let receipt = match seal_db_request_not_used(db_request, db_execution, value) {
        Ok(receipt) => receipt,
        Err((db_request, db_execution, value)) => {
            return Err(ProfuseGwUnusedDatabaseFailure {
                dispatch: ProfuseGwManagedDispatch {
                    execution,
                    deadline,
                    db_request,
                    db_execution,
                },
                value,
            });
        }
    };
    let value = receipt.into_value();
    execution.cancel();
    drop(deadline);
    Ok(value)
}

impl ProfuseGwConcreteDbRequestLease {
    /// Restores the pre-operation carrier without recreating any owner.
    #[doc(hidden)]
    pub fn restore_dispatch(self) -> ProfuseGwManagedDispatch {
        ProfuseGwManagedDispatch {
            execution: self.execution,
            deadline: self.deadline,
            db_request: self.db_request,
            db_execution: self.db_execution,
        }
    }

    /// Enters Admission finalization and preserves the same Core request pair
    /// and absolute deadline for Database physical disposition.
    #[doc(hidden)]
    pub fn into_physical_finalization(self) -> ProfuseGwDatabasePhysicalFinalizationHandoff {
        ProfuseGwDatabasePhysicalFinalizationHandoff {
            completion: ProfuseGwDatabaseFinalizationCompletion {
                finalization: self.execution.begin_database_finalization(),
                deadline: self.deadline,
                db_request: self.db_request,
            },
            execution: self.db_execution,
        }
    }
}

impl ProfuseGwDatabasePhysicalFinalizationHandoff {
    /// Database receives only its paired execution half. Runtime retains the
    /// Admission finalizer, request half, and deadline until sealed completion.
    #[doc(hidden)]
    pub fn into_database_execution(
        self,
    ) -> (
        ProfuseGwDatabaseFinalizationCompletion,
        DbPhysicalExecutionHalf,
    ) {
        (self.completion, self.execution)
    }
}

impl<T> ProfuseGwDatabaseDispositionFailure<T> {
    #[doc(hidden)]
    pub fn into_inputs(
        self,
    ) -> (
        ProfuseGwDatabaseFinalizationCompletion,
        DbPhysicalDispositionOwner<T>,
    ) {
        (self.completion, self.physical)
    }
}

enum OperationPoll<T> {
    Ready(T),
    TimedOut,
    Cancelled,
}

/// Polls one concrete Database operation under the admitted request permit.
/// Operation readiness wins a same-poll race; cancellation precedes timeout.
#[doc(hidden)]
pub async fn poll_profusegw_database_operation<T, O, C>(
    mut lease: ProfuseGwConcreteDbRequestLease,
    operation: O,
    cancel: C,
) -> ProfuseGwDatabaseOperationOutcome<T>
where
    O: Future<Output = T>,
    C: Future<Output = ()>,
{
    tokio::pin!(operation);
    tokio::pin!(cancel);
    let outcome = poll_fn(|context| {
        if let Poll::Ready(value) = lease
            .execution
            .poll_database_query(operation.as_mut(), context)
        {
            return Poll::Ready(OperationPoll::Ready(value));
        }
        if cancel.as_mut().poll(context).is_ready() {
            return Poll::Ready(OperationPoll::Cancelled);
        }
        if lease.deadline.timer.as_mut().poll(context).is_ready() {
            return Poll::Ready(OperationPoll::TimedOut);
        }
        Poll::Pending
    })
    .await;
    match outcome {
        OperationPoll::Ready(value) => ProfuseGwDatabaseOperationOutcome::Ready(lease, value),
        OperationPoll::TimedOut => ProfuseGwDatabaseOperationOutcome::TimedOut(lease),
        OperationPoll::Cancelled => ProfuseGwDatabaseOperationOutcome::Cancelled(lease),
    }
}

/// Pairs Database's physical proof with this exact request, reconciles the
/// Admission finalizer, and only then returns the preserved business value.
#[doc(hidden)]
pub fn finish_profusegw_database_disposition<T>(
    completion: ProfuseGwDatabaseFinalizationCompletion,
    physical: DbPhysicalDispositionOwner<T>,
) -> Result<T, ProfuseGwDatabaseDispositionFailure<T>> {
    let receipt = match pair_db_physical_disposition(physical, completion.db_request) {
        Ok(receipt) => receipt,
        Err((physical, db_request)) => {
            return Err(ProfuseGwDatabaseDispositionFailure {
                completion: ProfuseGwDatabaseFinalizationCompletion {
                    db_request,
                    ..completion
                },
                physical,
            });
        }
    };
    let (disposition, value) = receipt.into_outcome();
    let admission = match disposition {
        DbPhysicalDisposition::Returned => completion.finalization.connection_returned(),
        DbPhysicalDisposition::Discarded => completion.finalization.connection_discarded(),
    };
    admission.finish();
    drop(completion.deadline);
    Ok(value)
}

/// Sole framework-private App::run coordinator. Admission verifies the Core
/// rendezvous binding embedded in the budget, derives the four-dimensional
/// W=0 profile, and Runtime invokes exactly one process adapter.
#[doc(hidden)]
pub async fn coordinate_profusegw_app_run<Process, ProcessFuture>(
    budget: DeploymentResourceBudget,
    process: Process,
) -> Result<(), ProfuseGwCoordinatorFailure>
where
    Process: FnOnce(ProfuseGwRuntimeProcess) -> ProcessFuture,
    ProcessFuture: Future<Output = ProfuseGwTerminalProcess>,
{
    let admission = prepare_profusegw_lightweight_profile(budget)
        .map_err(ProfuseGwCoordinatorFailure::Startup)?;
    process(ProfuseGwRuntimeProcess::new(admission))
        .await
        .finish()
}

/// Runtime-owned synchronous lifecycle wrapper. The Facade factory receives a
/// single lease, constructs the Application inside this runtime, and cannot
/// retain the process authority after terminal shutdown.
#[doc(hidden)]
pub fn run_profusegw_owned_application<Factory, FactoryFuture>(
    process: ProfuseGwRuntimeProcess,
    factory: Factory,
) -> ProfuseGwTerminalProcess
where
    Factory: FnOnce(ProfuseGwProcessLease) -> FactoryFuture,
    FactoryFuture: Future<Output = saddle_core::Result<Application>>,
{
    let runtime = match claim_owned_runtime() {
        Ok(runtime) => runtime,
        Err(error) => {
            return ProfuseGwTerminalProcess {
                process: Some(process),
                lifecycle: Err(error),
            };
        }
    };
    let shared = Arc::new(SharedRuntimeProcess {
        process: Mutex::new(Some(process)),
    });
    let lease = ProfuseGwProcessLease {
        shared: Arc::clone(&shared),
    };
    let outcome = catch_unwind(AssertUnwindSafe(|| {
        runtime.block_on(async move {
            let signal = ShutdownSignal::register()?;
            let application = factory(lease).await?;
            let finalizer = application.pending_driver_finalizer();
            let result = application.run_until_shutdown(signal.wait()).await;
            Ok::<_, saddle_core::SaddleError>((finalizer, result))
        })
    }));
    let lifecycle = match outcome {
        Ok(Ok((finalizer, result))) => finalizer.finish(runtime, result),
        Ok(Err(error)) => {
            drop(runtime);
            Err(error)
        }
        Err(_) => {
            drop(runtime);
            Err(saddle_core::SaddleError::new(
                saddle_core::ErrorKind::Internal,
                "runtime.profusegw_lifecycle_panicked",
                "the ProfuseGW Application lifecycle panicked before terminal recovery",
            ))
        }
    };
    let process = shared
        .process
        .lock()
        .unwrap_or_else(|poisoned| poisoned.into_inner())
        .take();
    ProfuseGwTerminalProcess { process, lifecycle }
}

fn lifecycle_recovery_error() -> saddle_core::SaddleError {
    saddle_core::SaddleError::new(
        saddle_core::ErrorKind::Internal,
        "runtime.profusegw_owner_recovery_failed",
        "the ProfuseGW process authority was unavailable at lifecycle terminal",
    )
}

fn default_profusegw_deadline() -> Result<(i64, AbsoluteDeadlineOwner), AbsoluteDeadlineError> {
    let now = SystemTime::now()
        .duration_since(UNIX_EPOCH)
        .map_err(|_| AbsoluteDeadlineError::ClockBeforeUnixEpoch)?;
    let now_ms = u64::try_from(now.as_millis()).map_err(|_| AbsoluteDeadlineError::OutOfRange)?;
    let timeout_ms = u64::try_from(PROFUSEGW_DEFAULT_REQUEST_TIMEOUT.as_millis())
        .map_err(|_| AbsoluteDeadlineError::OutOfRange)?;
    let deadline_unix_ms = now_ms
        .checked_add(timeout_ms)
        .ok_or(AbsoluteDeadlineError::OutOfRange)?;
    let deadline = verify_absolute_deadline(deadline_unix_ms)?;
    let deadline_unix_ms =
        i64::try_from(deadline_unix_ms).map_err(|_| AbsoluteDeadlineError::OutOfRange)?;
    Ok((deadline_unix_ms, deadline))
}

#[cfg(test)]
mod tests {
    use std::sync::{
        Arc,
        atomic::{AtomicUsize, Ordering},
    };

    use super::default_profusegw_deadline;

    #[test]
    fn budget_default_deadline_is_runtime_owned_and_live() {
        let (unix_ms, _owner) = default_profusegw_deadline().unwrap();
        assert!(unix_ms > 0);
    }

    #[tokio::test]
    async fn process_adapter_shape_is_once_only() {
        async fn invoke_once<P, F, Fut>(owner: P, process: F) -> P
        where
            F: FnOnce(P) -> Fut,
            Fut: Future<Output = P>,
        {
            process(owner).await
        }

        let calls = Arc::new(AtomicUsize::new(0));
        let observed = Arc::clone(&calls);
        let owner = Box::new(41_u64);
        let address = (&*owner) as *const u64;
        let returned = invoke_once(owner, move |owner| async move {
            observed.fetch_add(1, Ordering::SeqCst);
            owner
        })
        .await;
        assert_eq!(calls.load(Ordering::SeqCst), 1);
        assert_eq!((&*returned) as *const u64, address);
    }
}