Skip to content

[Bug]: [Test Failure] After(Test) hook failed: The CancellationTokenSource has been disposed. #6339

Description

@mvanputgrccontrol

Description

Facing some issues with integration testing ASP.NET Core. The errors are random and occur from time to time. Don't exactly know what causes them and they occur also at different tests.

The following error occurs.

  Message: 
[Test Failure] After(Test) hook failed: The CancellationTokenSource has been disposed.

  Stack Trace: 
TestExecutor.ExecuteAsync(AbstractExecutableTest executableTest, TestInitializer testInitializer, CancellationToken cancellationToken, Nullable`1 testTimeout)
TestCoordinator.ExecuteTestAsync(AbstractExecutableTest test, CancellationToken cancellationToken)
TestCoordinator.ExecuteTestAsync(AbstractExecutableTest test, CancellationToken cancellationToken)

Also facing the following error from time to time

  Message: 
[Setup Failure] BeforeTest hook failed: An exception has been raised that is likely due to a transient failure. Consider enabling transient error resiliency by adding 'EnableRetryOnFailure' to the 'UseSqlServer' call.

  Stack Trace: 
HookExecutor.ExecuteBeforeTestHooksCoreAsync(AbstractExecutableTest test, Type testClassType, IReadOnlyList`1 beforeEveryTestHooks, IReadOnlyList`1 cachedBeforeTestHooks, CancellationToken cancellationToken)
TestExecutor.ExecuteAsync(AbstractExecutableTest executableTest, TestInitializer testInitializer, CancellationToken cancellationToken, Nullable`1 testTimeout)
TestExecutor.ExecuteAsync(AbstractExecutableTest executableTest, TestInitializer testInitializer, CancellationToken cancellationToken, Nullable`1 testTimeout)
TestCoordinator.ExecuteTestAsync(AbstractExecutableTest test, CancellationToken cancellationToken)
TestCoordinator.ExecuteTestAsync(AbstractExecutableTest test, CancellationToken cancellationToken)

Don't know it's something regarding my setup with the integration tests. I can share some setup code if required.

Expected Behavior

Tests run fine without any issues

Actual Behavior

Random tests fail

Steps to Reproduce

Current issue occurs at random tests at random times. So don't have any steps to reproduce. I can share my setup config.

TUnit Version

1.56.25

.NET Version

.NET 10

Operating System

Windows

IDE / Test Runner

Visual Studio

Error Output / Stack Trace

[Test Failure] After(Test) hook failed: The CancellationTokenSource has been disposed.

  Stack Trace: 
TestExecutor.ExecuteAsync(AbstractExecutableTest executableTest, TestInitializer testInitializer, CancellationToken cancellationToken, Nullable`1 testTimeout)
TestCoordinator.ExecuteTestAsync(AbstractExecutableTest test, CancellationToken cancellationToken)
TestCoordinator.ExecuteTestAsync(AbstractExecutableTest test, CancellationToken cancellationToken)

Additional Context

No response

IDE-Specific Issue?

  • I've confirmed this issue occurs when running via dotnet test or dotnet run, not just in my IDE

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions