Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

System.OutOfMemoryException in churn mode
spolonski
#1 Posted : Tuesday, April 4, 2023 9:36:34 AM(UTC)
Rank: Member

Groups: Registered
Joined: 7/11/2016(UTC)
Posts: 27
Location: Germany

Thanks: 6 times
Was thanked: 4 time(s) in 4 post(s)
Hi Remco,

An System.OutOfMemoryException exception occurs while executing the following test in churn mode from VS:

Ncrunch Version: 4.15.0.4
Build process CPU architecture: x64
Use CPU architecture: AutoDetect
Engine hosting strategy: x64SatelliteProcess
Solution Configuration: Release
Solution Platform: x86


Stacktrace:
Code:

System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   at System.Activator.CreateInstance(Type type, Object[] args)
   at nCrunch.Module.NUnit3.Integration.FrameworkController.RunTests(INUnit3CallbackHandler handler, String filter)
   at nCrunch.Module.NUnit3.Integration.NUnit3FrameworkInteractor.<>c__DisplayClass11_1.<RunTests>b__3()
   at nCrunch.Common.PerformanceTracking.PerfTracker.TrackUnreliableActivity(String name, Action activity)
   at nCrunch.Common.PerformanceTracking.PerfTracker.TryTrackUnreliableActivity(String name, Action activity)
   at nCrunch.Module.NUnit3.Integration.NUnit3FrameworkInteractor.<>c__DisplayClass11_0.<RunTests>b__1()
   at nCrunch.TestExecution.TimeoutEnforcement.AbortingTimeoutEnforcer.ExecuteWithPossibleEnforcement(Action codeToExecute)
   at nCrunch.TestExecution.TimeoutEnforcement.AbortingWithTerminationFallbackTimeoutEnforcer..()
   at nCrunch.TestExecution.TimeoutEnforcement.TerminatingTimeoutEnforcer.ExecuteWithPossibleEnforcement(Action codeToExecute)
   at nCrunch.TestExecution.TimeoutEnforcement.AbortingWithTerminationFallbackTimeoutEnforcer.ExecuteWithPossibleEnforcement(Action codeToExecute)
   at nCrunch.TestExecution.TestExecutionMonitor.PerformMonitoredTestExecution(Action testExecutionAction)
   at nCrunch.Module.NUnit3.Integration.NUnit3FrameworkInteractor.RunTests(TestEnvironmentConfig environmentConfig, TestTaskOutput output, TestExecutionMapSet testMapSet, TestExecutionParameters parameters, Int32 defaultTimeout, IIpcMessageProcessor ipcMessageProcessor)
   at nCrunch.Module.NUnit3.Integration.NUnit3FrameworkRuntimeEnvironment.RunTests(TestTaskOutput output, TestExecutionMapSet testMapSet, TestExecutionParameters parameters, IIpcMessageProcessor ipcMessageProcessor)
   at nCrunch.TestExecution.TestRunnerThread.()


Unit:
Code:

using System;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;

namespace My.Extensions
{
    public static class TaskExtensions
    {
        public static async Task<T> AwaitWithTimeout<T>(this Task<T> task, int timeout, Action error)
        {
            if (await Task.WhenAny(task, Task.Delay(timeout)).ConfigureAwait(false) == task)
            {
                return await task.ConfigureAwait(false);
            }

            error();
            return  default(T);
    }
}



Test:
Code:

using System;
using System.Threading.Tasks;
using FluentAssertions;
using NUnit.Framework;
using My.Extensions;

namespace My.Test
{
    [TestFixture]
    public class TaskExtensionsTest
    {
        [TestCase(50, 500, false, 1)]
        public async Task Task_Should_Terminate_If_Timeout_Is_Expired_Async(int time, int timeout, bool shouldExpired, int shouldValue)
        {
            var timeStart = HighResolutionTimer.Now();
            var t = CreateResultWithDelayAsync(time, 1);
            var value =  await t.AwaitWithTimeout(timeout, () => { }).ConfigureAwait(false);
            TestContext.WriteLine($"Duration = {new TimeSpan(HighResolutionTimer.Now() - timeStart)}");
            value.Should().Be(shouldValue);
        }

        private async Task<int> CreateResultWithDelayAsync(int delay, int result)
        {
            await Task.Delay(delay);
            return result;
        }
    }


Remco
#2 Posted : Tuesday, April 4, 2023 11:33:37 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,987

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Hi, thanks for sharing this issue.

Do you still experience this problem when running the test with the 'Test Process Memory Limit' NCrunch config setting set to something sensible? My guess here would be that accumulated memory in the process is pushing it past the x86 2GB memory limit. Setting the test to run under x64 might give you more space, but a memory limit would be a more sensible option.
1 user thanked Remco for this useful post.
spolonski on 4/5/2023(UTC)
spolonski
#5 Posted : Wednesday, April 5, 2023 6:30:34 AM(UTC)
Rank: Member

Groups: Registered
Joined: 7/11/2016(UTC)
Posts: 27
Location: Germany

Thanks: 6 times
Was thanked: 4 time(s) in 4 post(s)
Remco;16580 wrote:
Hi, thanks for sharing this issue.

Do you still experience this problem when running the test with the 'Test Process Memory Limit' NCrunch config setting set to something sensible? My guess here would be that accumulated memory in the process is pushing it past the x86 2GB memory limit. Setting the test to run under x64 might give you more space, but a memory limit would be a more sensible option.


Thanks. It was just what the doctor ordered. IMHO It should be set in default to something like 500MB.
PS: I set it to 130MB.
1 user thanked spolonski for this useful post.
Remco on 4/5/2023(UTC)
spolonski
#3 Posted : Wednesday, April 5, 2023 6:36:54 AM(UTC)
Rank: Member

Groups: Registered
Joined: 7/11/2016(UTC)
Posts: 27
Location: Germany

Thanks: 6 times
Was thanked: 4 time(s) in 4 post(s)
Remco;16580 wrote:
My guess here would be that accumulated memory in the process is pushing it past the x86 2GB memory limit.


Actually memory limit in x86 for .Net is about 600MB- 700MB :(
Remco
#4 Posted : Wednesday, April 5, 2023 11:27:06 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,987

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
spolonski;16583 wrote:

Actually memory limit in x86 for .Net is about 600MB- 700MB :(


Usually it's a 2GB heap minus fragmentation in the process. If you have code allocating large objects with high frequency, this causes more fragmentation. Older versions of .NET are worse. If you're getting OOM at 700MB, this suggests some serious fragmentation. Setting your test projects to run under x64 might not be a terrible idea (assuming your machine has sufficient memory).
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.036 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download