-
Notifications
You must be signed in to change notification settings - Fork 456
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
Test fail when run using Visual Studio 15.7.5 and Resharper 2018.1.3 but not from build.cmd for net45 #421
Comments
An example of a test that fails is: Windsor/src/Castle.Windsor.Tests/Lifecycle/DisposeTestCase.cs Lines 95 to 112 in 81fbdf0
|
Did you have dotMemory and dotTrace installed before this started failing? I've run the tests with them installed before but maybe something has changed with their instrumentation that is causing the short lived objects not to get garbage collected when asked. Could you try some of the suggestions in this StackOverflow thread to see what fixes it: |
@jonorossi You are right. Today I started profiling some integration tests on another project and file locks were kicking in and failing tests. I will re-post this on the JB issue tracker. |
@fir3pho3nixx I'm afraid it doesn't. Maybe related to some setting (in VS or R#), or installed components? I have the exact same versions in any case. |
Are you opening the solution with elevated privileges? Which tests are failing for you? |
I am. My Visual Studio is set to always run as Administrator. Now that I mention it: I am on 2017 Professional whereas you are using Community.
13 tests, so assuming the same ones as did for you earlier. |
Have you taken the latest updates from Visual Studio? Quite a few got barreled out over the past few days. |
@mario-d-s can you please try with the latest VS/RS updates and tell me if anything changes? I have not seen any problems. |
Marking this as abandoned. I don't have this issue at work or on BYOD. |
Reproing on VS 15.8.7 and ReSharper 2018.2.3 which are current as of today. In every case, the problem is that the In particular, this trivial test (which follows the same pattern that the real tests depend on) fails when run via ReSharper: [Test]
public void SimpleRepro()
{
var weak = new WeakReference(new object());
GC.Collect();
Assert.IsFalse(weak.IsAlive);
} Therefore, all the real tests have some hidden assumptions about the timeframe in which GC will certainly happen. There should probably be a test helper which actually ensures GC. |
Discovered that the problem disappears when the solution configuration is switched to Release. In Debug, this test never completes. In Release, it completes instantly: var weak = new WeakReference(new object());
while (weak.IsAlive)
{
GC.Collect();
} |
ReSharper is behaving as you'd expect for a .NET assembly compiled in debug mode. You'd get the same behavior if the test was a console app. The oddball is VSTest; these tests wouldn't normally pass if the project is compiled in debug mode. ReSharper is making sure its runner is running with JIT/GC optimizations enabled/disabled to match the test assembly instead of always enabled like VSTest. Good explanation in this answer: https://stackoverflow.com/questions/37462378/why-c-sharp-garbage-collection-behavior-differs-for-release-and-debug-executable |
What works is this pattern, never evaluating the expression that returns the tracked instance within the method but rather within a call that returns: [Test]
public void Managed_externally_factory_component_transient_is_not_tracked_by_the_container()
{
Kernel.Register(Component.For<DisposableComponent>()
.LifeStyle.Transient
.UsingFactoryMethod(() => new DisposableComponent(), managedExternally: true));
var weak = GetWeakReferenceForTesting(Kernel.Resolve<DisposableComponent>());
GC.Collect();
Assert.IsFalse(weak.IsAlive);
}
private static WeakReference GetWeakReferenceForTesting(Func<object> getInstanceToTrack)
{
return new WeakReference(getInstanceToTrack.Invoke());
} |
Hey, while refactoring all the WeakReference tests to use a new helper API, I discovered that @ivan-danilov had run into (and documented) this exact same issue on a single test: Windsor/src/Castle.Windsor.Tests/Lifestyle/ScopedLifestyleTestCase.cs Lines 179 to 201 in 07e4b66
See #138 for that pull request. |
This exact issue was also discovered on two other tests by @alinapopa and discussed here: #235 (comment) Windsor/src/Castle.Facilities.WcfIntegration.Tests/Client/WcfClientFixture.cs Lines 268 to 272 in 07e4b66
Windsor/src/Castle.Facilities.WcfIntegration.Tests/Client/WcfClientFixture.cs Lines 351 to 355 in 07e4b66
|
Got all tests passing in ReSharper! #440 |
@jnm2 I remember alinapopa coming across that one now. Great work getting this one sorted. |
When running test inside Visual Studio using Resharper I noticed that 13 tests are failing. However when I run the test from
build.cmd
everything passes. I just updated my Visual Studio and Resharper today and noticed this to be the case.The text was updated successfully, but these errors were encountered: