question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Command.Result blocks indefinitely in xunit

See original GitHub issue

I have been debugging this for a while and finally found a cause of my tests blocking on xunit.

I’ve been writing a simple xunit test:

using Medallion.Shell;

namespace TestProject1;

public class UnitTest1
{
    [Fact]
    public void Test1()
    {
        const string consoleAppPath = @"T:\Temp\ConsoleApp99";
        const string consoleAppProjectFileName = @"ConsoleApp99.csproj";

        Console.WriteLine(
            Command.Run("dotnet", new[] { "build", "--configuration", "Release", Path.Combine(
                consoleAppPath, consoleAppProjectFileName) }, o=> o.WorkingDirectory(consoleAppPath)).Result.StandardOutput
        );
    }
}

This blocks indefinitely on Result (not on StandardOutput!), even if I kill dotnet build and all the child processes manually.

xunit is known for its sync context, so probably there’s a ConfigureAwait(false) missing somewhere.

(I wouldn’t ask for this in general, but it’s a good idea to use that if you provide a synchronous API.)

Issue Analytics

  • State:closed
  • Created 2 months ago
  • Reactions:1
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ForNeVeRcommented, Aug 15, 2023

At least I’ve figured out that this issue is definitely unrelated to MedallionShell, so I’ve posted it to .NET SDK issue tracker: https://github.com/dotnet/sdk/issues/34653

Still no idea whatever happens there, but let’s at least free MedallionShell of this burden for now.

1reaction
ForNeVeRcommented, Jul 30, 2023
  1. Earlier, I was testing on .NET 8, but just found that .NET 7 is also affected.

    And this is unlikely to be a bug in Medallion.Shell. But I have no repro without it, and thus will investigate further.

  2. Reproduces on async test as well 😱

    using Medallion.Shell;
    
    namespace TestProject2;
    
    public class Tests
    {
        [SetUp]
        public void Setup()
        {
        }
    
        [Test]
        public async Task Test1()
        {
            const string consoleAppPath = @"G:\Projects\Medallion.Shell.Bug104\ConsoleApp99";
            const string consoleAppProjectFileName = @"ConsoleApp99.csproj";
    
            ThreadPool.GetMaxThreads(out var w, out var t);
            
            Console.WriteLine("threads worker " + w);
            Console.WriteLine("threads completion pool " + t);
    
            Console.WriteLine(SynchronizationContext.Current?.ToString());
            Console.WriteLine(TaskScheduler.Current.ToString());
    
            var result = await Command.Run("dotnet", new[] { "build", "--configuration", "Release", Path.Combine(
                    consoleAppPath, consoleAppProjectFileName) }, o=> o.WorkingDirectory(consoleAppPath)).Task;
            Console.WriteLine(
                result.StandardOutput
            );
        }
    }
    
Read more comments on GitHub >

github_iconTop Results From Across the Web

Some unit tests runs indefinitely
In a solution, I have 600 unit tests splitted in various libraries, and 450 of them are present in a single library. When...
Read more >
Crispy DRY Tests in xUnit/C# - Blog - Pavel Sapehin
This article explains how to write DRY unit tests for the xUnit framework. ... allows you to nest beforeEach/beforeAll blocks indefinitely, ...
Read more >
VS runner hangs on Run All · Issue #611 · xunit/xunit
VS is essentially calling the command line and interpreting the results, so it should run on the cmd line successfully.
Read more >
Capturing Output
When xUnit.net v2 shipped with parallelization turned on by default, this output capture mechanism was no longer appropriate; it is impossible to know...
Read more >
Out of memory error seems to causes test runner to wait ...
I have some tests that are pushing the boundary with x86 tests and sometimes they cause the xunit runner to give an out...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found