Skip to content

[Testing Platform] ObjectDisposedException on CancellationTokenSource #3695

Closed

Description

Happening in 1.4.0-preview.24422.11.

Stacktrace:

Error: Unhandled exception. System.ObjectDisposedException: The CancellationTokenSource has been disposed.
   at System.Threading.CancellationTokenSource.Cancel()
   at Microsoft.Testing.Platform.OutputDevice.Terminal.TestProgressStateAwareTerminal.StopShowingProgress() in /_/src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TestProgressStateAwareTerminal.cs:line 108
   at Microsoft.Testing.Platform.OutputDevice.Terminal.TerminalTestReporter.TestExecutionCompleted(DateTimeOffset endTime) in /_/src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TerminalTestReporter.cs:line 178
   at Microsoft.Testing.Platform.OutputDevice.TerminalOutputDevice.DisplayAfterSessionEndRunAsync() in /_/src/Platform/Microsoft.Testing.Platform/OutputDevice/TerminalOutputDevice.cs:line 293
   at Microsoft.Testing.Platform.Hosts.CommonTestHost.DisplayAfterSessionEndRunAsync(IPlatformOutputDevice outputDevice, ITestSessionContext sessionInfo, CancellationToken cancellationToken) in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 151
   at Microsoft.Testing.Platform.Hosts.CommonTestHost.ExecuteRequestAsync(IPlatformOutputDevice outputDevice, ITestSessionContext testSessionInfo, ServiceProvider serviceProvider, BaseMessageBus baseMessageBus, ITestFramework testFramework, ClientInfo client) in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 132
   at Microsoft.Testing.Platform.Hosts.ConsoleTestHost.InternalRunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Hosts/ConsoleTestHost.cs:line 88
   at Microsoft.Testing.Platform.Hosts.ConsoleTestHost.InternalRunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Hosts/ConsoleTestHost.cs:line 120
   at Microsoft.Testing.Platform.Hosts.CommonTestHost.RunTestAppAsync(CancellationToken testApplicationCancellationToken) in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 76
   at Microsoft.Testing.Platform.Hosts.CommonTestHost.RunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 38
   at Microsoft.Testing.Platform.Hosts.CommonTestHost.RunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 59
   at Microsoft.Testing.Platform.Builder.TestApplication.RunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs:line 240
   at TestingPlatformEntryPoint.Main(String[] args) in /_/tools/tunit-nuget-tester/TUnit.NugetTester/TUnit.NugetTester/obj/Debug/net8.0/TestPlatformEntryPoint.cs:line 16
   at TestingPlatformEntryPoint.<Main>(String[] args)

Activity

  1. nohwnd commented on Aug 26, 2024

    @nohwnd
    Member

    Is this during abort? Or it just randomly happens?

  2. thomhurst commented on Aug 26, 2024

    @thomhurst
    ContributorAuthor

    Is this during abort? Or it just randomly happens?

    Seems to be just random.

  3. nohwnd commented on Aug 27, 2024

    @nohwnd
    Member

    I can't reproduce, I've run big test projects, small test projects, test projects with 0 tests. each I ran for 100 times and never seen the erro. I also tried aborting. Can your reproduce this regularly? Is the project public so I can try?

    And what is the tfm? I tried net framework and net8

  4. thomhurst commented on Aug 27, 2024

    @thomhurst
    ContributorAuthor

    Weird - I'm getting it every time.

    v0.1.496.0 | 64-bit | Microsoft Windows 10.0.22621 | win-x64 | .NET 8.0.8 | Microsoft Testing Platform v1.4.0-preview.24422.11

    The repro is using my framework - Hope it's still useful though.

    <Project Sdk="Microsoft.NET.Sdk">
    
        <PropertyGroup>
            <OutputType>Exe</OutputType>
            <TargetFramework>net8.0</TargetFramework>
            <ImplicitUsings>enable</ImplicitUsings>
            <Nullable>enable</Nullable>
        </PropertyGroup>
    
        <ItemGroup>
          <PackageReference Include="TUnit" Version="0.1.496-PullRequest324.0" />
        </ItemGroup>
    
    </Project>
    
    public class Tests
    {
        [Test]
        public async Task Test()
        {
            await Task.CompletedTask;
        }
    }

    dotnet run

    NuGet packages are attached here: TUnit.zip
    Should be able to put them in a local folder and add that as a nuget source

  5. nohwnd commented on Aug 27, 2024

    @nohwnd
    Member

    You are registering our output device in AddFromFrameworkServiceProvider and you are disposing the service provider (along with all disposable registered services), in TUnitTestFramework.ExecuteRequestAsync -> serviceProvider.DisposeAsync();

    This will dispose the output device before we are done completing the run, and hence the crash.

    Please don't dispose our service, or wrap it in a dummy object that will not call the Dispose.

  6. thomhurst commented on Aug 27, 2024

    @thomhurst
    ContributorAuthor

    Ah my bad. Thanks for spotting that! An oversight on my part that if they're registered in my service provider it'll try and dispose them. I'll tidy this up! Sorry for the issue

  7. nohwnd commented on Aug 27, 2024

    @nohwnd
    Member

    No problem!

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

Metadata

Metadata

Labels

state/in-pr

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions