Skip to content

Commit 37fe279

Browse files
committed
Fixed too strict test assumptions in SearchLeakTest
The SearchLeakTest starts search, opens an editor and expects it is **exactly** `TextEditor.class`. Now after changes in eclipse-platform/eclipse.platform.ui#2881 it finds `ExtensionBasedTextEditor` class, which is a subclass of `TextEditor`, but test logic doesn't like that. Fixed test expectation and allow opened editor be a subclass of `TextEditor`. Fixes eclipse-jdt#2132
1 parent 8859f2a commit 37fe279

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

org.eclipse.jdt.ui.tests/leaks/org/eclipse/jdt/ui/leaktest/LeakTestCase.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ public boolean visit(ReferencedObject object, Class<?> clazz, boolean firstVisit
5353
}
5454

5555
private InstancesOfTypeCollector collect(String requestedTypeName) {
56-
InstancesOfTypeCollector requestor= new InstancesOfTypeCollector(requestedTypeName, false);
56+
return collect(requestedTypeName, false);
57+
}
58+
59+
private InstancesOfTypeCollector collect(String requestedTypeName, boolean includeSubtypes) {
60+
InstancesOfTypeCollector requestor= new InstancesOfTypeCollector(requestedTypeName, includeSubtypes);
5761
calmDown();
5862
new ReferenceTracker(requestor).start(getClass().getClassLoader());
5963
return requestor;
@@ -130,6 +134,26 @@ public void assertInstanceCount(final Class<?> clazz, final int expected) {
130134
}
131135
}
132136

137+
/**
138+
* Asserts that the instance count of the given class is as expected.
139+
*
140+
* @param clazz the class of the instances to count
141+
* @param includeSubtypes true to include subtypes
142+
* @param expected the expected instance count
143+
*/
144+
public void assertInstanceCount(final Class<?> clazz, boolean includeSubtypes, final int expected) {
145+
int numTries= 2;
146+
while (true) {
147+
InstancesOfTypeCollector requestor= collect(clazz.getName(), includeSubtypes);
148+
int actual= requestor.getNumberOfResults();
149+
if (expected == actual) {
150+
return;
151+
}
152+
numTries--;
153+
assertNotEquals("Expected instance count: " + expected + ", actual: " + actual + "\n" + requestor.getResultString(), 0, numTries);
154+
}
155+
}
156+
133157

134158
/**
135159
* Asserts that the instance count of the given class is as expected.

org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/SearchLeakTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void testRemoveAllQueries() throws Exception {
7070

7171
@Test
7272
public void testSearchResultEditorClose() throws Exception {
73-
assertInstanceCount(TextEditor.class, 0);
73+
assertInstanceCount(TextEditor.class, true, 0);
7474

7575
FileTextSearchScope scope= FileTextSearchScope.newWorkspaceScope(null, false);
7676
FileSearchQuery query= new FileSearchQuery("projectDescription", false, false, scope);
@@ -81,11 +81,11 @@ public void testSearchResultEditorClose() throws Exception {
8181
DisplayHelper.sleep(Display.getDefault(), 2000);
8282
page.gotoNextMatch();
8383

84-
assertInstanceCount(TextEditor.class, 1);
84+
assertInstanceCount(TextEditor.class, true, 1);
8585

8686
assertTrue(JavaPlugin.getActivePage().closeAllEditors(false));
8787

88-
assertInstanceCount(TextEditor.class, 0);
88+
assertInstanceCount(TextEditor.class, true, 0);
8989

9090
NewSearchUI.removeQuery(query);
9191
}

0 commit comments

Comments
 (0)