Starts in:
1 DAY
3 HRS
30 MIN
20 SEC
Starts in:
1 D
3 H
30 M
20 S
Open Closed

Unit tests randomly fail #5658


User avatar
0
jpatron created
  • ABP Framework version: v6.0.3

  • UI Type: MVC

  • Database System: EF Core (SQL Server)

  • Tiered (for MVC) or Auth Server Separated (for Angular): yes

  • Exception message and full stack trace: [xUnit.net 00:00:16.32] Volo.Abp.AbpInitializationException : An error occurred during the initialize Volo.Abp.Modularity.OnApplicationInitializationModuleLifecycleContributor phase of the module MyApp.MyAppTestBaseModule, MyApp.TestBase, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: The property 'Provstate.Id' is part of a key and so cannot be modified or marked as modified. To change the principal of an existing entity with an identifying foreign key, first delete the dependent and invoke 'SaveChanges', and then associate the dependent with the new principal.. See the inner exception for details. [xUnit.net 00:00:16.32] ---- System.InvalidOperationException : The property 'Provstate.Id' is part of a key and so cannot be modified or marked as modified. To change the principal of an existing entity with an identifying foreign key, first delete the dependent and invoke 'SaveChanges', and then associate the dependent with the new principal. [xUnit.net 00:00:16.32] Stack Trace: [xUnit.net 00:00:16.32] at Volo.Abp.Modularity.ModuleManager.InitializeModules(ApplicationInitializationContext context) [xUnit.net 00:00:16.32] at Volo.Abp.AbpApplicationBase.InitializeModules() [xUnit.net 00:00:16.32] at Volo.Abp.AbpApplicationWithExternalServiceProvider.Initialize(IServiceProvider serviceProvider) [xUnit.net 00:00:16.32] at Microsoft.AspNetCore.Builder.AbpApplicationBuilderExtensions.InitializeApplication(IApplicationBuilder app) [xUnit.net 00:00:16.32] C:\Code\MyApp.Abp\test\MyApp.Web.Tests\MyAppWebTestStartup.cs(16,0): at MyApp.MyAppWebTestStartup.Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) [xUnit.net 00:00:16.32] at System.RuntimeMethodHandle.InvokeMethod(Object target, Span1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) [xUnit.net 00:00:16.32] at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) [xUnit.net 00:00:16.32] at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder) [xUnit.net 00:00:16.32] at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder) [xUnit.net 00:00:16.32] at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass15_0.<UseStartup>b__1(IApplicationBuilder app) [xUnit.net 00:00:16.32] at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder) [xUnit.net 00:00:16.32] at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app) [xUnit.net 00:00:16.32] at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken) [xUnit.net 00:00:16.32] at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken) [xUnit.net 00:00:16.32] at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Start(IHost host) [xUnit.net 00:00:16.32] at Volo.Abp.AspNetCore.TestBase.AbpAspNetCoreIntegratedTestBase1..ctor() [xUnit.net 00:00:16.32] at MyApp.MyAppWebTestBase..ctor() [xUnit.net 00:00:16.32] at MyApp.Pages.Questionnaire_Tests..ctor() [xUnit.net 00:00:16.32] at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions) [xUnit.net 00:00:16.32] ----- Inner Stack Trace ----- [xUnit.net 00:00:16.32] at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetPropertyModified(IProperty property, Boolean changeState, Boolean isModified, Boolean isConceptualNull, Boolean acceptChanges) [xUnit.net 00:00:16.32] at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectValueChange(InternalEntityEntry entry, IProperty property) [xUnit.net 00:00:16.32] at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.LocalDetectChanges(InternalEntityEntry entry) [xUnit.net 00:00:16.32] at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectChanges(IStateManager stateManager) [xUnit.net 00:00:16.32] at Microsoft.EntityFrameworkCore.ChangeTracking.ChangeTracker.DetectChanges() [xUnit.net 00:00:16.32] at Microsoft.EntityFrameworkCore.ChangeTracking.ChangeTracker.TryDetectChanges() [xUnit.net 00:00:16.32] at Microsoft.EntityFrameworkCore.ChangeTracking.ChangeTracker.Entries() [xUnit.net 00:00:16.32] at Volo.Abp.EntityFrameworkCore.AbpDbContext1.HandlePropertiesBeforeSave() [xUnit.net 00:00:16.32] at Volo.Abp.EntityFrameworkCore.AbpDbContext1.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken) [xUnit.net 00:00:16.32] at Volo.Abp.Uow.UnitOfWork.SaveChangesAsync(CancellationToken cancellationToken) [xUnit.net 00:00:16.32] C:\Code\MyApp.Abp\src\MyApp.Domain\Seed\MyAppDataSeedContributor.cs(117,0): at MyApp.Seed.MyAppDataSeedContributor.SeedFormTypes() [xUnit.net 00:00:16.32] C:\Code\MyApp.Abp\src\MyApp.Domain\Seed\MyAppDataSeedContributor.cs(59,0): at MyApp.Seed.MyAppDataSeedContributor.SeedAsync(DataSeedContext context) [xUnit.net 00:00:16.32] at Volo.Abp.Data.DataSeeder.SeedAsync(DataSeedContext context) [xUnit.net 00:00:16.32] at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous(IInvocation invocation, IInvocationProceedInfo proceedInfo) [xUnit.net 00:00:16.32] at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapter.ProceedAsync() [xUnit.net 00:00:16.32] at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation) [xUnit.net 00:00:16.32] at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync(IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed) [xUnit.net 00:00:16.32] C:\Code\MyApp.Abp\test\MyApp.TestBase\MyAppTestBaseModule.cs(40,0): at MyApp.MyAppTestBaseModule.<>c__DisplayClass2_0.<<SeedTestData>b__0>d.MoveNext() [xUnit.net 00:00:16.32] --- End of stack trace from previous location --- [xUnit.net 00:00:16.32] at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException(Task task) [xUnit.net 00:00:16.32] at Nito.AsyncEx.AsyncContext.<>c__DisplayClass15_0.<Run>b__0(Task t) [xUnit.net 00:00:16.32] at System.Threading.Tasks.ContinuationTaskFromTask.InnerInvoke() [xUnit.net 00:00:16.32] at System.Threading.Tasks.Task.<>c.<.cctor>b__272_0(Object obj) [xUnit.net 00:00:16.32] at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) [xUnit.net 00:00:16.32] --- End of stack trace from previous location --- [xUnit.net 00:00:16.32] at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) [xUnit.net 00:00:16.32] at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread) [xUnit.net 00:00:16.32] --- End of stack trace from previous location --- [xUnit.net 00:00:16.32] at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException(Task task) [xUnit.net 00:00:16.32] at Nito.AsyncEx.AsyncContext.Run(Func1 action) [xUnit.net 00:00:16.32] at Volo.Abp.Threading.AsyncHelper.RunSync(Func1 action) [xUnit.net 00:00:16.32] C:\Code\MyApp.Abp\test\MyApp.TestBase\MyAppTestBaseModule.cs(37,0): at MyApp.MyAppTestBaseModule.SeedTestData(ApplicationInitializationContext context) [xUnit.net 00:00:16.32] C:\Code\MyApp.Abp\test\MyApp.TestBase\MyAppTestBaseModule.cs(32,0): at MyApp.MyAppTestBaseModule.OnApplicationInitialization(ApplicationInitializationContext context) [xUnit.net 00:00:16.32] at Volo.Abp.Modularity.OnApplicationInitializationModuleLifecycleContributor.Initialize(ApplicationInitializationContext context, IAbpModule module) [xUnit.net 00:00:16.32] at Volo.Abp.Modularity.ModuleManager.InitializeModules(ApplicationInitializationContext context)

  • Steps to reproduce the issue:

    1. Run all tests

We have an issue where random unit tests fail randomly but the error message is consistent (see stack trace above). I did some research and you may have solved a similar issue in newer versions of ABP: https://support.abp.io/QA/Questions/5204/Randomly-test-are-failing

My question is whether I can implement that solution in v.6.0.3. If so, can you provide some guidance on how to do such implementation? Thanks!


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

    Hi,

    They don't look like the same error, could you share the full steps to reproduce the problem? thanks.

  • User Avatar
    0
    jpatron created

    There are no particular steps to reproduce the error. The issue occurs randomly while running all unit tests either locally via Visual Studio or while part of our CI/CD process. We made a previous solution for a different application and we never found this issue there, though. The main difference between this new solution (let's call it "Solution B") and the one we made for the previous application ("Solution A") is that we have foreign keys between a couple of tables in Solution B.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    This seems to be related to your code

    The property 'Provstate.Id' is part of a key and so cannot be modified or marked as modified. To change the principal of an existing entity with an identifying foreign key, first delete the dependent and invoke 'SaveChanges', and then associate the dependent with the new principa

    https://stackoverflow.com/questions/73704497/the-property-is-part-of-a-key-and-so-cannot-be-modified-or-marked-as-modified-f https://github.com/dotnet/efcore/issues/4560

  • User Avatar
    0
    jpatron created

    Thanks for the links, but as I mentioned before, we are using ABP Commercial v.6.0.3, which seems to rely on Microsoft.EntityFrameworkCore v.6.0.5 so the second link doesn't quite apply to us. Based on the first link you provided, is the only solution to this issue for us to remove the foreign keys from our solution?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    is the only solution to this issue for us to remove the foreign keys from our solution?

    I don't think so, there must be a solution.

    But I don't know your project details, if you can provide the full steps to reproduce the problem or share a simple project that can reproduce the problem. I will check it and try to help you.

  • User Avatar
    0
    jpatron created

    We removed the primary keys from our solution but the error still occurs randomly. Like I have said before, the steps are:

    1. Clean solution
    2. Run all tests

    I am not sure how to provide you with a copy of our solution in a secure way, though.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    We removed the primary keys from our solution but the error still occurs randomly.

    What's the error logs?

    I am not sure how to provide you with a copy of our solution in a secure way, though.

    You can use Suite to create a new solution to reproduce this problem.

  • User Avatar
    0
    jpatron created

    I would like to send you the logs of the last 3 failed builds in our CI/CD process but the character limit here prevents me to do so. Is there an email address I can send you the logs as attachments?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Ok, my email is: shiwei.liang@volosoft.com

  • User Avatar
    0
    jpatron created

    Hi, I emailed you the logs earlier today. Please let me know if you got the attachments. Thanks!

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    ok, I received the email.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    I have checked the logs.

    All error messages are The property 'Provstate.Id' is part of a key and so cannot be modified or marked as modified....

    Do you have such code in your project?

    HasPrincipalKey(....)
    

    This is by EF design: https://learn.microsoft.com/en-us/ef/core/modeling/keys?tabs=data-annotations#alternate-keys https://github.com/dotnet/efcore/issues/4560 If you just want to enforce uniqueness on a column, define a unique index rather than an alternate key (see Indexes). In EF, alternate keys are read-only and provide additional semantics over unique indexes because they can be used as the target of a foreign key.

    Anyway, I don't know the details of your project, could you use Suite to create a new solution to reproduce this problem? I will try to help you.

  • User Avatar
    0
    jpatron created

    Thanks for reviewing the logs! We do not have any instance of "HasPrincipalKey" across our solution. I can create a new solution using Suite, but I am not sure how that would help us to reproduce this issue, could you elaborate a little further?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    but I am not sure how that would help us to reproduce this issue, could you elaborate a little further?

    You just need to make a minimum reproducible example similar to your project entity.

  • User Avatar
    0
    jpatron created

    We used the CLI instead of the Suite to create the solution. Another difference I just noticed between this solution we are having issues with and the other one for a different application is that we have an entity with navigation properties. Do you think that might be related to this issue?

    In the meantime, I'll try to create a new solution using CLI, add the missing entities without navigation properties this time and see how that goes.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Another difference I just noticed between this solution we are having issues with and the other one for a different application is that we have an entity with navigation properties. Do you think that might be related to this issue?

    I'm not sure. but I don't think it should be relevant.

    In the meantime, I'll try to create a new solution using CLI, add the missing entities without navigation properties this time and see how that goes.

    Ok.

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