State machine test for an implementation of a `KVWritable` using a sequence of random ops.
(sut: &impl KVWritable<S>, data: TestData)
| 149 | |
| 150 | /// State machine test for an implementation of a `KVWritable` using a sequence of random ops. |
| 151 | pub fn check_writable<S>(sut: &impl KVWritable<S>, data: TestData) -> bool |
| 152 | where |
| 153 | S: KVStore<Namespace = TestNamespace> + Clone + Codec<String> + Codec<u8>, |
| 154 | S::Repr: Ord + 'static, |
| 155 | { |
| 156 | let mut model = Model::default(); |
| 157 | // Creating a collection doesn't add much to the test but at least we exercise this path. |
| 158 | let mut colls = Collections::<S>::default(); |
| 159 | // Start the transaction. |
| 160 | let mut tx = sut.write(); |
| 161 | let mut ok = true; |
| 162 | for d in data.ops { |
| 163 | match d { |
| 164 | TestOpNs::S2I(ns, op) => { |
| 165 | let coll = colls.s2i(ns); |
| 166 | if !apply_both(&mut tx, &mut model.s2i, coll, ns, op) { |
| 167 | ok = false; |
| 168 | } |
| 169 | } |
| 170 | TestOpNs::I2S(ns, op) => { |
| 171 | let coll = colls.i2s(ns); |
| 172 | if !apply_both(&mut tx, &mut model.i2s, coll, ns, op) { |
| 173 | ok = false; |
| 174 | } |
| 175 | } |
| 176 | TestOpNs::Rollback => { |
| 177 | //println!("ROLLBACK"); |
| 178 | model = Model::default(); |
| 179 | tx.rollback().unwrap(); |
| 180 | tx = sut.write(); |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | tx.rollback().unwrap(); |
| 185 | ok |
| 186 | } |
| 187 | |
| 188 | /// Check that two write transactions don't see each others' changes. |
| 189 | /// |
no test coverage detected