LightningChart in HeadlessMode in NUnit

Found a possible bug in LightningChart? Report it here.

Moderator: Queue Moderators

Post Reply
ezray3
Posts: 9
Joined: Sun Nov 11, 2018 9:41 am

LightningChart in HeadlessMode in NUnit

Post by ezray3 » Mon Mar 04, 2019 9:12 am

Hi,

We use LightningChart Headless mode in a module that produces a PDF report that contains charts.
We wanted to write unit tests to that module (to test general requirements like file name, path etc...)
We have an issue with the test, so to figure out what is the problem I wrote a simple test that reproduces the issue:

Code: Select all

using Arction.Wpf.Charting;
.
.
.
        [Test]
        public void Test()
        {
            Thread thread = new Thread(() =>
            {
                var lcu = new LightningChartUltimate();
                lcu.ChartRenderOptions.HeadlessMode = true; // When this line is commented out, the issue is NOT reproduced
            });
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();
        }
The issue is this: when we run the test it's passing. but after the test passes we get an error from NUnit:
2019.03.04 11:00:08.956 ERROR NUnit.Engine.NUnitEngineException: Exception encountered unloading AppDomain
NUnit.Engine.NUnitEngineException: Exception encountered unloading AppDomain ---> System.CannotUnloadAppDomainException: Error while unloading appdomain. (Exception from HRESULT: 0x80131015)
at System.AppDomain.Unload(AppDomain domain)
at NUnit.Engine.Services.DomainManager.DomainUnloader.UnloadOnThread()
--- End of inner exception stack trace ---
at NUnit.Engine.Services.DomainManager.DomainUnloader.Unload()
at NUnit.Engine.Runners.TestDomainRunner.UnloadPackage()
at NUnit.Engine.Runners.AbstractTestRunner.Dispose(Boolean disposing)
at NUnit.Engine.Runners.AbstractTestRunner.Dispose()
at NUnit.Engine.Runners.MasterTestRunner.Dispose(Boolean disposing)
at NUnit.Engine.Runners.MasterTestRunner.Dispose()
at JetBrains.ReSharper.UnitTestRunner.nUnit30.BuiltInNUnitRunner.<>c__DisplayClass6_0.<RunTests>b__0()
at JetBrains.ReSharper.UnitTestRunner.nUnit30.BuiltInNUnitRunner.WithExtensiveErrorHandling(IRemoteTaskServer server, Action action)
I tried to investigate it, and instead of running the test from Resharper, I ran it from nunit-console command line utility:

Code: Select all

"C:\Program Files (x86)\NUnit.org\nunit-console\nunit3-console.exe" --noresult --labels=All Test.dll
The result is this:
Test Run Summary
Overall result: Passed
Test Count: 1, Passed: 1, Failed: 0, Warnings: 0, Inconclusive: 0, Skipped: 0
Start time: 2019-03-04 09:07:41Z
End time: 2019-03-04 09:07:53Z
Duration: 0.716 seconds

NUnit.Engine.NUnitEngineUnloadException : Agent Process was terminated successfully after error.
----> NUnit.Engine.NUnitEngineUnloadException : Exception encountered unloading application domain
----> NUnit.Engine.NUnitEngineException : Exception encountered unloading application domain: Error while unloading appdomain. (Exception from HRESULT: 0x80131015)
Application domain name: domain-
I used windbg and catched TaskCanceledException when domain is unloading.

Thanks,
Yitzchak

ArctionKestutis
Posts: 552
Joined: Mon Mar 14, 2016 9:22 am

Re: LightningChart in HeadlessMode in NUnit

Post by ArctionKestutis » Tue Mar 05, 2019 1:33 pm

Thank you for all the details.

We believe that you are missing Chart disposal. The 'fix' is to dispose chart before unit test is finished.

Code: Select all

            Thread thread = new Thread(() =>
            {
                var lcu = new LightningChartUltimate();
                lcu.ChartRenderOptions.HeadlessMode = true; // When this line is commented out, the issue is NOT reproduced
                lcu.Dispose();
            });
Although Visual Studio's Unit test framework did not show similar problem, it is recommended to dispose chart after each unit test.

Hope this helps.

ezray3
Posts: 9
Joined: Sun Nov 11, 2018 9:41 am

Re: LightningChart in HeadlessMode in NUnit

Post by ezray3 » Tue Mar 05, 2019 6:58 pm

I forgot to mention, I already tried to dispose the chart, this wasn't helpful.
(In our real code we also disposing the chart)

Can you reproduce the issue and investigate it?
Should I contact support instead of this forum?

Thanks,
Yitzchak

ArctionKestutis
Posts: 552
Joined: Mon Mar 14, 2016 9:22 am

Re: LightningChart in HeadlessMode in NUnit

Post by ArctionKestutis » Wed Mar 06, 2019 7:52 am

Hi Yitzchak,

I am handling both support and forum :)
Of course, the support emails have higher priority as I am more aware about subscription status.

We reproduced the issue with NUnit, but not with default Visual Studio's Unit test. Based on provided information about Exception (encountered unloading AppDomain), we believe that undisposed chart was the problem. We verified that with NUnit test. That is, the piece of code you provided did not raise the exception after inclusion of lcu.Dispose() call.
If this did not fixed for you, then it may be good idea to send complete Unit test to support email.

All the best.

ezray3
Posts: 9
Joined: Sun Nov 11, 2018 9:41 am

Re: LightningChart in HeadlessMode in NUnit

Post by ezray3 » Thu Mar 07, 2019 8:59 am

Thanks,

I sent you a mail

ArctionKestutis
Posts: 552
Joined: Mon Mar 14, 2016 9:22 am

Re: LightningChart in HeadlessMode in NUnit

Post by ArctionKestutis » Thu Mar 07, 2019 10:26 am

Thank you for all the details.
Previously we didn’t use the Console Runner. We ran the test with NUnit directly in Visual Studio as instructed here.
We have been able to replicate the exception with NUnit Console Runner 3.8.0. However, it seems that the exception is not related to LightningChart, but NUnit itself. There are several discussions in GitHub regarding this unloading issue, and the changelogs of the Nunit console runner state it as well. The problem is at least partially fixed in the newest version of console runner (3.9). The exception message didn’t show up with the 3.9 version and with lcu.Dispose(), but it did show without lcu.Dispose().
In other words:
- Update to the newest Nunit console runner (3.9);
- Make sure that lcu.Dispose() is included, rebuild test and run the test via the Console Runner.

Hope this helps.

Post Reply