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

Notification

Icon
Error

NCrunch seem to keep an outdated cache after git branch switch
JulienN
#1 Posted : Tuesday, February 28, 2023 3:28:53 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 2/28/2023(UTC)
Posts: 2
Location: France

As I'm working on several topics in parallel, and reviewing a lot of Pull requests, I'm switching between branches a lot.

The issue is that very often, when I switch branch, NCrunch displays a lot of build errors, and rebuilding projects keep displaying the same errors.
Even when the Visual Studio (2022, v17.5, but all previous version did the same) builds properly the solution.

Usually, caused by some method or property not defined, and as soon as you open the file that defines that property or method, the error disappears.
I guess this is caused by some kind of cache on NCrunch side, that refreshes when you open the file.
Another "quick" way to fix the build is to restart the engine.

The issue is that I cannot trust NCrunch when I switch branch, because I also had the issue in the other direction : running tests on outdated code, and not detecting issues.
So I need to restart the engine everytime I switch branch, which is time consuming and error prone.
This is really annoying, and slows the adoption in our company, as this is the main complain I see.
This is not a new issue, I feel that I had it since day one (~18 months ago).

So please, make sure that the code used when building / running tests after a git checkout is always up-to-date (I'm using the VS to switch branch, if that matters).

Note that I'm always using the latest versions of everything (VS, NCrunch, nugets), the project is a solution with 30 projects (half Web API + libs, other half are test projects) in .NET 7 (we also had the issue when it was in .NET 6).
Remco
#2 Posted : Tuesday, February 28, 2023 11:21:11 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 918 times
Was thanked: 1241 time(s) in 1157 post(s)
Hi, thanks for sharing this issue.

The short answer to this is that we actually can't reliably support large branch switches without a reset of the NCrunch engine.

The long answer is that after trying to tackle this particular problem for the better part of 14 years, we haven't found a way to make it work correctly with newer versions of Visual Studio as the platform simply isn't designed with this sort of thing in mind. Presently we have 4 different synchronisation systems all working in parallel to try and keep NCrunch updated with the in-memory state of the codebase in VS. We integrate with the automation interfaces, the package interfaces, the CPS project system and the file system. No one of these provides us with all we need, and the handling changes between each version of VS. Since VS2012, the entire project system is multi-threaded and we have a range of crazy workarounds in place to try and allow the engine to align itself through the numerous reliability problems that have been introduced and fixed in different versions of VS over the years. Since VS2017, VS performs a background package-restore on projects when it loads them (but not all the time), the behaviour and timing of which depends on the VS version, and sometimes it actually doesn't work, so VS itself gets confused about the state of the projects .. sometimes to the point where it even crashes. Should the stars ever align and VS has a build that can handle branch switches and we can too, it won't stay that way. The project/dependency system appears to be one of the most complex parts of VS and it also changes all the time. I mention all this not because I expect it's helpful for you, but more because I want you to understand that I'm not just trying to push this issue away: We actually have no feasible way to implement it.

If you need to switch branches regularly, I suggest having two separate checkouts of your codebase on disk, one for each branch. You can then have two IDEs open, one for each branch. This will also alleviate the problem of having a single NCrunch cache file shared between branches, which would result in all your tests needing to be re-run every time you switch branch. I accept that this is a very resource intensive way to work (given the memory footprint of both VS and NCrunch), but it might be a viable way to work if you have the hardware to handle it.
JulienN
#3 Posted : Thursday, March 9, 2023 4:36:18 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 2/28/2023(UTC)
Posts: 2
Location: France

Thanks for this very detailed response.
And having tried to develop some VS extensions, I understand your pain :).

We are using short-lived feature branches so it won't be very practical to have several checkouts.
I'll keep restarting the engine on branch change then !

Thanks again.
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.032 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download