Skip to content

Commit a3bcfc6

Browse files
committed
graph, test-store: Small improvements
* Do not arbitrarily truncate subgraph names to 32 characters; that can lead to strange surprises when the names of two test subgraphs only differ after the 32nd character * Use a more direct method to get rid of test subgraphs. Using `record_unused_deployments` is a bit too roundabout for tests, and can lead to not deleting a subgraph if a previous run recorded the subgraph as unused, but didn't delete it
1 parent 3ba05c3 commit a3bcfc6

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

graph/src/data/subgraph/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ impl SubgraphName {
218218
Ok(SubgraphName(s))
219219
}
220220

221+
/// Tests are allowed to create arbitrary subgraph names
222+
#[cfg(debug_assertions)]
223+
pub fn new_unchecked(s: impl Into<String>) -> Self {
224+
SubgraphName(s.into())
225+
}
226+
221227
pub fn as_str(&self) -> &str {
222228
self.0.as_str()
223229
}

store/test-store/src/store.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,7 @@ pub async fn create_subgraph(
170170
yaml.insert("dataSources".into(), Vec::<serde_yaml::Value>::new().into());
171171
let yaml = serde_yaml::to_string(&yaml).unwrap();
172172
let deployment = DeploymentCreate::new(yaml, &manifest, None).graft(base);
173-
let name = {
174-
let mut name = subgraph_id.to_string();
175-
name.truncate(32);
176-
SubgraphName::new(name).unwrap()
177-
};
173+
let name = SubgraphName::new_unchecked(subgraph_id.to_string());
178174
let deployment = SUBGRAPH_STORE.create_deployment_replace(
179175
name,
180176
&schema,
@@ -198,14 +194,14 @@ pub async fn create_test_subgraph(subgraph_id: &DeploymentHash, schema: &str) ->
198194
}
199195

200196
pub fn remove_subgraph(id: &DeploymentHash) {
201-
let name = {
202-
let mut name = id.to_string();
203-
name.truncate(32);
204-
SubgraphName::new(name).unwrap()
205-
};
197+
let name = SubgraphName::new_unchecked(id.to_string());
206198
SUBGRAPH_STORE.remove_subgraph(name).unwrap();
207-
for detail in SUBGRAPH_STORE.record_unused_deployments().unwrap() {
208-
SUBGRAPH_STORE.remove_deployment(detail.id).unwrap();
199+
let locs = SUBGRAPH_STORE.locators(id.as_str()).unwrap();
200+
let conn = primary_connection();
201+
for loc in locs {
202+
let site = conn.locate_site(loc.clone()).unwrap().unwrap();
203+
conn.unassign_subgraph(&site).unwrap();
204+
SUBGRAPH_STORE.remove_deployment(site.id).unwrap();
209205
}
210206
}
211207

0 commit comments

Comments
 (0)