Skip to content

Commit 1be9cc3

Browse files
committed
Release Transient Fakes obtained from CW after using them
1 parent e991c43 commit 1be9cc3

File tree

2 files changed

+42
-35
lines changed

2 files changed

+42
-35
lines changed

Rubberduck.Core/UnitTesting/IFakes.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ public interface IFakes
99
public interface IFakesFactory
1010
{
1111
IFakes GetFakes();
12+
void Release(IFakes fakes);
1213
}
1314
}

Rubberduck.Core/UnitTesting/TestEngine.cs

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -75,51 +75,57 @@ public void Run(IEnumerable<TestMethod> tests)
7575
&& test.Declaration.QualifiedName.QualifiedModuleName.ComponentName == capturedModule.Key.ComponentName);
7676

7777
var fakes = _fakesFactory.GetFakes();
78-
79-
Run(module.Key.FindModuleInitializeMethods(_state));
80-
foreach (var test in moduleTestMethods)
78+
try
8179
{
82-
// no need to run setup/teardown for ignored tests
83-
if (test.Declaration.Annotations.Any(a => a.AnnotationType == AnnotationType.IgnoreTest))
80+
Run(module.Key.FindModuleInitializeMethods(_state));
81+
foreach (var test in moduleTestMethods)
8482
{
85-
test.UpdateResult(TestOutcome.Ignored);
86-
OnTestCompleted();
87-
continue;
88-
}
89-
90-
var stopwatch = new Stopwatch();
91-
stopwatch.Start();
83+
// no need to run setup/teardown for ignored tests
84+
if (test.Declaration.Annotations.Any(a => a.AnnotationType == AnnotationType.IgnoreTest))
85+
{
86+
test.UpdateResult(TestOutcome.Ignored);
87+
OnTestCompleted();
88+
continue;
89+
}
90+
91+
var stopwatch = new Stopwatch();
92+
stopwatch.Start();
93+
94+
try
95+
{
96+
fakes.StartTest();
97+
Run(testInitialize);
98+
test.Run();
99+
Run(testCleanup);
100+
}
101+
catch (COMException ex)
102+
{
103+
Logger.Error(ex, "Unexpected COM exception while running tests.", test.Declaration?.QualifiedName);
104+
test.UpdateResult(TestOutcome.Inconclusive, RubberduckUI.Assert_ComException);
105+
}
106+
finally
107+
{
108+
fakes.StopTest();
109+
}
110+
111+
stopwatch.Stop();
112+
test.Result.SetDuration(stopwatch.ElapsedMilliseconds);
92113

93-
try
94-
{
95-
fakes.StartTest();
96-
Run(testInitialize);
97-
test.Run();
98-
Run(testCleanup);
99-
}
100-
catch (COMException ex)
101-
{
102-
Logger.Error(ex, "Unexpected COM exception while running tests.", test.Declaration?.QualifiedName);
103-
test.UpdateResult(TestOutcome.Inconclusive, RubberduckUI.Assert_ComException);
104-
}
105-
finally
106-
{
107-
fakes.StopTest();
114+
OnTestCompleted();
115+
Model.AddExecutedTest(test);
108116
}
109-
110-
stopwatch.Stop();
111-
test.Result.SetDuration(stopwatch.ElapsedMilliseconds);
112-
113-
OnTestCompleted();
114-
Model.AddExecutedTest(test);
117+
Run(module.Key.FindModuleCleanupMethods(_state));
118+
}
119+
finally
120+
{
121+
_fakesFactory.Release(fakes);
115122
}
116-
Run(module.Key.FindModuleCleanupMethods(_state));
117123
}
118124
}
119125

120126
private void Run(IEnumerable<Declaration> members)
121127
{
122-
var groupedMembers = members.GroupBy(m=> m.ProjectName);
128+
var groupedMembers = members.GroupBy(m => m.ProjectName);
123129
foreach (var group in groupedMembers)
124130
{
125131
using (var project = _vbe.VBProjects[group.Key])

0 commit comments

Comments
 (0)