Skip to content

Replace #[should_panic] with assertions in HTTP example tests#3705

Merged
jvff merged 14 commits intolinera-io:mainfrom
jvff:replace-should-panics-with-assertions-in-http-tests
Apr 3, 2025
Merged

Replace #[should_panic] with assertions in HTTP example tests#3705
jvff merged 14 commits intolinera-io:mainfrom
jvff:replace-should-panics-with-assertions-in-http-tests

Conversation

@jvff
Copy link
Copy Markdown
Contributor

@jvff jvff commented Apr 2, 2025

Motivation

The integration tests for the HTTP Requests How-To example (#3509) used the #[should_panic] attribute for testing failures. However, as pointed out during review, these are quite broad and may lead to mistakes. Being able to assert the exact error leads to better tests and a better example for external developers.

Proposal

Add try_query, try_graphql_query and try_graphql_mutation helper methods to the ActiveChain test interface. Use the new methods to replace usages of #[should_panic] with error type assertions.

To reduce boilerplate code, a WorkerError::expect_execution_error test helper method was added, that dives into the internal ExecutionError stored inside a WorkerError.

Test Plan

CI should catch any regressions caused by this refactor to the tests.

Release Plan

  • These changes follow the usual release cycle, because this only includes small backward-compatible API additions to the public API and SDK.

Links

jvff added 6 commits April 2, 2025 17:26
Return a `Result` instead of panicking, so that the user can match the
error if needed.
Return a `Result` instead of panicking, so that the user can match the
error if needed.
Ensure application integration tests can match against Wasm execution
errors.
Ensure application integration tests can match against execution errors.
Ensure application integration tests can match against execution errors.
Ensure application integration tests can match against execution errors.
@jvff jvff added the refactor label Apr 2, 2025
@jvff jvff added this to the Testnet #3 milestone Apr 2, 2025
@jvff jvff requested review from Twey, afck, deuszx and ma2bd April 2, 2025 18:54
@jvff jvff self-assigned this Apr 2, 2025
@jvff jvff force-pushed the replace-should-panics-with-assertions-in-http-tests branch from 42ecafd to 9d90a53 Compare April 2, 2025 19:17
}

#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

#[cfg_attr(with_testing, derive(Eq, PartialEq))] ?

jvff added 8 commits April 3, 2025 02:22
Make it simple to compare two instances of the type.
Centralize the boilerplate code to extract an `ExecutionError` from a
`WorkerError`.
Centralize the boilerplate code to extract an `ExecutionError` from a
`TryGraphQLQueryError`.
Be more precise with the expected failure.
Allow users to match the error for more precise test assertions.
Return a `Result` instead of panicking, so that the user can match the
error if needed.
Allow extracting an `ExecutionError` that occurred while proposing a
block after a GraphQL mutation.
Be more precise with the expected failure.
@jvff jvff force-pushed the replace-should-panics-with-assertions-in-http-tests branch from 9d90a53 to a76e0a3 Compare April 3, 2025 02:23
@jvff jvff merged commit a4b90a8 into linera-io:main Apr 3, 2025
23 checks passed
@jvff jvff deleted the replace-should-panics-with-assertions-in-http-tests branch April 3, 2025 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants