Open Closed

Unit tests fail randomly in v7.0.1 #4545


User avatar
0
scott7106 created
  • ABP Framework version: v7.0.1
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no
  • Steps to reproduce the issue:"
  1. Generate a new project Acme.Bookstore using ABP Suite (selected Angular, EF Core and Lepton-X)
  2. Build the project
  3. Run the unit tests -- no code changes made to the project of any kind

The 3 example unit tests given do not run reliably. Sometimes they all error, sometimes they all pass, and sometimes a random test passes. Just keep running to get different results. The error (when it fails) is always the same and show below.

  • Exception message and stack trace: see below

Volo.Abp.AbpInitializationException: An error occurred during the initialize Volo.Abp.Modularity.OnApplicationInitializationModuleLifecycleContributor...

Volo.Abp.AbpInitializationException An error occurred during the initialize Volo.Abp.Modularity.OnApplicationInitializationModuleLifecycleContributor phase of the module Acme.Bookstore.BookstoreTestBaseModule, Acme.Bookstore.TestBase, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: Object reference not set to an instance of an object.. See the inner exception for details. 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 Acme.Bookstore.BookstoreTestBase1..ctor() at Acme.Bookstore.EntityFrameworkCore.BookstoreEntityFrameworkCoreTestBase..ctor() at Acme.Bookstore.EntityFrameworkCore.Samples.SampleRepositoryTests..ctor() in C:\Users\scott\source\repos\Acme.Bookstore\aspnet-core\test\Acme.Bookstore.EntityFrameworkCore.Tests\EntityFrameworkCore\Samples\SampleRepositoryTests.cs:line 18 at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)

System.NullReferenceException Object reference not set to an instance of an object. at Microsoft.Data.Sqlite.SqliteConnection.RemoveCommand(SqliteCommand command) at Microsoft.Data.Sqlite.SqliteCommand.Dispose(Boolean disposing) at System.ComponentModel.Component.Dispose() at System.Data.Common.DbCommand.DisposeAsync() at Microsoft.EntityFrameworkCore.Storage.RelationalDataReader.DisposeAsync() at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable1 source, CancellationToken cancellationToken) at Volo.Abp.SettingManagement.EntityFrameworkCore.EfCoreSettingRepository.GetListAsync(String providerName, String providerKey, CancellationToken cancellationToken) at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo) at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue1.ProceedAsync() at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation) at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed) at Volo.Abp.SettingManagement.SettingManagementStore.SetCacheItemsAsync(String providerName, String providerKey, String currentName, SettingCacheItem currentCacheItem) at Volo.Abp.SettingManagement.SettingManagementStore.GetCacheItemAsync(String name, String providerName, String providerKey) at Volo.Abp.SettingManagement.SettingManagementStore.GetOrNullAsync(String name, String providerName, String providerKey) at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo) at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue1.ProceedAsync() at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation) at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed) at Volo.Abp.Settings.UserSettingValueProvider.GetOrNullAsync(SettingDefinition setting) at Volo.Abp.Settings.SettingProvider.GetOrNullValueFromProvidersAsync(IEnumerable1 providers, SettingDefinition setting) at Volo.Abp.Settings.SettingProvider.GetOrNullAsync(String name) at Volo.Abp.Settings.SettingProviderExtensions.GetAsync[T](ISettingProvider settingProvider, String name, T defaultValue) at Volo.Abp.Identity.AbpIdentityOptionsManager.OverrideOptionsAsync(String name, IdentityOptions options) at Volo.Abp.Identity.IdentityDataSeeder.SeedAsync(String adminEmail, String adminPassword, Nullable1 tenantId) at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo) at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue1.ProceedAsync() at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation) at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed) at Volo.Abp.Data.DataSeeder.SeedAsync(DataSeedContext context) at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous(IInvocation invocation, IInvocationProceedInfo proceedInfo) at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapter.ProceedAsync() at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation) at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync(IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed) at Acme.Bookstore.BookstoreTestBaseModule.<>c__DisplayClass2_0.<<SeedTestData>b__0>d.MoveNext() in C:\Users\scott\source\repos\Acme.Bookstore\aspnet-core\test\Acme.Bookstore.TestBase\BookstoreTestBaseModule.cs:line 41 --- 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(Func1 action) at Acme.Bookstore.BookstoreTestBaseModule.SeedTestData(ApplicationInitializationContext context) in C:\Users\scott\source\repos\Acme.Bookstore\aspnet-core\test\Acme.Bookstore.TestBase\BookstoreTestBaseModule.cs:line 37 at Acme.Bookstore.BookstoreTestBaseModule.OnApplicationInitialization(ApplicationInitializationContext context) in C:\Users\scott\source\repos\Acme.Bookstore\aspnet-core\test\Acme.Bookstore.TestBase\BookstoreTestBaseModule.cs:line 32 at Volo.Abp.Modularity.OnApplicationInitializationModuleLifecycleContributor.Initialize(ApplicationInitializationContext context, IAbpModule module) at Volo.Abp.Modularity.ModuleManager.InitializeModules(ApplicationInitializationContext context)

Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

6 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    Hi,

    https://github.com/abpframework/abp/pull/15508

    We fixed the problem.

    You can add the context.Services.AddAlwaysDisableUnitOfWorkTransaction(); to test the project.

    https://github.com/abpframework/abp/pull/15508/files#diff-59bb2ffc71a0feb31225e572089bcdfff798fc00c95dd402b3b5aace7735ee76R25

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    scott7106 created

    Hi,

    Unfortunately, this does not resolve the issue. I am still getting random failures. In fact, now there is an additional problem. Not only do random tests fail, but the process randomly hangs and does not complete. I have to manually kill the test process.

    Edit: if the unit of work manager is not reliable for tests, why would I want to use it in my application? Disabling the UnitOfWorkTransaction seems like a material change. Now the tests are not covering a key element of the underlying system. What keeps this from being an issue in my application when it is under load? In addition to getting a fix which works, I would like to understand why you think disabling this in the tests is acceptable. What am I missing?

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    . I am still getting random failures.

    What's the exception details?

    We disable transactions because of SQLite limitations.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    scott7106 created

    When I get an error, The error is the one below. Many times, it just hangs and does not complete. It acts like something is deadlocked in those cases. I will email you a link to one of our project files. This is happening in all of our projects we have upgraded to v7 at this point.

    Volo.Abp.AbpInitializationException: An error occurred during the initialize Volo.Abp.Modularity.OnApplicationInitializationModuleLifecycleContributor...
    
    Volo.Abp.AbpInitializationException
    An error occurred during the initialize Volo.Abp.Modularity.OnApplicationInitializationModuleLifecycleContributor phase of the module Anlar.Everest.EverestTestBaseModule, Anlar.Everest.TestBase, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null: Object reference not set to an instance of an object.. See the inner exception for details.
       at Volo.Abp.Modularity.ModuleManager.InitializeModules(ApplicationInitializationContext context)
       at Volo.Abp.AbpApplicationBase.InitializeModules()
       at Volo.Abp.AbpApplicationWithExternalServiceProvider.Initialize(IServiceProvider serviceProvider)
       at Volo.Abp.Testing.AbpIntegratedTest`1..ctor()
       at Anlar.Everest.EverestTestBase`1..ctor()
       at Anlar.Everest.EverestDomainTestBase..ctor()
       at Anlar.Everest.Samples.SampleDomainTests..ctor() in C:\AppDev\otised\Anlar.Everest\aspnet-core\test\Anlar.Everest.Domain.Tests\Samples\SampleDomainTests.cs:line 18
       at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
    
    System.NullReferenceException
    Object reference not set to an instance of an object.
       at Microsoft.Data.Sqlite.SqliteConnection.RemoveCommand(SqliteCommand command)
       at Microsoft.Data.Sqlite.SqliteCommand.Dispose(Boolean disposing)
       at System.ComponentModel.Component.Dispose()
       at System.Data.Common.DbCommand.DisposeAsync()
       at Microsoft.EntityFrameworkCore.Storage.RelationalDataReader.DisposeAsync()
       at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
       at Volo.Abp.SettingManagement.EntityFrameworkCore.EfCoreSettingRepository.GetListAsync(String providerName, String providerKey, CancellationToken cancellationToken)
       at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
       at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
       at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
       at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
       at Volo.Abp.SettingManagement.SettingManagementStore.SetCacheItemsAsync(String providerName, String providerKey, String currentName, SettingCacheItem currentCacheItem)
       at Volo.Abp.SettingManagement.SettingManagementStore.GetCacheItemAsync(String name, String providerName, String providerKey)
       at Volo.Abp.SettingManagement.SettingManagementStore.GetOrNullAsync(String name, String providerName, String providerKey)
       at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
       at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
       at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
       at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
       at Volo.Abp.Settings.UserSettingValueProvider.GetOrNullAsync(SettingDefinition setting)
       at Volo.Abp.Settings.SettingProvider.GetOrNullValueFromProvidersAsync(IEnumerable`1 providers, SettingDefinition setting)
       at Volo.Abp.Settings.SettingProvider.GetOrNullAsync(String name)
       at Volo.Abp.Settings.SettingProviderExtensions.GetAsync[T](ISettingProvider settingProvider, String name, T defaultValue)
       at Volo.Abp.Identity.AbpIdentityOptionsManager.OverrideOptionsAsync(String name, IdentityOptions options)
       at Volo.Abp.Identity.IdentityDataSeeder.SeedAsync(String adminEmail, String adminPassword, Nullable`1 tenantId)
       at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
       at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
       at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
       at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
       at Volo.Abp.Data.DataSeeder.SeedAsync(DataSeedContext context)
       at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous(IInvocation invocation, IInvocationProceedInfo proceedInfo)
       at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapter.ProceedAsync()
       at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
       at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync(IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
       at Anlar.Everest.EverestTestBaseModule.<>c__DisplayClass2_0.<<SeedTestData>b__0>d.MoveNext() in C:\AppDev\otised\Anlar.Everest\aspnet-core\test\Anlar.Everest.TestBase\EverestTestBaseModule.cs:line 43
    --- 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(Func`1 action)
       at Volo.Abp.Threading.AsyncHelper.RunSync(Func`1 action)
       at Anlar.Everest.EverestTestBaseModule.SeedTestData(ApplicationInitializationContext context) in C:\AppDev\otised\Anlar.Everest\aspnet-core\test\Anlar.Everest.TestBase\EverestTestBaseModule.cs:line 39
       at Anlar.Everest.EverestTestBaseModule.OnApplicationInitialization(ApplicationInitializationContext context) in C:\AppDev\otised\Anlar.Everest\aspnet-core\test\Anlar.Everest.TestBase\EverestTestBaseModule.cs:line 34
       at Volo.Abp.Modularity.OnApplicationInitializationModuleLifecycleContributor.Initialize(ApplicationInitializationContext context, IAbpModule module)
       at Volo.Abp.Modularity.ModuleManager.InitializeModules(ApplicationInitializationContext context)
    
    
    
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can try that.

    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        ConfigureInMemorySqlite(context.Services);
        
    
        Configure<FeatureManagementOptions>(options =>
        {
            options.SaveStaticFeaturesToDatabase = false;
            options.IsDynamicFeatureStoreEnabled = false;
        });
        Configure<PermissionManagementOptions>(options =>
        {
            options.SaveStaticPermissionsToDatabase = false;
            options.IsDynamicPermissionStoreEnabled = false;
        });
        
        context.Services.AddAbpDynamicOptions<IdentityOptions, MyAbpIdentityOptionsManager>();
    }
    
    public class MyAbpIdentityOptionsManager : AbpIdentityOptionsManager
    {
        public MyAbpIdentityOptionsManager(
            IOptionsFactory<IdentityOptions> factory,
            ISettingProvider settingProvider)
            : base(factory, settingProvider)
        {
        }
    
        protected override Task OverrideOptionsAsync(string name, IdentityOptions options)
        {
            return Task.CompletedTask;
        }
    }
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    scott7106 created

    Adding the code below resolved the problem and allowed all tests to run successfully to completion. After running this successfully multiple times, I then re-enabled the unit of work transactions and reran the tests. They ran successfully with the unit of work transactions enabled.

    Configure&lt;FeatureManagementOptions&gt;(options =>
    {
        options.SaveStaticFeaturesToDatabase = false;
        options.IsDynamicFeatureStoreEnabled = false;
    });
    Configure&lt;PermissionManagementOptions&gt;(options =>
    {
        options.SaveStaticPermissionsToDatabase = false;
        options.IsDynamicPermissionStoreEnabled = false;
    });
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 23, 2026, 09:57
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.