Skip to content

MTP test runner crash when coverage enabled and username is too long #3397

@hchamre

Description

@hchamre

Description

When running xUnit.net v3 tests with Microsoft Testing Platform integration code coverage enabled on macOS, the test runner fails if the full path for the IPC socket file exceeds the platform's 104-character limit. This happens because the socket file is created in a directory like ~/Library/Application Support/MONITORTOHOST_<guid>/.p. The error is a System.ArgumentOutOfRangeException thrown by Microsoft.Testing.Platform.IPC.NamedPipeServer. It is unclear to me whether this is an issue in xUnit.net or MTP as the path used by NamePipeServer seems to be determined by input arguments.

Steps To Reproduce

  1. Use a macOS user account with a username of 20 or more characters.
  2. Set up a sample project as described in the official code Coverage with MTP tutorial.
  3. Run the test command:
    dotnet test -- --coverage
    
  4. Observe the test runner crash with an exception about the path length.

Expected behavior

The test run should pass.

Actual behavior

The test run fails with.

Click to expand full command output
dotnet test -- --coverage
Restore complete (0.4s)
  xunit3 succeeded (0.3s) → bin/Debug/net8.0/xunit3.dll
  xunit3 test failed with 1 error(s) (0.4s)
    /Users/my-username-is-very-long/TestProject/bin/Debug/net8.0/xunit3.dll : error run failed:
      Tests failed: xUnit.net v3 Microsoft.Testing.Platform Runner v3.0.1+9214bef154 (64-bit .NET 8.0.19)

      Unhandled exception. System.ArgumentOutOfRangeException: The path '/Users/my-username-is-very-long/Library/Application Support
      /MONITORTOHOST_0c4f96ab74184727b6776e7353ccdefe/.p' is of an invalid length for use with domain sockets on this platform.
       The length must be between 1 and 104 characters, inclusive. (Parameter 'path')
      Actual value was /Users/my-username-is-very-long/Library/Application Support/MONITORTOHOST_0c4f96ab74184727b6776e7353ccdefe/.p
      .
         at System.Net.Sockets.UnixDomainSocketEndPoint..ctor(String path, String boundFileName)
         at System.IO.Pipes.NamedPipeServerStream.SharedServer..ctor(String path, Int32 maxCount, Boolean isFirstPipeInstance)
         at System.IO.Pipes.NamedPipeServerStream.SharedServer.Get(String path, Int32 maxCount, PipeOptions pipeOptions)
         at System.IO.Pipes.NamedPipeServerStream.Create(String pipeName, PipeDirection direction, Int32 maxNumberOfServerInstan
      ces, PipeTransmissionMode transmissionMode, PipeOptions options, Int32 inBufferSize, Int32 outBufferSize, HandleInheritabi
      lity inheritability)
         at System.IO.Pipes.NamedPipeServerStream..ctor(String pipeName, PipeDirection direction, Int32 maxNumberOfServerInstanc
      es, PipeTransmissionMode transmissionMode, PipeOptions options)
         at Microsoft.Testing.Platform.IPC.NamedPipeServer..ctor(PipeNameDescription pipeNameDescription, Func`2 callback, IEnvi
      ronment environment, ILogger logger, ITask task, Int32 maxNumberOfServerInstances, CancellationToken cancellationToken) in
       /_/src/Platform/Microsoft.Testing.Platform/IPC/NamedPipeServer.cs:line 65
         at Microsoft.Testing.Platform.IPC.NamedPipeServer..ctor(PipeNameDescription pipeNameDescription, Func`2 callback, IEnvi
      ronment environment, ILogger logger, ITask task, CancellationToken cancellationToken) in /_/src/Platform/Microsoft.Testing
      .Platform/IPC/NamedPipeServer.cs:line 50
         at Microsoft.Testing.Platform.IPC.NamedPipeServer..ctor(String name, Func`2 callback, IEnvironment environment, ILogger
       logger, ITask task, CancellationToken cancellationToken) in /_/src/Platform/Microsoft.Testing.Platform/IPC/NamedPipeServe
      r.cs:line 39
         at Microsoft.Testing.Platform.Hosts.TestHostControllersTestHost.InternalRunAsync() in /_/src/Platform/Microsoft.Testing
      .Platform/Hosts/TestHostControllersTestHost.cs:line 96
         at Microsoft.Testing.Platform.Hosts.TestHostControllersTestHost.InternalRunAsync() in /_/src/Platform/Microsoft.Testing
      .Platform/Hosts/TestHostControllersTestHost.cs:line 351
         at Microsoft.Testing.Platform.Hosts.CommonHost.RunTestAppAsync(CancellationToken testApplicationCancellationToken) in /
      _/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 115
         at Microsoft.Testing.Platform.Hosts.CommonHost.RunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTes
      tHost.cs:line 38
         at Microsoft.Testing.Platform.Hosts.CommonHost.RunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTes
      tHost.cs:line 74
         at Microsoft.Testing.Platform.Builder.TestApplication.RunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Builder/
      TestApplication.cs:line 222
         at Xunit.Runner.InProc.SystemConsole.TestingPlatform.TestPlatformTestFramework.RunAsync(String[] args, Action`2 extensi
      onRegistration) in /_/src/xunit.v3.runner.inproc.console/TestingPlatform/TestPlatformTestFramework.cs:line 282
         at xunit3.AutoGenerated.XunitAutoGeneratedEntryPoint.Main(String[] args) in /Users/my-username-is-very-long/TestProject/obj
      /Debug/net8.0/XunitAutoGeneratedEntryPoint.cs:line 13

      === COMMAND LINE ===
      /Users/my-username-is-very-long/TestProject/bin/Debug/net8.0/xunit3 --internal-msbuild-node "/Users/my-username-is-very-long/Libra
      ry/Application Support/868b9863a151474390193e6c26949ae3/.p" --coverage --coverage-output coverage.cobertura.xml --coverage
      -output-format cobertura



Build failed with 1 error(s) in 1.3s

Additional context

  • The socket file is created under the user's Application Support directory, which is non-standard for temporary or ephemeral files like IPC sockets.
  • The Application Support folder becomes polluted with many MONITORTOHOST_* directories after running tests, and these do not get cleaned up.
  • Workarounds like using a shorter username or are not practical.

Environment

  • macOS 15.6.1
  • .NET SDK: 9.0.304
  • Package versions:
    • Microsoft.NET.Test.Sdk: 17.13.0
    • Microsoft.Testing.Extensions.CodeCoverage: 17.14.2
    • xunit.v3: 3.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    ExternalThe issue is caused by an external partyMTPMicrosoft Testing Platform

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions