flutter/docs/contributing/testing/Leak-tracking.md

2.7 KiB

Leak tracking in Flutter framework

Flutter Framework widget tests use [leak_tracker](https://github.com/dart-lang/leak_tracker/blob/main/doc/leak_tracking/ OVERVIEW.md) to detect leaks from objects that have not been disposed.

This page contains Flutter Framework related information.

See leak_tracker documentation for general leak troubleshooting.

Test failures cause by leaks look like this:

Expected: leak free
    Actual: <Instance of 'Leaks'>
     Which: contains leaks:
            # The text is generated by leak_tracker.
            # For leak troubleshooting tips open:
            # https://github.com/flutter/flutter/blob/main/docs/contributing/testing/Leak-tracking.md
            notDisposed:
              total: 1
              objects:
                FocusNode:
                  test: Align smoke test
                  identityHashCode: 82308154

When is it ok to opt-out from leak tracking?

In general, leak tracking should be enabled, to verify that all disposables are disposed. If a tests is opted out, the reasons should be clearly explained in the comments.

It is ok to opt out a test when a test throws an exception and the code did not finalize properly.

While some exceptions should be finalized properly and should not result in leaking objects, the project to make sure disposables are disposed in exceptional code paths was not prioritized yet. See issue #157470.

Where leak tracking is configured?

Leak tracker is configured in flutter_test_config.dart.

See leak_tracker documentation on how to enable/disable leak tracking for individual tests and files.

What are defaults?

Leak tracking is enabled on two test shards in Flutter's testing infrastructure:

For local testing, or for test shards configuration, to enable leak tracking for flutter tests, pass --dart-define LEAK_TRACKING=true to flutter test.

You can see the bot's status on the Flutter build dashboard. The bots are not blocking yet. See a proposal to convert them to be blocking.