Skip to content

Stack overflow when running tests on machine with Thai regional format #4246

Closed

Description

@estrizhok

NUnit Version: 3.13.3
OS: Microsoft Windows 10.0.19042
Runtime: .NET 6.0.9

STR:

  1. Set Regional format to Thai (Thailand)
    image
  2. Create a simple NOOP test targeting net6.0
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
    <PackageReference Include="NUnit" Version="3.13.3" />
    <PackageReference Include="NUnit3TestAdapter" Version="4.3.0-rc.1" />
  </ItemGroup>

</Project>
using NUnit.Framework;

namespace Tests.NUnit
{
  public class Tests
  {
    [Test]
    public void Test1() { }
  }
}
  1. Compile the project
  2. Run the tests
    nunit3-console.exe <PATH_TO_TEST_DLL>

Expected result:

  1. Tests passes

Actual result:

  1. nunit3-console.exe fails with stack overflow
NUnit Console 3.15.2 (Release)
Copyright (c) 2022 Charlie Poole, Rob Prouse
28 ?????? 2565 11:51:53

Runtime Environment
   OS Version: Microsoft Windows 10.0.19042
  Runtime: .NET 6.0.9

Test Files
    c:\Users\jetbrains\source\repos\UT.Frameworks\Tests.NUnit\bin\Debug\net6.0\Tests.NUnit.dll

Stack overflow.
   at System.Globalization.CompareInfo.IcuIndexOfCore(System.ReadOnlySpan`1<Char>, System.ReadOnlySpan`1<Char>, System.Globalization.CompareOptions, Int32*, Boolean)
   at System.Globalization.CompareInfo.IndexOfCore(System.ReadOnlySpan`1<Char>, System.ReadOnlySpan`1<Char>, System.Globalization.CompareOptions, Int32*, Boolean)
   at System.Globalization.CompareInfo.LastIndexOf(System.ReadOnlySpan`1<Char>, System.ReadOnlySpan`1<Char>, System.Globalization.CompareOptions)
   at System.Globalization.CompareInfo.LastIndexOf(System.String, System.String, Int32, Int32, System.Globalization.CompareOptions)
   at System.String.LastIndexOf(System.String, Int32, Int32, System.StringComparison)
   at System.String.LastIndexOf(System.String)
   at NUnit.Framework.Internal.Builders.NamespaceTreeBuilder.GetNamespaceSuite(System.String)
<<< Many more GetNamespaceSuite calls here >>>
   at NUnit.Framework.Internal.Builders.NamespaceTreeBuilder.GetNamespaceSuite(System.String)
   at NUnit.Framework.Internal.Builders.NamespaceTreeBuilder.Add(NUnit.Framework.Internal.TestSuite)
   at NUnit.Framework.Internal.Builders.NamespaceTreeBuilder.Add(System.Collections.Generic.IList`1<NUnit.Framework.Internal.Test>)
   at NUnit.Framework.Api.DefaultTestAssemblyBuilder.BuildTestAssembly(System.Reflection.Assembly, System.String, System.Collections.Generic.IList`1<NUnit.Framework.Internal.Test>)
   at NUnit.Framework.Api.DefaultTestAssemblyBuilder.Build(System.Reflection.Assembly, System.String, System.Collections.Generic.IDictionary`2<System.String,System.Object>)
   at NUnit.Framework.Api.DefaultTestAssemblyBuilder.Build(System.Reflection.Assembly, System.Collections.Generic.IDictionary`2<System.String,System.Object>)
   at NUnit.Framework.Api.NUnitTestAssemblyRunner+<>c__DisplayClass34_0.<Load>b__0()
   at NUnit.Framework.Api.NUnitTestAssemblyRunner.WrapInNUnitCallContext(System.Action)
   at NUnit.Framework.Api.NUnitTestAssemblyRunner.Load(System.Reflection.Assembly, System.Collections.Generic.IDictionary`2<System.String,System.Object>)
   at NUnit.Framework.Api.FrameworkController.LoadTests()
   at System.RuntimeMethodHandle.InvokeMethod(System.Object, System.Span`1<System.Object> ByRef, System.Signature, Boolean, Boolean)
   at System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)
   at System.Reflection.MethodBase.Invoke(System.Object, System.Object[])
   at NUnit.Engine.Drivers.NUnitNetCore31Driver.ExecuteMethod(System.Reflection.MethodInfo, System.Object[])
   at NUnit.Engine.Drivers.NUnitNetCore31Driver.ExecuteMethod(System.String, System.Object[])
   at NUnit.Engine.Drivers.NUnitNetCore31Driver.Load(System.String, System.Collections.Generic.IDictionary`2<System.String,System.Object>)
   at NUnit.Engine.Runners.DirectTestRunner.LoadDriver(NUnit.Engine.Extensibility.IFrameworkDriver, System.String, NUnit.Engine.TestPackage)
   at NUnit.Engine.Runners.DirectTestRunner.LoadPackage()
   at NUnit.Engine.Runners.DirectTestRunner.EnsurePackageIsLoaded()
   at NUnit.Engine.Runners.DirectTestRunner.RunTests(NUnit.Engine.ITestEventListener, NUnit.Engine.TestFilter)
   at NUnit.Engine.Runners.AbstractTestRunner.Run(NUnit.Engine.ITestEventListener, NUnit.Engine.TestFilter)
   at NUnit.Engine.Runners.MasterTestRunner.RunTests(NUnit.Engine.ITestEventListener, NUnit.Engine.TestFilter)
   at NUnit.Engine.Runners.MasterTestRunner.Run(NUnit.Engine.ITestEventListener, NUnit.Engine.TestFilter)
   at NUnit.ConsoleRunner.ConsoleRunner.RunTests(NUnit.Engine.TestPackage, NUnit.Engine.TestFilter)
   at NUnit.ConsoleRunner.ConsoleRunner.Execute()
   at NUnit.ConsoleRunner.Program.Main(System.String[])

Activity

  1. stevenaw commented on Oct 29, 2022

    @stevenaw
    Member

    Thanks @estrizhok
    I'm going to label this as confirm to see if it's still happening in the current codebase. The line which seems to be triggering this has changed in master branch since the 3.13.3 release and it would be good to confirm if any existing fix should be backported.

  2. stevenaw commented on Oct 29, 2022

    @stevenaw
    Member

    Ok, I can confirm that this is happening on the latest 3.13.x code, as well as that I suspect it to be fixed on master via #3770
    It is also reproducible on .NET6 and not .NET Core 3.1. I suspect it could be related to differences in the NLS vs ICU globalization tables.

    We may want to consider applying the changes in #3770 to v3.13-dev

    using System.Globalization;
    
    CultureInfo.CurrentCulture = CultureInfo.CreateSpecificCulture("th-TH");
    
    var v313 = "Issue4246.Test1".IndexOf(".");        // Returns 0
    var vMaster = "Issue4246.Test1".IndexOf('.');     // Returns 9
    
    Console.WriteLine($"3.13.x branch: {v313}");
    Console.WriteLine($"master branch : {vMaster}");

    Also of note here is that this happens when the machine localization settings are th-TH but NOT when applying the culture to a test directly via the [SetCulture("th-TH")] attribute

  3. stevenaw commented on Oct 29, 2022

    @stevenaw
    Member

    Confirmed as an NLS vs ICU issue. Adding the below to the csproj file on Windows should work around the issue on affected runtimes until this can be fixed.

    <ItemGroup>
        <RuntimeHostConfigurationOption Include="System.Globalization.UseNls" Value="true" />
    </ItemGroup>

    https://learn.microsoft.com/en-us/dotnet/core/extensions/globalization-icu#use-nls-instead-of-icu

  4. stevenaw commented on Mar 24, 2023

    @stevenaw
    Member

    @estrizhok I recall you mentioning in another issue that you've been testing localization in Rider. Did the RuntimeHostConfigurationOption workaround work in your case or is this still an issue you're facing?

  5. self-assigned this
    on Apr 7, 2023
  6. stevenaw commented on Apr 8, 2023

    @stevenaw
    Member

    @OsirisTerje Adding this to 3.14 as I'd like to include this in a 3.x release too. This has been "broken" for a while and while there is a work around I think it'd be nice to avoid asking our users to apply it. I'll be trying to tackle this early next week. I believe it's quite simple, there's just a very minor merge conflict to resolve as part of it.
    It can be bumped out of 3.14 if a release goes out before this can get in.

  7. added this to the 3.14 milestone on Apr 8, 2023
  8. modified the milestones: 3.14, 4.0 on Oct 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions