pub struct FakeRemote { /* private fields */ }Expand description
A scripted remote system for exercising failure handling.
It creates resources by name and counts how often each was really
created: FakeRemote::applications above 1 is a duplicated side effect.
Each request consumes the next scripted Behavior; once the script is
empty, requests succeed.
A request with an idempotency key the remote has already applied returns
the earlier result without applying again, like a provider that honours
Idempotency-Key. That includes a request scripted to
Behavior::Fail: the remote answers a replay before it would evaluate
the request. Network-level behaviors (Unreachable, LoseRequest,
CommitThenDrop’s dropped answer, Hang) still happen. FakeRemote::find sees a resource only lag after
it was created, like an eventually consistent search API.
Implementations§
Source§impl FakeRemote
impl FakeRemote
Sourcepub fn new(clock: impl Clock) -> Self
pub fn new(clock: impl Clock) -> Self
A remote that reads time from clock (for the lookup lag).
Sourcepub fn script(self, behaviors: impl IntoIterator<Item = Behavior>) -> Self
pub fn script(self, behaviors: impl IntoIterator<Item = Behavior>) -> Self
Queues behaviors for the next requests, in order.
Sourcepub fn lag(self, lag: Duration) -> Self
pub fn lag(self, lag: Duration) -> Self
Makes Self::find lag lag behind creation.
Sourcepub async fn create(
&self,
resource: &str,
idempotency_key: Option<IdempotencyKey>,
) -> Result<String, EffectFailure>
pub async fn create( &self, resource: &str, idempotency_key: Option<IdempotencyKey>, ) -> Result<String, EffectFailure>
Creates resource, deduplicating on idempotency_key if given.
Returns the resource’s id.
§Errors
Whatever the script says.
Sourcepub async fn find(
&self,
resource: &str,
) -> Result<Option<String>, EffectFailure>
pub async fn find( &self, resource: &str, ) -> Result<Option<String>, EffectFailure>
Looks resource up, seeing it only once the lookup lag has passed.
§Errors
Never; the signature matches a real lookup.
Sourcepub fn applications(&self, resource: &str) -> u32
pub fn applications(&self, resource: &str) -> u32
How often resource was really created. More than 1 is a duplicate.
Sourcepub async fn cancel(
&self,
resource: &str,
idempotency_key: Option<IdempotencyKey>,
) -> Result<(), EffectFailure>
pub async fn cancel( &self, resource: &str, idempotency_key: Option<IdempotencyKey>, ) -> Result<(), EffectFailure>
Undoes resource, deduplicating on idempotency_key if given. Each
request consumes the next scripted Behavior, like create:
CommitThenDrop cancels and then reports an ambiguous failure.
Cancelling a resource that does not exist succeeds and changes
nothing, as idempotent deletes do.
§Errors
Whatever the script says.
Sourcepub fn cancellations(&self, resource: &str) -> u32
pub fn cancellations(&self, resource: &str) -> u32
How often resource was really cancelled. More than 1 means an undo
ran twice.