Skip to content

Commit 765e683

Browse files
committed
store/test-store : Add tests for nonFatalErrors
1 parent bcd5e65 commit 765e683

File tree

4 files changed

+70
-7
lines changed

4 files changed

+70
-7
lines changed

store/test-store/src/store.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,14 @@ pub fn remove_subgraph(id: &DeploymentHash) {
207207
}
208208

209209
/// Transact errors for this block and wait until changes have been written
210+
/// Takes store, deployment, block ptr to, errors, and a bool indicating whether
211+
/// nonFatalErrors are active
210212
pub async fn transact_errors(
211213
store: &Arc<Store>,
212214
deployment: &DeploymentLocator,
213215
block_ptr_to: BlockPtr,
214216
errs: Vec<SubgraphError>,
217+
is_non_fatal_errors_active: bool,
215218
) -> Result<(), StoreError> {
216219
let metrics_registry = Arc::new(MetricsRegistry::mock());
217220
let stopwatch_metrics = StopwatchMetrics::new(
@@ -232,7 +235,7 @@ pub async fn transact_errors(
232235
Vec::new(),
233236
errs,
234237
Vec::new(),
235-
false,
238+
is_non_fatal_errors_active,
236239
)
237240
.await?;
238241
flush(deployment).await

store/test-store/tests/chain/ethereum/manifest.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ specVersion: 0.0.2
225225
&deployment,
226226
test_store::BLOCKS[1].clone(),
227227
vec![error],
228+
false,
228229
)
229230
.await
230231
.unwrap();
@@ -336,6 +337,7 @@ specVersion: 0.0.2
336337
&deployment,
337338
test_store::BLOCKS[1].clone(),
338339
vec![error],
340+
false,
339341
)
340342
.await
341343
.unwrap();

store/test-store/tests/graphql/query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2439,7 +2439,7 @@ fn non_fatal_errors() {
24392439
deterministic: true,
24402440
};
24412441

2442-
transact_errors(&STORE, &deployment, BLOCK_TWO.block_ptr(), vec![err])
2442+
transact_errors(&STORE, &deployment, BLOCK_TWO.block_ptr(), vec![err], true)
24432443
.await
24442444
.unwrap();
24452445

@@ -2545,7 +2545,7 @@ fn deterministic_error() {
25452545
deterministic: true,
25462546
};
25472547

2548-
transact_errors(&STORE, &deployment, BLOCK_TWO.block_ptr(), vec![err])
2548+
transact_errors(&STORE, &deployment, BLOCK_TWO.block_ptr(), vec![err], false)
25492549
.await
25502550
.unwrap();
25512551

store/test-store/tests/postgres/subgraph.rs

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ fn subgraph_error() {
506506

507507
assert!(count() == 0);
508508

509-
transact_errors(&store, &deployment, BLOCKS[1].clone(), vec![error])
509+
transact_errors(&store, &deployment, BLOCKS[1].clone(), vec![error], false)
510510
.await
511511
.unwrap();
512512
assert!(count() == 1);
@@ -520,7 +520,7 @@ fn subgraph_error() {
520520
};
521521

522522
// Inserting the same error is allowed but ignored.
523-
transact_errors(&store, &deployment, BLOCKS[2].clone(), vec![error])
523+
transact_errors(&store, &deployment, BLOCKS[2].clone(), vec![error], false)
524524
.await
525525
.unwrap();
526526
assert!(count() == 1);
@@ -533,7 +533,7 @@ fn subgraph_error() {
533533
deterministic: false,
534534
};
535535

536-
transact_errors(&store, &deployment, BLOCKS[3].clone(), vec![error2])
536+
transact_errors(&store, &deployment, BLOCKS[3].clone(), vec![error2], false)
537537
.await
538538
.unwrap();
539539
assert!(count() == 2);
@@ -542,6 +542,64 @@ fn subgraph_error() {
542542
})
543543
}
544544

545+
#[test]
546+
fn subgraph_non_fatal_error() {
547+
test_store::run_test_sequentially(|store| async move {
548+
let subgraph_store = store.subgraph_store();
549+
let subgraph_id = DeploymentHash::new("subgraph_non_fatal_error").unwrap();
550+
let deployment =
551+
test_store::create_test_subgraph(&subgraph_id, "type Foo { id: ID! }").await;
552+
553+
let count = || -> usize {
554+
let store = store.subgraph_store();
555+
let count = store.error_count(&subgraph_id).unwrap();
556+
println!("count: {}", count);
557+
count
558+
};
559+
560+
let error = SubgraphError {
561+
subgraph_id: subgraph_id.clone(),
562+
message: "test".to_string(),
563+
block_ptr: Some(BLOCKS[1].clone()),
564+
handler: None,
565+
deterministic: true,
566+
};
567+
568+
assert!(count() == 0);
569+
570+
transact_errors(&store, &deployment, BLOCKS[1].clone(), vec![error], true)
571+
.await
572+
.unwrap();
573+
assert!(count() == 1);
574+
575+
let info = subgraph_store.status_for_id(deployment.id);
576+
577+
assert!(info.non_fatal_errors.len() == 1);
578+
assert!(info.health == SubgraphHealth::Unhealthy);
579+
580+
let error2 = SubgraphError {
581+
subgraph_id: subgraph_id.clone(),
582+
message: "test2".to_string(),
583+
block_ptr: None,
584+
handler: None,
585+
deterministic: false,
586+
};
587+
588+
// Inserting non deterministic errors will increase error count but not count of non fatal errors
589+
transact_errors(&store, &deployment, BLOCKS[2].clone(), vec![error2], false)
590+
.await
591+
.unwrap();
592+
assert!(count() == 2);
593+
594+
let info = subgraph_store.status_for_id(deployment.id);
595+
596+
assert!(info.non_fatal_errors.len() == 1);
597+
assert!(info.health == SubgraphHealth::Unhealthy);
598+
599+
test_store::remove_subgraph(&subgraph_id);
600+
})
601+
}
602+
545603
#[test]
546604
fn fatal_vs_non_fatal() {
547605
async fn setup() -> DeploymentLocator {
@@ -592,7 +650,7 @@ fn fatal_vs_non_fatal() {
592650
.await
593651
.unwrap());
594652

595-
transact_errors(&store, &deployment, BLOCKS[1].clone(), vec![error()])
653+
transact_errors(&store, &deployment, BLOCKS[1].clone(), vec![error()], false)
596654
.await
597655
.unwrap();
598656

0 commit comments

Comments
 (0)