Skip to content

Commit 51e52a9

Browse files
committed
graph: Do not use mockall for the MockStore
1 parent 1b66b44 commit 51e52a9

File tree

5 files changed

+52
-109
lines changed

5 files changed

+52
-109
lines changed

Cargo.lock

Lines changed: 2 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

graph/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ fail = { version = "0.5", features = ["failpoints"] }
2323
futures = "0.1.21"
2424
graphql-parser = "0.4.0"
2525
lazy_static = "1.4.0"
26-
mockall = "0.8.3"
2726
num-bigint = { version = "^0.2.6", features = ["serde"] }
2827
num_cpus = "1.13.1"
2928
num-traits = "0.2.14"

graph/src/components/store.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ use futures::stream::poll_fn;
22
use futures::{Async, Poll, Stream};
33
use graphql_parser::schema as s;
44
use lazy_static::lazy_static;
5-
use mockall::predicate::*;
6-
use mockall::*;
75
use serde::{Deserialize, Serialize};
86
use stable_hash::prelude::*;
97
use std::collections::btree_map::Entry;
@@ -1115,15 +1113,6 @@ pub trait QueryStoreManager: Send + Sync + 'static {
11151113
) -> Result<Arc<dyn QueryStore + Send + Sync>, QueryExecutionError>;
11161114
}
11171115

1118-
mock! {
1119-
pub Store {
1120-
fn get_many_mock<'a>(
1121-
&self,
1122-
_ids_for_type: BTreeMap<&'a EntityType, Vec<&'a str>>,
1123-
) -> Result<BTreeMap<EntityType, Vec<Entity>>, StoreError>;
1124-
}
1125-
}
1126-
11271116
// The type that the connection pool uses to track wait times for
11281117
// connection checkouts
11291118
pub type PoolWaitStats = Arc<RwLock<MovingStats>>;

graph/src/lib.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ pub mod firehose;
2727
/// Helpers for parsing environment variables.
2828
pub mod env;
2929

30-
/// Module with mocks for different parts of the system.
31-
pub mod mock {
32-
pub use crate::components::store::MockStore;
33-
}
34-
3530
/// Wrapper for spawning tasks that abort on panic, which is our default.
3631
mod task_spawn;
3732
pub use task_spawn::{
@@ -40,7 +35,6 @@ pub use task_spawn::{
4035

4136
pub use anyhow;
4237
pub use bytes;
43-
pub use mockall;
4438
pub use parking_lot;
4539
pub use petgraph;
4640
pub use prometheus;

graph/tests/entity_cache.rs

Lines changed: 50 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ use graph::blockchain::BlockPtr;
33
use graph::data::subgraph::schema::{SubgraphError, SubgraphHealth};
44
use graph::prelude::{Schema, StopwatchMetrics, StoreError};
55
use lazy_static::lazy_static;
6-
use mockall::predicate::*;
7-
use mockall::*;
86
use slog::Logger;
97
use std::collections::BTreeMap;
108
use std::sync::Arc;
@@ -21,12 +19,13 @@ lazy_static! {
2119
DeploymentLocator::new(DeploymentId::new(-12), SUBGRAPH_ID.clone());
2220
}
2321

24-
mock! {
25-
pub Store {
26-
fn get_many_mock<'a>(
27-
&self,
28-
_ids_for_type: BTreeMap<&'a EntityType, Vec<&'a str>>,
29-
) -> Result<BTreeMap<EntityType, Vec<Entity>>, StoreError>;
22+
struct MockStore {
23+
get_many_res: BTreeMap<EntityType, Vec<Entity>>,
24+
}
25+
26+
impl MockStore {
27+
fn new(get_many_res: BTreeMap<EntityType, Vec<Entity>>) -> Self {
28+
Self { get_many_res }
3029
}
3130
}
3231

@@ -83,9 +82,9 @@ impl WritableStore for MockStore {
8382

8483
fn get_many(
8584
&self,
86-
ids_for_type: BTreeMap<&EntityType, Vec<&str>>,
85+
_ids_for_type: BTreeMap<&EntityType, Vec<&str>>,
8786
) -> Result<BTreeMap<EntityType, Vec<Entity>>, StoreError> {
88-
self.get_many_mock(ids_for_type)
87+
Ok(self.get_many_res.clone())
8988
}
9089

9190
async fn is_deployment_synced(&self) -> Result<bool, StoreError> {
@@ -131,21 +130,17 @@ fn sort_by_entity_key(mut mods: Vec<EntityModification>) -> Vec<EntityModificati
131130

132131
#[tokio::test]
133132
async fn empty_cache_modifications() {
134-
let store = Arc::new(MockStore::new());
133+
let store = Arc::new(MockStore::new(BTreeMap::new()));
135134
let cache = EntityCache::new(store.clone());
136135
let result = cache.as_modifications();
137136
assert_eq!(result.unwrap().modifications, vec![]);
138137
}
139138

140139
#[test]
141140
fn insert_modifications() {
142-
let mut store = MockStore::new();
143-
144141
// Return no entities from the store, forcing the cache to treat any `set`
145142
// operation as an insert.
146-
store
147-
.expect_get_many_mock()
148-
.returning(|_| Ok(BTreeMap::new()));
143+
let store = MockStore::new(BTreeMap::new());
149144

150145
let store = Arc::new(store);
151146
let mut cache = EntityCache::new(store.clone());
@@ -178,33 +173,34 @@ fn insert_modifications() {
178173
);
179174
}
180175

176+
fn entity_version_map(
177+
entity_type: &str,
178+
entities: Vec<Entity>,
179+
) -> BTreeMap<EntityType, Vec<Entity>> {
180+
let mut map = BTreeMap::new();
181+
map.insert(EntityType::from(entity_type), entities);
182+
map
183+
}
184+
181185
#[test]
182186
fn overwrite_modifications() {
183-
let mut store = MockStore::new();
184-
185187
// Pre-populate the store with entities so that the cache treats
186188
// every set operation as an overwrite.
187-
store.expect_get_many_mock().returning(|_| {
188-
let mut map = BTreeMap::new();
189-
190-
map.insert(
191-
EntityType::from("Band"),
192-
vec![
193-
make_band(
194-
"mogwai",
195-
vec![("id", "mogwai".into()), ("name", "Mogwai".into())],
196-
)
197-
.1,
198-
make_band(
199-
"sigurros",
200-
vec![("id", "sigurros".into()), ("name", "Sigur Ros".into())],
201-
)
202-
.1,
203-
],
204-
);
205-
206-
Ok(map)
207-
});
189+
let store = {
190+
let entities = vec![
191+
make_band(
192+
"mogwai",
193+
vec![("id", "mogwai".into()), ("name", "Mogwai".into())],
194+
)
195+
.1,
196+
make_band(
197+
"sigurros",
198+
vec![("id", "sigurros".into()), ("name", "Sigur Ros".into())],
199+
)
200+
.1,
201+
];
202+
MockStore::new(entity_version_map("Band", entities))
203+
};
208204

209205
let store = Arc::new(store);
210206
let mut cache = EntityCache::new(store.clone());
@@ -247,30 +243,23 @@ fn overwrite_modifications() {
247243

248244
#[test]
249245
fn consecutive_modifications() {
250-
let mut store = MockStore::new();
251-
252246
// Pre-populate the store with data so that we can test setting a field to
253247
// `Value::Null`.
254-
store.expect_get_many_mock().returning(|_| {
255-
let mut map = BTreeMap::new();
256-
257-
map.insert(
258-
EntityType::from("Band"),
259-
vec![
260-
make_band(
261-
"mogwai",
262-
vec![
263-
("id", "mogwai".into()),
264-
("name", "Mogwai".into()),
265-
("label", "Chemikal Underground".into()),
266-
],
267-
)
268-
.1,
269-
],
270-
);
271-
272-
Ok(map)
273-
});
248+
let store = {
249+
let entities = vec![
250+
make_band(
251+
"mogwai",
252+
vec![
253+
("id", "mogwai".into()),
254+
("name", "Mogwai".into()),
255+
("label", "Chemikal Underground".into()),
256+
],
257+
)
258+
.1,
259+
];
260+
261+
MockStore::new(entity_version_map("Band", entities))
262+
};
274263

275264
let store = Arc::new(store);
276265
let mut cache = EntityCache::new(store.clone());

0 commit comments

Comments
 (0)