coven_storage/memory_faults.rs
1//! Faults the in-memory provider injects into its next calls.
2
3use super::BodyFailure;
4use crate::*;
5use std::collections::{BTreeMap, BTreeSet};
6use std::time::Duration;
7
8/// Faults applied to the next calls, including accepted parts with lost replies.
9#[derive(Clone)]
10pub struct Faults {
11 /// Fail this many calls before doing their work.
12 pub fail_next: usize,
13 /// Refuse this many file uploads as they start, each with `failure`,
14 /// `response` and `retry_after` as `fail_next` fails a call: a file's
15 /// single create, or the call beginning its multipart upload. Nothing is
16 /// stored. Every other call goes through, so a pass beside the upload
17 /// can't take the fault.
18 pub refuse_file_uploads: usize,
19 /// Panic in this many file uploads as they start, as a bug in the
20 /// caller's upload would; every other call goes through.
21 pub panic_file_uploads: usize,
22 /// Panic in exact reads at these paths, as a bug in the reader would.
23 pub read_panics: BTreeSet<ObjectPath>,
24 /// Fail exact reads at these paths, retaining other in-flight responses.
25 pub read_failures: BTreeMap<ObjectPath, StorageFailure>,
26 /// Fail exact status calls at these paths, independently of reads.
27 pub status_failures: BTreeMap<ObjectPath, StorageFailure>,
28 /// Fail exact deletions at these paths; the object stays.
29 pub delete_failures: BTreeMap<ObjectPath, StorageFailure>,
30 /// Refuse creates at these paths with a provider response of this
31 /// HTTP status; nothing is stored.
32 pub create_failures: BTreeMap<ObjectPath, (StorageFailure, u16)>,
33 /// Fail listings of exactly these prefixes.
34 pub list_failures: BTreeMap<ObjectPrefix, StorageFailure>,
35 /// Maximum bytes returned by each body read; nonzero.
36 pub read_chunk_size: usize,
37 /// Failures after metadata, independently of request-start failures.
38 pub body_failures: BTreeMap<ObjectPath, BodyFailure>,
39 /// Change one byte of responses at these paths, each response
40 /// differently, as faults on the way to the device would; the stored
41 /// object stays as it was.
42 pub garbled_reads: BTreeMap<ObjectPath, Garble>,
43 /// The classification of injected failures.
44 pub failure: StorageFailure,
45 /// Injected failures arrive as a provider response with this HTTP
46 /// status (E5). None, without `retry_after`, is a request that received
47 /// no response.
48 pub response: Option<u16>,
49 /// Injected failures arrive as a response, a 429 unless `response`
50 /// names another status, asking every consumer to wait this many
51 /// seconds (`Retry-After`).
52 pub retry_after: Option<u64>,
53 /// Delay each call without blocking its executor.
54 pub delay: Duration,
55 /// Drop the next part before it is stored.
56 pub drop_part: bool,
57 /// Store the next part, but lose the reply before advancing the caller's session.
58 pub lose_part_reply: bool,
59 /// Start the next planned session's upload, but lose the reply: the
60 /// caller never learns the id of the session the provider holds.
61 pub lose_initiation_reply: bool,
62 /// Publish the next upload but lose the completion reply.
63 pub lose_completion_reply: bool,
64 /// Refuse this many upload aborts, retaining the pending bytes.
65 pub abort_failures: usize,
66 /// Expire all pending sessions before the next call.
67 pub expire_uploads: bool,
68 /// Accept creates at occupied paths, violating the provider contract.
69 pub overwrite_create: bool,
70 /// Hide published objects from listings while exact reads and status still see them.
71 pub hide_listings: bool,
72 /// Hide objects no older than this lag; exact reads still see publication.
73 pub listing_lag: Option<Duration>,
74 /// Refuse a duplicate create but fail to abort its upload session.
75 pub fail_duplicate_cleanup: bool,
76 /// Store this many creates and replacements, then answer each with a
77 /// 429, as a copy publication does when its temporary's deletion is
78 /// refused after the object is published (ยง20.6).
79 pub refuse_after_storing: usize,
80 /// Refuse this many conditional replacements with `Conflict` although
81 /// they name the current revision, leaving the object unchanged, as
82 /// OneDrive can refuse every writer of one race.
83 pub refuse_replacements: usize,
84 /// Fail every grant of access to an account with this failure, as a
85 /// provider refusing to share the store would.
86 pub grant_failure: Option<StorageFailure>,
87}
88/// Faults on the way to the device that change one byte of a response.
89#[derive(Clone, Copy, Debug)]
90pub struct Garble {
91 /// The object offset whose byte changes, in a response that holds it.
92 pub at: u64,
93 /// How many such responses change.
94 pub reads: u8,
95}
96
97impl Faults {
98 /// No failures or delays.
99 pub fn none() -> Self {
100 Self {
101 fail_next: 0,
102 refuse_file_uploads: 0,
103 panic_file_uploads: 0,
104 read_panics: BTreeSet::new(),
105 read_failures: BTreeMap::new(),
106 status_failures: BTreeMap::new(),
107 delete_failures: BTreeMap::new(),
108 create_failures: BTreeMap::new(),
109 list_failures: BTreeMap::new(),
110 read_chunk_size: 64 * 1024,
111 body_failures: BTreeMap::new(),
112 garbled_reads: BTreeMap::new(),
113 failure: StorageFailure::Network,
114 response: None,
115 retry_after: None,
116 delay: Duration::ZERO,
117 drop_part: false,
118 lose_part_reply: false,
119 lose_initiation_reply: false,
120 lose_completion_reply: false,
121 expire_uploads: false,
122 abort_failures: 0,
123 overwrite_create: false,
124 fail_duplicate_cleanup: false,
125 refuse_replacements: 0,
126 refuse_after_storing: 0,
127 grant_failure: None,
128 hide_listings: false,
129 listing_lag: None,
130 }
131 }
132}