Starts in:
2 DAYS
21 HRS
35 MIN
44 SEC
Starts in:
2 D
21 H
35 M
44 S
Open Closed

Unit Tests Fail Randomly #7480


User avatar
0
scott7106 created
  • ABP Framework version: v8.2.0
  • UI Type: Blazor Web App
  • Database System: EF Core (SQL Server)
  • Tiered (for MVC) or Auth Server Separated (for Angular): no
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

Running the unit tests fails randomly. This is related to issue #4545 https://support.abp.io/QA/Questions/4545/Unit-tests-fail-randomly-in-v701 This has never been resolved. We took the steps in that ticket and reduced the frequency, but it is still occurring across multiple projects.

The error shown below is from a baseline project with very little customization at this point. We added the CMS Kit Pro via source code to the project.

Run dotnet test --configuration Release --no-build Test run for /home/runner/work/OtisEd.Artifact.Blazor/OtisEd.Artifact.Blazor/modules/Volo.CmsKit.Pro/test/Volo.CmsKit.Pro.Application.Tests/bin/Release/net8.0/Volo.CmsKit.Pro.Application.Tests.dll (.NETCoreApp,Version=v8.0) Test run for /home/runner/work/OtisEd.Artifact.Blazor/OtisEd.Artifact.Blazor/modules/Volo.CmsKit.Pro/test/Volo.CmsKit.Pro.Domain.Tests/bin/Release/net8.0/Volo.CmsKit.Pro.Domain.Tests.dll (.NETCoreApp,Version=v8.0) Microsoft (R) Test Execution Command Line Tool Version 17.10.0 (x64) Copyright (c) Microsoft Corporation. All rights reserved.

Starting test execution, please wait... Microsoft (R) Test Execution Command Line Tool Version 17.10.0 (x64) Copyright (c) Microsoft Corporation. All rights reserved.

A total of 1 test files matched the specified pattern. Starting test execution, please wait... A total of 1 test files matched the specified pattern. [xUnit.net 00:00:10.31] Volo.CmsKit.Pro.Newsletters.NewsletterRecordManager_Tests.GetNewsletterPreferencesAsync [FAIL] Failed Volo.CmsKit.Pro.Newsletters.NewsletterRecordManager_Tests.GetNewsletterPreferencesAsync [1 ms] Error Message: Volo.Abp.AbpInitializationException : An error occurred during the initialize Volo.Abp.Modularity.OnApplicationInitializationModuleLifecycleContributor phase of the module Volo.CmsKit.Pro.CmsKitProTestBaseModule, Volo.CmsKit.Pro.TestBase, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: SqliteConnection does not support nested transactions.. See the inner exception for details. ---- System.InvalidOperationException : SqliteConnection does not support nested transactions. Stack Trace: at Volo.Abp.Modularity.ModuleManager.InitializeModules(ApplicationInitializationContext context) at Volo.Abp.AbpApplicationBase.InitializeModules() at Volo.Abp.AbpApplicationWithExternalServiceProvider.Initialize(IServiceProvider serviceProvider) at Volo.Abp.Testing.AbpIntegratedTest1..ctor() at Volo.CmsKit.Pro.CmsKitProTestBase1..ctor() at Volo.CmsKit.Pro.CmsKitProDomainTestBase..ctor() at Volo.CmsKit.Pro.Newsletters.NewsletterRecordManager_Tests..ctor() in /home/runner/work/OtisEd.Artifact.Blazor/OtisEd.Artifact.Blazor/modules/Volo.CmsKit.Pro/test/Volo.CmsKit.Pro.Domain.Tests/Newsletters/NewsletterRecordManager_Tests.cs:line 15 at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions) ----- Inner Stack Trace ----- at Microsoft.Data.Sqlite.SqliteConnection.BeginTransaction(IsolationLevel isolationLevel, Boolean deferred) at Microsoft.Data.Sqlite.SqliteConnection.BeginTransaction(IsolationLevel isolationLevel) at Microsoft.Data.Sqlite.SqliteConnection.BeginDbTransaction(IsolationLevel isolationLevel) at System.Data.Common.DbConnection.BeginDbTransactionAsync(IsolationLevel isolationLevel, CancellationToken cancellationToken) --- End of stack trace from previous location --- at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.BeginTransactionAsync(IsolationLevel isolationLevel, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.BeginTransactionAsync(CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.ExecuteAsync(IEnumerable1 commandBatches, IRelationalConnection connection, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.ExecuteAsync(IEnumerable1 commandBatches, IRelationalConnection connection, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.ExecuteAsync(IEnumerable1 commandBatches, IRelationalConnection connection, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(IList1 entriesToSave, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(StateManager stateManager, Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken) at Volo.Abp.EntityFrameworkCore.AbpDbContext1.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken) at Volo.Abp.Uow.UnitOfWork.SaveChangesAsync(CancellationToken cancellationToken) at Volo.Abp.Uow.UnitOfWork.CompleteAsync(CancellationToken cancellationToken) at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation) at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync(IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed) at Volo.CmsKit.Pro.CmsKitProTestBaseModule.<>c__DisplayClass4_0.<<SeedTestData>b__0>d.MoveNext() in /home/runner/work/OtisEd.Artifact.Blazor/OtisEd.Artifact.Blazor/modules/Volo.CmsKit.Pro/test/Volo.CmsKit.Pro.TestBase/CmsKitProTestBaseModule.cs:line 90 --- End of stack trace from previous location --- at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException(Task task) at Nito.AsyncEx.AsyncContext.<>c__DisplayClass15_0.<Run>b__0(Task t) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) --- End of stack trace from previous location --- at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread) --- End of stack trace from previous location --- at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException(Task task) at Nito.AsyncEx.AsyncContext.Run(Func1 action) at Volo.Abp.Threading.AsyncHelper.RunSync(Func`1 action) at Volo.CmsKit.Pro.CmsKitProTestBaseModule.SeedTestData(ApplicationInitializationContext context) in /home/runner/work/OtisEd.Artifact.Blazor/OtisEd.Artifact.Blazor/modules/Volo.CmsKit.Pro/test/Volo.CmsKit.Pro.TestBase/CmsKitProTestBaseModule.cs:line 86 at Volo.CmsKit.Pro.CmsKitProTestBaseModule.OnApplicationInitialization(ApplicationInitializationContext context) in /home/runner/work/OtisEd.Artifact.Blazor/OtisEd.Artifact.Blazor/modules/Volo.CmsKit.Pro/test/Volo.CmsKit.Pro.TestBase/CmsKitProTestBaseModule.cs:line 81 at Volo.Abp.Modularity.OnApplicationInitializationModuleLifecycleContributor.Initialize(ApplicationInitializationContext context, IAbpModule module) at Volo.Abp.Modularity.ModuleManager.InitializeModules(ApplicationInitializationContext context)


3 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you try to using the AbpUnitTestSqliteConnection in your EF Core test project?

    https://github.com/abpframework/abp/blob/c4b8e00e2e4b2b0f7e56aff07e26b56fceb0d0ed/templates/module/aspnet-core/test/MyCompanyName.MyProjectName.EntityFrameworkCore.Tests/EntityFrameworkCore/MyProjectNameEntityFrameworkCoreTestModule.cs#L36

  • User Avatar
    0
    scott7106 created

    It was already using the AbpUnitTestSqliteConnection but it was not disabling the UnitOfWorkTransaction. I added the following line to the CmsKitProEntityFrameworkCoreTestModule ConfigureServices method.

    context.Services.AddAlwaysDisableUnitOfWorkTransaction();

    I haven't seen it fail since in the new project.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    ok, You can keep watch.

    as the AddAlwaysDisableUnitOfWorkTransaction method name, It disables transaction always.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06