Open Closed

Running Tests Randomly generate exception message Object reference not set to an instance of an object. #7280


User avatar
0
alex.maiereanu@3sstudio.com created
  • ABP Framework version: v8.1.1
  • UI Type: Angular
  • 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:

HI ABP team,

When running tests on Azure Devops and very rarely on the developer machine, we get randomly failing unit tests. We can see the following exception:

Starting test execution, please wait... A total of 1 test files matched the specified pattern. [xUnit.net 00:00:18.48] Project.App.EntityFrameworkCore.Repositories.IdentityCustomerUserRepositoryTests.GetCustomerIdentityUsers_Will_Filter_By_Email_Or_UserName(email: null, userName: null, customerName: "CME", customerNumber: null, expectedCount: 1) [FAIL] Failed Project.App.EntityFrameworkCore.Repositories.IdentityCustomerUserRepositoryTests.GetCustomerIdentityUsers_Will_Filter_By_Email_Or_UserName(email: null, userName: null, customerName: "CME", customerNumber: null, expectedCount: 1) [1 ms] Error Message: Volo.Abp.AbpInitializationException : An error occurred during the initialize Volo.Abp.Modularity.OnApplicationInitializationModuleLifecycleContributor phase of the module Project.App.QQTestBaseModule, Project.App.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. ---- System.NullReferenceException : Object reference not set to an instance of an object. 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 Project.App.QQTestBase1..ctor() at Project.App.EntityFrameworkCore.QQEntityFrameworkCoreTestBase..ctor() at Project.App.EntityFrameworkCore.Repositories.IdentityCustomerUserRepositoryTests..ctor() in /home/vsts/work/1/s/test/Project.App.EntityFrameworkCore.Tests/EntityFrameworkCore/Repositories/IdentityCustomerUserRepositoryTests.cs:line 23 at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions) ----- Inner Stack Trace ----- at Microsoft.Data.Sqlite.SqliteConnection.RemoveCommand(SqliteCommand command) 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)

As mentioned, each time it's a different test. The only common thing is the exception root: Volo.Abp.AbpInitializationException : An error occurred during the initialize Volo.Abp.Modularity.OnApplicationInitializationModuleLifecycleContributor phase of the module Project.App.QQTestBaseModule, Project.App.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. ---- System.NullReferenceException : Object reference not set to an instance of an object. Stack Trace: at Volo.Abp.Modularity.ModuleManager.InitializeModules(ApplicationInitializationContext context)

We would gladly work together with you to discover the root cause, but I don't what we can change in the setup to get more details.


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

    Hi,

    Maybe these links can help you

    https://support.abp.io/QA/Questions/4545/Unit-tests-fail-randomly-in-v701 https://github.com/abpframework/abp/issues/15389

  • User Avatar
    0
    alex.maiereanu@3sstudio.com created

    Hi liangshiwei,

    Thanks for the quick reply.

    Since we are running a new project, from template version 8.0.5, we already have all the proposed fixes implemented.

    This is the EF test project module:

    
    
    
    public class MyEntityFrameworkCoreTestModule : AbpModule
    {
    private SqliteConnection? \_sqliteConnection;
    
    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        Configure<FeatureManagementOptions>(options =>
        {
            options.SaveStaticFeaturesToDatabase = false;
            options.IsDynamicFeatureStoreEnabled = false;
        });
        Configure<PermissionManagementOptions>(options =>
        {
            options.SaveStaticPermissionsToDatabase = false;
            options.IsDynamicPermissionStoreEnabled = false;
        });
        Configure<TextTemplateManagementOptions>(options =>
        {
            options.SaveStaticTemplatesToDatabase = false;
            options.IsDynamicTemplateStoreEnabled = false;
        });
        context.Services.AddAlwaysDisableUnitOfWorkTransaction();
    
        ConfigureInMemorySqlite(context.Services);
    
    }
    
    private void ConfigureInMemorySqlite(IServiceCollection services)
    {
        _sqliteConnection = CreateDatabaseAndGetConnection();
    
        services.Configure<AbpDbContextOptions>(options =>
        {
            options.Configure(context =>
            {
                context.DbContextOptions.UseSqlite(_sqliteConnection);
            });
        });
    }
    
    public override void OnApplicationShutdown(ApplicationShutdownContext context)
    {
        _sqliteConnection?.Dispose();
    }
    
    private static SqliteConnection CreateDatabaseAndGetConnection()
    {
        var connection = new SqliteConnection("Data Source=:memory:");
        connection.Open();
    
        var options = new DbContextOptionsBuilder<QQDbContext>()
            .UseSqlite(connection)
            .Options;
    
        using (var context = new QQDbContext(options))
        {
            context.GetService<IRelationalDatabaseCreator>().CreateTables();
        }
    
        return connection;
    }
    
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Have do I reproduce the problem? could you share a simple project with me? I will check it.

  • User Avatar
    0
    alex.maiereanu@3sstudio.com created

    Thats the issue

    I can't reproduce the issue consistently on my project, which has more than 100 tests and of course on a new sample project this is not appearing.

    My hunch is that this is starting to be a problem after X amount of tests are added.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Sorry, But if I can't reproduce the problem, I can't help you.

  • User Avatar
    0
    alex.maiereanu@3sstudio.com created

    Hi

    I understand that it's difficult for you to move forward, but you also need to understand that we can't just share customer projects :D. What I'm asking from you is for help to see how we can better catch this exception and see what is going on. Is there a way to add better error handling? Would you have a hunch from where this originates?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    I remember this is an EF core problem, you can check this:

    https://github.com/abpframework/abp/issues/19065

  • User Avatar
    0
    alex.maiereanu@3sstudio.com created

    I'm trying out the fix from here: https://github.com/abpframework/abp/pull/19125

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    okay

Made with ❤️ on ABP v9.1.0-preview. Updated on December 12, 2024, 07:15