Open Closed

Test host crashes when running Language Management unit tests #2943


User avatar
0
andreking created

If you're creating a bug/problem report, please include followings:

  • ABP Framework version: 5.2.1 / 5.2.0 (commercial)
  • UI type: Blazor
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no
  • Exception message and stack trace: test host crashes
  • Steps to reproduce the issue:try to run language management unit tests after modifying downloaded source

Hi the problem I am encountering sounds like the same one Jesse (I am working on the same code as Jesse but he is no longer with the project) had in this post: https://support.abp.io/QA/Questions/1985/Volo-Modules-Unit-Tests-are-not-executing I followed the link in that post to the duplicate, but the source that was posted with a fix/explanation is no longer available. I downloaded the source for the Language Management module and am able to run the tests in that state, unfortunately, i am unable to get the unit tests to run in our modified version. I can confirm that the crash happens when getting the IDataSeeder service from the container. I have also tried to get each of the dependencies in the data seeder's ctor and the test host will crash when trying to fetch this service: DbContextOptions<LanguageManagementDbContext>> I tested this by adding the following just before the call to the data seeder in the LanguageManagementTestBase var dbo = context.ServiceProvider.GetService<DbContextOptions<LanguageManagementDbContext>>(); //crashes test host I am unable to catch the exception that is being thrown, but assume it has something to do with constructing the above object. We are using the in memory sqlite provider for the database.

I am using the xunit visual studio test runner (not jet-brains resharper). I can reproduce the same problem running on the command line (dotnet test ...). I can provide the logs, but they are not very interesting. Do you have any advice on how to find the problem? thanks, andre Full text of the test base class

using Volo.Abp.Localization;
using Volo.Abp.Modularity;
using Volo.Abp.Threading;
namespace Volo.Abp.LanguageManagement
{
    [DependsOn(
        typeof(AbpAutofacModule),
        typeof(AbpTestBaseModule),
        typeof(AbpAuthorizationModule),
        typeof(LanguageManagementDomainModule)
        )]
    public class LanguageManagementTestBaseModule : AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            context.Services.AddAlwaysAllowAuthorization();
            Configure<AbpLocalizationOptions>(options =>
            {
                options.Languages.Add(new LanguageInfo("en-US", "en", "English", "flag-icon flag-icon-gb"));
                options.Languages.Add(new LanguageInfo("tr", "tr", "Türkçe", "flag-icon flag-icon-tr"));
            });
        }
        public override void OnApplicationInitialization(ApplicationInitializationContext context)
        {
            SeedTestData(context);
        }
        private static void SeedTestData(ApplicationInitializationContext context)
        {
            var dbo = context.ServiceProvider.GetService<DbContextOptions<LanguageManagementDbContext>>(); // test host crashes
            AsyncHelper.RunSync(async () =>
            {
                using (var scope = context.ServiceProvider.CreateScope())
                {
                    await scope.ServiceProvider
                        .GetRequiredService<IDataSeeder>() // this is the original crash
                        .SeedAsync();
                }
            });
        }
    }
}

14 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Can you share a simple project? shiwei.liang@volosoft.com

  • User Avatar
    0
    andreking created

    Hi,

    Can you share a simple project? shiwei.liang@volosoft.com

    Not easy to create a simple project since it is based on the Language Management source. Do you have any other ideas?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Ok, can you provide steps to reproduce the problem?

  • User Avatar
    0
    andreking created

    To reproduce, just need to run any test in the project that calls the code above, the problem happens when the line marked with the comment is run. All the tests call this code, so running any test will cause the problem. I am not sure how you can reproduce since you do not have our code and as I explained in the original, it does not crash in the code we started with (using abp cli). I will see if I am allowed to give you our source. What I was really looking for is suggestion of how to diagnose the problem with instantiating var dbo = context.ServiceProvider.GetService<DbContextOptions<LanguageManagementDbContext>>(); // test host crashes I assume it is a configuration we have changed but cannot find it. When I run the line above in the code produced by abp get-source LanguageManagement it goes into the configure method here:

    public class LanguageManagementEntityFrameworkCoreTestModule : AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            var sqliteConnection = CreateDatabaseAndGetConnection();
    
            Configure<AbpDbContextOptions>(options =>
            {
                options.Configure(abpDbContextConfigurationContext =>
                {
       **// this line gets called in original code
                     abpDbContextConfigurationContext.DbContextOptions.UseSqlite(sqliteConnection);**
                });
            });
        }
    
        private static SqliteConnection CreateDatabaseAndGetConnection()
        {
            var connection = new SqliteConnection("Data Source=:memory:");
            connection.Open();
    
            new LanguageManagementDbContext(
                new DbContextOptionsBuilder<LanguageManagementDbContext>().UseSqlite(connection).Options
            ).GetService<IRelationalDatabaseCreator>().CreateTables();
    
            new SettingManagementDbContext(
                new DbContextOptionsBuilder<SettingManagementDbContext>().UseSqlite(connection).Options
            ).GetService<IRelationalDatabaseCreator>().CreateTables();
    
            return connection;
        }
    }
    

    When I run the line above to fetch the options from the container (via any LM test), the test crashes before it runs the Configure method above. Note that our code for the class above is the same as this, we did not change it.

  • User Avatar
    0
    alper created
    Support Team Director

    any logs retrieved from filesystem or console output?

  • User Avatar
    0
    andreking created

    Here is the command line I ran limited it to 1 test to reduce the log size: dotnet test '.\modules\Volo.LanguageManagement\test\Volo.Abp.LanguageManagement.Application.Tests\Volo.Abp.LanguageManagement.Application.Tests.csproj' --diag:testcrashx.log --filter "FullyQualifiedName=Volo.Abp.LanguageManagement.LanguageAppService_Tests.GetAsync" --blame-crash Nothing very interesting, here is the exception: TpTrace Information: 0 : 15220, 8, 2022/04/21, 08:24:25.341, 4876539929101, datacollector.dll, DataCollectionTestCaseEventHandler: Test case 'Volo.Abp.LanguageManagement.LanguageAppService_Tests.GetAsync - c5219fb8-f8c4-fcd9-ca4c-02f7b5f369c6' started. TpTrace Error: 0 : 15220, 8, 2022/04/21, 08:24:26.061, 4876547134238, datacollector.dll, DataCollectionRequestHandler.HandleBeforeTestRunStart : Error occurred during initialization of TestHost : System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.. ---> System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host. at System.Net.Sockets.NetworkStream.Read(Span1 buffer) --- End of inner exception stack trace --- at System.Net.Sockets.NetworkStream.Read(Span1 buffer) at System.Net.Sockets.NetworkStream.ReadByte() at System.IO.BinaryReader.Read7BitEncodedInt() at System.IO.BinaryReader.ReadString() at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.SocketCommunicationManager.ReceiveRawMessage() at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.SocketCommunicationManager.ReceiveMessage() at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.DataCollection.DataCollectionTestCaseEventHandler.ProcessRequests() at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.DataCollection.DataCollectionRequestHandler.<HandleBeforeTestRunStart>b__24_0() TpTrace Information: 0 : 15220, 1, 2022/04/21, 08:24:26.078, 4876547305013, datacollector.dll, DataCollectionRequestHandler.ProcessRequests : Datacoll

    I can send the complete logs if you have a place to send them. andre

  • User Avatar
    0
    alper created
    Support Team Director

    there must be an exit code. something like this . The thread 0xaacc has exited with code -42

  • User Avatar
    0
    andreking created

    That is the exit code: -42. I can post the whole log here, but it will be messy - if you give me a place to send it, I can. here is more context including the exit code: TpTrace Verbose: 0 : 36120, 7, 2022/04/21, 08:24:25.331, 4876539827956, vstest.console.dll, TcpClientExtensions.MessageLoopAsync: NotifyDataAvailable remoteEndPoint: 127.0.0.1:55474 localEndPoint: 127.0.0.1:55473 TpTrace Verbose: 0 : 36120, 7, 2022/04/21, 08:24:25.331, 4876539829022, vstest.console.dll, TestRequestSender.OnExecutionMessageReceived: Received message: {"Version":5,"MessageType":"TestExecution.StatsChange","Payload":{"NewTestResults":[],"TestRunStatistics":{"ExecutedTests":0,"Stats":{}},"ActiveTests":[{"Id":"c5219fb8-f8c4-fcd9-ca4c-02f7b5f369c6","FullyQualifiedName":"Volo.Abp.LanguageManagement.LanguageAppService_Tests.GetAsync","DisplayName":"Volo.Abp.LanguageManagement.LanguageAppService_Tests.GetAsync","ExecutorUri":"executor://xunit/VsTestRunner2/netcoreapp","Source":"C:\\dev\\CAO\\CAT-OS-Project\\modules\\Volo.LanguageManagement\\test\\Volo.Abp.LanguageManagement.Application.Tests\\bin\\Debug\\net6.0\\Volo.Abp.LanguageManagement.Application.Tests.dll","CodeFilePath":null,"LineNumber":0,"Properties":[]}]}} TpTrace Verbose: 0 : 36120, 7, 2022/04/21, 08:24:25.337, 4876539891163, vstest.console.dll, TestRunRequest:SendTestRunStatsChange: Starting. TpTrace Verbose: 0 : 36120, 7, 2022/04/21, 08:24:25.337, 4876539891813, vstest.console.dll, InProgress is Volo.Abp.LanguageManagement.LanguageAppService_Tests.GetAsync TpTrace Information: 0 : 36120, 7, 2022/04/21, 08:24:25.337, 4876539892230, vstest.console.dll, TestRunRequest:SendTestRunStatsChange: Completed. TpTrace Verbose: 0 : 36120, 7, 2022/04/21, 08:24:25.337, 4876539892436, vstest.console.dll, TcpClientExtensions.MessageLoopAsync: Polling on remoteEndPoint: 127.0.0.1:55474 localEndPoint: 127.0.0.1:55473 TpTrace Verbose: 0 : 36120, 7, 2022/04/21, 08:24:26.053, 4876547052981, vstest.console.dll, TcpClientExtensions.MessageLoopAsync: NotifyDataAvailable remoteEndPoint: 127.0.0.1:55474 localEndPoint: 127.0.0.1:55473 TpTrace Warning: 0 : 36120, 13, 2022/04/21, 08:24:26.054, 4876547062078, vstest.console.dll, TestHostManagerCallbacks.ErrorReceivedCallback Test host standard error line: TpTrace Error: 0 : 36120, 7, 2022/04/21, 08:24:26.056, 4876547079447, vstest.console.dll, Socket: Message loop: failed to receive message due to socket error System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.. ---> System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host. at System.Net.Sockets.NetworkStream.Read(Span1 buffer) --- End of inner exception stack trace --- at System.Net.Sockets.NetworkStream.Read(Span1 buffer) at System.Net.Sockets.NetworkStream.ReadByte() at System.IO.BinaryReader.Read7BitEncodedInt() at System.IO.BinaryReader.ReadString() at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.LengthPrefixCommunicationChannel.NotifyDataAvailable() at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.TcpClientExtensions.MessageLoopAsync(TcpClient client, ICommunicationChannel channel, Action1 errorHandler, CancellationToken cancellationToken), remoteEndPoint: 127.0.0.1:55474 localEndPoint: 127.0.0.1:55473 TpTrace Information: 0 : 36120, 7, 2022/04/21, 08:24:26.056, 4876547080622, vstest.console.dll, SocketServer.PrivateStop: Stopping server endPoint: 127.0.0.1:55473 error: System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.. ---> System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host. at System.Net.Sockets.NetworkStream.Read(Span1 buffer) --- End of inner exception stack trace --- at System.Net.Sockets.NetworkStream.Read(Span1 buffer) at System.Net.Sockets.NetworkStream.ReadByte() at System.IO.BinaryReader.Read7BitEncodedInt() at System.IO.BinaryReader.ReadString() at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.LengthPrefixCommunicationChannel.NotifyDataAvailable() at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.TcpClientExtensions.MessageLoopAsync(TcpClient client, ICommunicationChannel channel, Action1 errorHandler, CancellationToken cancellationToken) TpTrace Verbose: 0 : 36120, 7, 2022/04/21, 08:24:26.056, 4876547084194, vstest.console.dll, LengthPrefixCommunicationChannel.Dispose: Dispose reader and writer. TpTrace Information: 0 : 36120, 7, 2022/04/21, 08:24:26.056, 4876547085122, vstest.console.dll, SocketServer.Stop: Raise disconnected event endPoint: 127.0.0.1:55473 error: System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.. ---> System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host. at System.Net.Sockets.NetworkStream.Read(Span1 buffer) --- End of inner exception stack trace --- at System.Net.Sockets.NetworkStream.Read(Span1 buffer) at System.Net.Sockets.NetworkStream.ReadByte() at System.IO.BinaryReader.Read7BitEncodedInt() at System.IO.BinaryReader.ReadString() at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.LengthPrefixCommunicationChannel.NotifyDataAvailable() at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.TcpClientExtensions.MessageLoopAsync(TcpClient client, ICommunicationChannel channel, Action1 errorHandler, CancellationToken cancellationToken) TpTrace Verbose: 0 : 36120, 7, 2022/04/21, 08:24:26.056, 4876547085663, vstest.console.dll, TestRequestSender: OnTestRunAbort: Set operation complete. TpTrace Verbose: 0 : 36120, 7, 2022/04/21, 08:24:26.056, 4876547085832, vstest.console.dll, TestRequestSender.SetOperationComplete: Setting operation complete. TpTrace Information: 0 : 36120, 7, 2022/04/21, 08:24:26.056, 4876547085994, vstest.console.dll, SocketServer.Stop: Stop server endPoint: 127.0.0.1:55473 TpTrace Verbose: 0 : 36120, 7, 2022/04/21, 08:24:26.056, 4876547086445, vstest.console.dll, TestRequestSender: GetAbortErrorMessage: Exception: System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.. ---> System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host. at System.Net.Sockets.NetworkStream.Read(Span1 buffer) --- End of inner exception stack trace --- at System.Net.Sockets.NetworkStream.Read(Span1 buffer) at System.Net.Sockets.NetworkStream.ReadByte() at System.IO.BinaryReader.Read7BitEncodedInt() at System.IO.BinaryReader.ReadString() at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.LengthPrefixCommunicationChannel.NotifyDataAvailable() at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.TcpClientExtensions.MessageLoopAsync(TcpClient client, ICommunicationChannel channel, Action1 errorHandler, CancellationToken cancellationToken) TpTrace Verbose: 0 : 36120, 7, 2022/04/21, 08:24:26.056, 4876547086674, vstest.console.dll, TestRequestSender: GetAbortErrorMessage: Client has disconnected. Wait for standard error. TpTrace Verbose: 0 : 36120, 8, 2022/04/21, 08:24:26.070, 4876547219227, vstest.console.dll, TestHostProvider.ExitCallBack: Host exited starting callback. TpTrace Error: 0 : 36120, 8, 2022/04/21, 08:24:26.070, 4876547222958, vstest.console.dll, TestHostManagerCallbacks.ExitCallBack: Testhost processId: 31832 exited with exitcode: -42 error: '' TpTrace Verbose: 0 : 36120, 8, 2022/04/21, 08:24:26.070, 4876547223376, vstest.console.dll, DotnetTestHostManager.OnHostExited: invoking OnHostExited callback TpTrace Verbose: 0 : 36120, 8, 2022/04/21, 08:24:26.070, 4876547223635, vstest.console.dll, CrossPlatEngine.TestHostManagerHostExited: calling on client process exit callback. TpTrace Information: 0 : 36120, 8, 2022/04/21, 08:24:26.070, 4876547223875, vstest.console.dll, TestRequestSender.OnClientProcessExit: Test host process exited. Standard error: TpTrace Information: 0 : 36120, 8, 2022/04/21, 08:24:26.070, 4876547224098, vstest.console.dll, SocketServer.Stop: Stop server endPoint: 127.0.0.1:55473 TpTrace Information: 0 : 36120, 7, 2022/04/21, 08:24:26.070, 4876547224462, vstest.console.dll, TestRequestSender: GetAbortErrorMessage: Received test host error message. TpTrace Error: 0 : 36120, 7, 2022/04/21, 08:24:26.070, 4876547226675, vstest.console.dll, TestRequestSender: Aborting test run because Test host process crashed

  • User Avatar
    0
    alper created
    Support Team Director

    did you solve it? I see this ticket is closed

  • User Avatar
    0
    andreking created

    No, sorry I must have hit the wrong 'add answer button'

  • User Avatar
    0
    alper created
    Support Team Director

    @maliming it looks like a license validation problem. And I guess @andreking is using v5.2.1 was that fixed in v5.2.1?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    We may not have released this patch yet.

    https://github.com/volosoft/volo/pull/9916

  • User Avatar
    0
    yekalkan created
    Support Team Fullstack Developer

    @andreking I guess you somehow made the tests dependent on another commercial package. That is the reason you are getting -42 exit code.

    Here is the solution:

    • Create appsettings.json & appsettings.secrets.json files under test\Volo.Abp.LanguageManagement.TestBase\Volo\Abp\LanguageManagement folder.

    appsettings.json content:

    {
    
    }
    

    appsettings.secrets.json content:

    {
      "AbpLicenseCode": "Your Abp License Code"
    }
    

    (You can find your license code in the main solution. Just copy from there.)

    • Add the following configuration to test\Volo.Abp.LanguageManagement.TestBase\Volo.Abp.LanguageManagement.TestBase.csproj file:
      <ItemGroup>
        <None Remove="Volo/Abp/LanguageManagement/appsettings.json" />
        <Content Include="Volo/Abp/LanguageManagement/appsettings.json">
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
          <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
          <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
        </Content>
        <None Remove="Volo/Abp/LanguageManagement/appsettings.secrets.json" />
        <Content Include="Volo/Abp/LanguageManagement/appsettings.secrets.json">
          <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
          <CopyToOutputDirectory>Always</CopyToOutputDirectory>
        </Content>
      </ItemGroup>
    
    • Add the following configuration to ConfigureServices method in test\Volo.Abp.LanguageManagement.TestBase\Volo\Abp\LanguageManagement\LanguageManagementTestBaseModule.cs file:
            var builder = new ConfigurationBuilder();
            builder.AddJsonFile("Volo/Abp/LanguageManagement/appsettings.json", false);
            builder.AddJsonFile("Volo/Abp/LanguageManagement/appsettings.secrets.json", true);
            context.Services.ReplaceConfiguration(builder.Build());
    

    (you may need to add Microsoft.Extensions.Configuration namespace)

  • User Avatar
    0
    andreking created

    Thanks for your help, the tests run now.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 01, 2024, 05:35