Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update nonFatalErrors in subgraphs.subgraph_deployment table #4615

Merged
merged 2 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion store/test-store/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,14 @@ pub fn remove_subgraph(id: &DeploymentHash) {
}

/// Transact errors for this block and wait until changes have been written
/// Takes store, deployment, block ptr to, errors, and a bool indicating whether
/// nonFatalErrors are active
pub async fn transact_errors(
store: &Arc<Store>,
deployment: &DeploymentLocator,
block_ptr_to: BlockPtr,
errs: Vec<SubgraphError>,
is_non_fatal_errors_active: bool,
) -> Result<(), StoreError> {
let metrics_registry = Arc::new(MetricsRegistry::mock());
let stopwatch_metrics = StopwatchMetrics::new(
Expand All @@ -232,7 +235,7 @@ pub async fn transact_errors(
Vec::new(),
errs,
Vec::new(),
false,
is_non_fatal_errors_active,
)
.await?;
flush(deployment).await
Expand Down
2 changes: 2 additions & 0 deletions store/test-store/tests/chain/ethereum/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ specVersion: 0.0.2
&deployment,
test_store::BLOCKS[1].clone(),
vec![error],
false,
)
.await
.unwrap();
Expand Down Expand Up @@ -336,6 +337,7 @@ specVersion: 0.0.2
&deployment,
test_store::BLOCKS[1].clone(),
vec![error],
false,
)
.await
.unwrap();
Expand Down
4 changes: 2 additions & 2 deletions store/test-store/tests/graphql/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2439,7 +2439,7 @@ fn non_fatal_errors() {
deterministic: true,
};

transact_errors(&STORE, &deployment, BLOCK_TWO.block_ptr(), vec![err])
transact_errors(&STORE, &deployment, BLOCK_TWO.block_ptr(), vec![err], true)
.await
.unwrap();

Expand Down Expand Up @@ -2545,7 +2545,7 @@ fn deterministic_error() {
deterministic: true,
};

transact_errors(&STORE, &deployment, BLOCK_TWO.block_ptr(), vec![err])
transact_errors(&STORE, &deployment, BLOCK_TWO.block_ptr(), vec![err], false)
.await
.unwrap();

Expand Down
66 changes: 62 additions & 4 deletions store/test-store/tests/postgres/subgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ fn subgraph_error() {

assert!(count() == 0);

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

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

transact_errors(&store, &deployment, BLOCKS[3].clone(), vec![error2])
transact_errors(&store, &deployment, BLOCKS[3].clone(), vec![error2], false)
.await
.unwrap();
assert!(count() == 2);
Expand All @@ -542,6 +542,64 @@ fn subgraph_error() {
})
}

#[test]
fn subgraph_non_fatal_error() {
test_store::run_test_sequentially(|store| async move {
let subgraph_store = store.subgraph_store();
let subgraph_id = DeploymentHash::new("subgraph_non_fatal_error").unwrap();
let deployment =
test_store::create_test_subgraph(&subgraph_id, "type Foo { id: ID! }").await;

let count = || -> usize {
let store = store.subgraph_store();
let count = store.error_count(&subgraph_id).unwrap();
println!("count: {}", count);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a leftover from debugging.

count
};

let error = SubgraphError {
subgraph_id: subgraph_id.clone(),
message: "test".to_string(),
block_ptr: Some(BLOCKS[1].clone()),
handler: None,
deterministic: true,
};

assert!(count() == 0);

transact_errors(&store, &deployment, BLOCKS[1].clone(), vec![error], true)
.await
.unwrap();
assert!(count() == 1);

let info = subgraph_store.status_for_id(deployment.id);

assert!(info.non_fatal_errors.len() == 1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's generally better to use assert_eq!(1, info.non_fatal_errors.len()) for equality comparisons since that will print both the expected and actual values when the assertion fails. It's a small quality-of-life improvement when tests fail, not that big a deal, but would be good to change before merging.

assert!(info.health == SubgraphHealth::Unhealthy);

let error2 = SubgraphError {
subgraph_id: subgraph_id.clone(),
message: "test2".to_string(),
block_ptr: None,
handler: None,
deterministic: false,
};

// Inserting non deterministic errors will increase error count but not count of non fatal errors
transact_errors(&store, &deployment, BLOCKS[2].clone(), vec![error2], false)
.await
.unwrap();
assert!(count() == 2);

let info = subgraph_store.status_for_id(deployment.id);

assert!(info.non_fatal_errors.len() == 1);
assert!(info.health == SubgraphHealth::Unhealthy);

test_store::remove_subgraph(&subgraph_id);
})
}

#[test]
fn fatal_vs_non_fatal() {
async fn setup() -> DeploymentLocator {
Expand Down Expand Up @@ -592,7 +650,7 @@ fn fatal_vs_non_fatal() {
.await
.unwrap());

transact_errors(&store, &deployment, BLOCKS[1].clone(), vec![error()])
transact_errors(&store, &deployment, BLOCKS[1].clone(), vec![error()], false)
.await
.unwrap();

Expand Down