Deadlock issue with Listeners RRS feed

  • Question

  • User114561 posted


    I am trying to implement code to support authentication using an external library. The authentication result is returned asynchronously using a Java listener. Using JNI, I pass an interface implementing IAuthResultHandler that exposes OnAuthenticated and OnAuthenticationError.

    So, basically, when I call the authentication method, I pass the handler. The OnAuthenticated gets called asynchronously when the result is known.

    My problem: the call to OnAuthenticated is done on the main thread instead of the thread where the object was created. A Java programmer told me this was the norm in Java. I was trying to await the call to the callback, but the tests in NUnitLite are also executed on the main thread, which causes a deadlock.

    Any idea how I could get around this?

    Thank you!

    Monday, May 25, 2015 3:11 PM

All replies

  • User3188 posted

    Has soon has you have to test something on the ui thread using thread, NUnitLite will block. We had to switch to xunit to test code with thread. https://github.com/xunit/devices.xunit

    Monday, May 25, 2015 3:53 PM
  • User112 posted

    Well, I wouldn't use unit testing for that in first place. Instead you should mock all external services. Besides does NUnitLite support asynchronous testing? NUnit does.

    Monday, May 25, 2015 7:18 PM
  • User114561 posted

    Thank you for your comments! I will try XUnit

    @MihaMarkic: Good point. Except I am developping the wrapper for the external service... This is not my app. To put this in context, I did a Java bindings project for Firebase API which is only available in Java, not in C#. I want to make sure that all the calls are working and that the inner logic that converts from Java to C# data types is working and vice-versa. I will mock the calls to the API in the app. So I need NUnitLite because of the Java dependencies... Nunit fails when I have anything related to java.

    Monday, May 25, 2015 7:56 PM