Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.ArgumentException occurs on StateMachine.NET.UnitTest #8

Closed
cozzyy2002 opened this issue Dec 8, 2019 · 3 comments
Closed

System.ArgumentException occurs on StateMachine.NET.UnitTest #8

cozzyy2002 opened this issue Dec 8, 2019 · 3 comments

Comments

@cozzyy2002
Copy link
Owner

cozzyy2002 commented Dec 8, 2019

Describe the bug
System.ArgumentException occurs when StateMachine.NET.UnitTest runs.

[2019/12/07 23:09:44 Informational] ------ Run test started ------
[2019/12/07 23:09:45 Informational] NUnit Adapter 3.15.1.0: Test execution started
[2019/12/07 23:09:45 Informational] Running selected tests in C:\Users\cozzy\source\repos\tsm\StateMachine.NET.UnitTest\bin\Debug\StateMachine.NET.UnitTest.dll
[2019/12/07 23:09:45 Informational]    NUnit3TestExecutor converted 1 of 1 NUnit test cases
[2019/12/07 23:09:53 Error] アクティブなテストの実行が中止されました。理由: ハンドルされていない例外: System.ArgumentException: AppDomain 間で GCHandle を渡すことはできません。
パラメーター名:handle
   場所 System.Runtime.InteropServices.GCHandle.InternalCheckDomain(IntPtr handle)
   場所 System.Runtime.InteropServices.GCHandle.FromIntPtr(IntPtr value)
   場所 System.Runtime.InteropServices.GCHandle.op_Explicit(IntPtr value)
   場所 gcroot<tsm_NET::State::ExitDelegate ^>.{dtor}(gcroot<tsm_NET::State::ExitDelegate ^>* ) 場所 c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\msclr\gcroot.h:行 89
   場所 native.Callback<tsm_NET::State::ExitDelegate,long (__stdcall*)(tsm::IContext *,tsm::IEvent *,tsm::IState *)>.{dtor}(Callback<tsm_NET::State::ExitDelegate\,long (__stdcall\*)(tsm::IContext \*\,tsm::IEvent \*\,tsm::IState \*)>* )
   場所 native.State.{dtor}(State* )
   場所 native.State.__vecDelDtor(State* , UInt32 A_0)

[2019/12/07 23:09:53 Informational] ========== Run test finished: 0 run (0:00:09.210603) ==========
[2019/12/07 23:16:10 Informational] ------ Discover test started ------
[2019/12/07 23:16:11 Informational] ========== Discover test finished: 0 found (0:00:00.6042904) ==========

To Reproduce
Steps to reproduce the behavior:

  1. Check-out branch feature-memory-check
  2. Comment out the code that calls AddRef/Release methods of tsm_NET::State and tsm_NET::Event.
    • These codes are intended to release memories when the objects becomes not referenced.
    • But Adding reference count of State/Event object causes mutual reference of Managed object and Native object.
    • Then uncommenting out the code leads:
      • Unit test succeeds.
      • Though State/Event object is NOT released.
  3. Build project StateMachine.NET.UnitTest.
  4. Run a test case.

Expected behavior
No exception occurs and Test succeeds.

Desktop (please complete the following information):

  • OS: Windows 10 Pro version 1909

Additional context

@cozzyy2002
Copy link
Owner Author

cozzyy2002 commented Jan 5, 2020

I've found a way to run unit test using nunit3-console.exe as follows.
But when unit test runs on test explorer of Visual Studio, the exception occurs.

The exception occurs when native State(or Event) deletes managed object associated with it.

  • Native object runs on default AppDomain.
  • Managed object runs on secondary AppDomain.

To avoid above situation, unit test should run on a single AppDomain.

NUnit console runner accepts command line option --domain=None.
See Console Command Line - nunit / docs.
As of nunit3, test assembly and all nunit assemblies should be in the same directory for --domain=None option to work.
See nunit/nunit#1741

To run unit test in debug mode:

  • Append command line option --pause.
  • Attach to unit test process after executing nunit console.

@cozzyy2002
Copy link
Owner Author

Now working on branch bugfix-0008-dispatch-on-managed-thread so that unit test can run on test explorer of Visual Studio.

cozzyy2002 added a commit that referenced this issue Jan 11, 2020
…d-thread

Bugfix #8 dispatch on managed thread
@cozzyy2002
Copy link
Owner Author

Fixed by PR #10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant