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

Notification

Icon
Error

Disabling JustMock Integration
Micah71381
#1 Posted : Friday, June 20, 2014 4:14:12 PM(UTC)
Rank: Member

Groups: Registered
Joined: 10/18/2013(UTC)
Posts: 27
Location: United States of America

Was thanked: 2 time(s) in 2 post(s)
Visual Studio 2013
Just Mock 2014.1.1623.1
NCrunch 2.7.0.5

Currently, NCrunch is running with the Just Mock Profiler as seen here: http://snag.gy/04kqj.jpg

The instructions found here (http://www.telerik.com/help/justmock/integration-ncrunch.html) state that in order to have this work I need to setup a "Proxy process file path" in NCrunch. However, I currently do not have that set on any of my NCrunch projects, e.g., http://snag.gy/mPQCc.jpg

I would like to disable the Just Mock Profiler for some of my NCrunch projects but I am not sure how Just Mock Runner is being executed so I don't know what to change to make it stop executing using Just Mock Runner.

I am aware that I can programmatically disable the runner, but I am looking for a configuration based solution that doesn't require code changes to my tests.

I initially posted this over on the Telerik forums and they indicated that they believe NCrunch has built-in support for Just Mock, which is likely the cause of my issue. What I would like is the ability to disable the automatic Just Mock integration and follow the instructions at the above link to manually hook-up Just Mock on a per-project basis.

Here is a link to my post on their forum:
http://www.telerik.com/f...mock-ncrunch-integration
Remco
#2 Posted : Friday, June 20, 2014 10:52:44 PM(UTC)
Rank: NCrunch Developer

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

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

NCrunch does auto-detect JustMock and automatically sets the proxy process file path. The intention of this is to make things easier for people that use JustMock.

However, NCrunch will only load JustMock if it detects a dependency on the JustMock DLL file from the test project. So it will only load the profiler if it's actually needed.

Can you share any details as to why you need to disable the profiler? Is it possible for you to simply remove the reference to the JustMock DLL?
Micah71381
#3 Posted : Saturday, June 21, 2014 4:08:03 AM(UTC)
Rank: Member

Groups: Registered
Joined: 10/18/2013(UTC)
Posts: 27
Location: United States of America

Was thanked: 2 time(s) in 2 post(s)
TL;DR:
* Having a code-injecting profiler attached slows down process cold-start times, even if the profiler doesn't inject any code.
* I want a way to see which tests are still utilizing the Just Mock Profiled Mocking features and which are utilizing the regular mocking features.


The long version:

Just Mock has one set of features that are are accessible without their profiler. It has another set of features that require their profiler attach in order to function. I inherited a code base a couple years ago and began using Just Mock to improve test coverage while I slowly worked through refactoring various parts of my application to be more testable without the need for profiled mocking (dependency injection, loosely coupled eventing system, etc.). I am at the point where I would like to get an idea of how many of my tests still require the profiling features of Just Mock. In order to do that, I need to be able to turn the profiler off temporarily so I can assess the situation.

Also, application cold start times are significantly higher with a code-injecting profiler attached than they are without. This is due to the nature of how the CLR Profiling API works and unfortunately, there is nothing that Telerik or NCrunch can do to resolve it. As an example, an application that normally loads in 1-2 seconds and hits ~15,000 methods (mostly Framework) on my machine takes ~10-12 seconds if a code-injecting profiler is attached. I have other projects I work on that do not require any profiler in order to run yet I still utilize the non-profiling features of Just Mock. I would like NCrunch to be able to execute those test projects faster. Unfortunately, because NCrunch automatically attaches the profiler to any project that utilizes Just Mock (whether it needs the profiled mocking or not), I suffer the performance hit for most of my projects.

I can fully appreciate the desire to have Just Mock work out of the box for users and I am not suggesting that that change, it definitely helped me get NCrunch up and running quickly. However, I would like some way to turn it off on both a temporary basis and on a permanent per-project/solution basis for the two reasons listed above.


Additional information:

For the curious, the reason attaching a code injecting profiler hurts cold start times is because the CLR is unable to utilize the pre-JIT-compiled .NET Framework class libraries. When you install the .NET Framework, it pre-compiles the entire framework to improve cold start times, as well as to provide some other runtime performance benefits (http://msdn.microsoft.com/en-us/magazine/cc163610.aspx). In order for a code-injecting profiler to work, every method has to go through the JIT-compilation process before it can be used, to give the profiler an opportunity to inject the code it wants into methods at runtime. Because of this, the pre-compiled libraries can't be used and while the CLR's JIT-compiler is fast, it still takes time to JIT-compile every method hit in the .NET Framework.
Remco
#4 Posted : Saturday, June 21, 2014 9:23:01 AM(UTC)
Rank: NCrunch Developer

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

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Wow, your post was a gem of useful information about this for probably more reasons that you would have initially thought.

As you likely know, NCrunch works by statically instrumenting assemblies on disk. The instrumentation step is relatively fast, and allows NCrunch to discover tests at the same time (as an added bonus). It does, unfortunately, have a few limitations. To overcome these limitations, I had been looking at experimenting with CLR profiler integration as an alternative way to profile/instrument the runtime code. I hadn't considered the effect this would have on NGENed assemblies, nor was I aware that the performance difference was so large. I don't think I'll be considering this approach now for NCrunch.

I've been thinking about how we can get NCrunch to stop detecting the use of JustMock and to avoid enabling the profiler. I believe there may be an unconventional approach where we can hide the JustMock dependency from the NCrunch engine.

When NCrunch loads your test project, it searches the list of referenced assemblies and identifies whether JustMock.dll or Telerik.JustMock.dll is being referenced. If so, it will automatically set the Proxy Process path by querying the registry at HKEY_LOCAL_MACHINE\SOFTWARE\Telerik\JustMock\BinaryPath.

If you rename the JustMock.dll or Telerik.JustMock.dll (for example, JustMock_.dll or Telerik.JustMock_.dll), NCrunch will not detect the dependency and will not attempt to load the profiler. If you then choose to load the profiler at a later time, you can simply set the Proxy Process path directly in your NCrunch configuration. This should save you from needing to rename referenced assemblies all the time.

I'm keen to hear if this does the trick for you.

Cheers,

Remco
Micah71381
#5 Posted : Monday, June 23, 2014 4:18:01 PM(UTC)
Rank: Member

Groups: Registered
Joined: 10/18/2013(UTC)
Posts: 27
Location: United States of America

Was thanked: 2 time(s) in 2 post(s)
I set the registry key you mentioned (HKEY_LOCAL_MACHINE\SOFTWARE\Telerik\JustMock\BinaryPath) to an empty string but it appears NCrunch was still able to find Just Mock. I'm guessing it has some fallback code to check the default install path if the registry key isn't found (restarted VS after the registry change). I'll try messing around with assembly name changes and possible moving/removing the Just Mock install folder.

As a feature request for a future version, it would be nice if I could turn off automatic integrations like this via NCrunch configuration.
Micah71381
#6 Posted : Monday, June 23, 2014 4:22:18 PM(UTC)
Rank: Member

Groups: Registered
Joined: 10/18/2013(UTC)
Posts: 27
Location: United States of America

Was thanked: 2 time(s) in 2 post(s)
Figured it out, the trick was to set the Wow6432Node version of that key since Visual Studio and NCrunch TaskRunner run as 32-bit processes.

The key can be found at HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Telerik\JustMock\BinaryPath.

I did receive an error from Visual Studio when I launched it complaining about the Just Mock install being bad, but at least now I can temporarily turn off profiled tests only having to restart Visual Studio.
1 user thanked Micah71381 for this useful post.
Remco on 6/23/2014(UTC)
Micah71381
#7 Posted : Friday, October 24, 2014 9:02:23 PM(UTC)
Rank: Member

Groups: Registered
Joined: 10/18/2013(UTC)
Posts: 27
Location: United States of America

Was thanked: 2 time(s) in 2 post(s)
For anyone who removes it and can't remember what to set it back to, this is what it defaults to for me: C:\Program Files (x86)\Telerik\JustMock\Libraries\
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.061 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download