Skip to content

Global teardown functionality #74

@rockboynton

Description

@rockboynton

@t-moe had a great idea for per-test teardown by implementing Drop on the test resource. That should work for happy-path teardown, however it looks like it doesn't work in the case of a panic in a test.

My use case is that I would like to have a test (or suite of tests) that powers on a variety of components (in init) on the board to do checks, however I want to shutdown the power rails gracefully in any result of the tests (pass or fail, including panic) to not drain power or cause the board to get hot or melt lol.

The only way I can seem to get this behavior reliably is having a "final test" that is the last in the file, which isn't actually a test, it just powers off the rails. But according to @bugadani, we shouldn't rely on the tests being run sequentially in-order due to some recent changes. So it seems like a global teardown would be needed here to achieve the use case we are after.

This global teardown I imagine would be the complement to #[init] and would take the resource returned by that function and run the teardown to ensure the board is never left in a bad or unexpected state after failing or panicking a test part-way through.

I think it may be a good idea to run the init before the final teardown as well to ensure it is in a known state going in to the teardown, but that point may be up for debate (may want to keep some state from the previous runs, like some status LED being set for example).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions