Skip to content

tearDown is not called if a test times out #897

Closed

Description

@itsjoeconway

Ran into this issue in particular when the current working directory was being manipulated in the test, and restored in tearDown.

Repro:

import 'dart:async';

import 'package:test/test.dart';

void main() {
  tearDown(() {
    print("tearDown");
  });

  test("test", () async {
    await new Future.delayed(Duration(seconds: 5));
  }, timeout: new Timeout(Duration(seconds: 1)));
}

Activity

  1. changed the title [-]tearDown is not called is a test times out[/-] [+]tearDown is not called if a test times out[/+] on Jun 28, 2018
  2. jakemac53 commented on Jun 28, 2018

    @jakemac53
    Contributor

    I don't know that it is entirely clear if tearDown should or should not be called in this case.

    The problem is, the test is actually still running after the timeout (until the isolate is killed at least). There isn't a trivial way to cancel async tasks that are already scheduled in Dart. We could investigate some zone crazyness here to effectively do this though?

    So, given that the test is still actually running, executing tearDown may have unintended side effects or fail entirely. For instance if you are running a process in a temp dir which you clean up in tearDown, and the process is still running when you execute tearDown, then it will fail to delete the directory on windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions