Skip to content

Commit f99cfcf

Browse files
committed
Don't update hidden consoles every second
- Added new API to allow console pages knew whether they are visible or not. - Use new IConsole API to schedule console updates only if console page is visible (top level) in the console view. This prevents multiple opened consoles in same console view run update tasks every second, even if no one can see the updated console name. - Added tests Fixes #2478
1 parent bfcc200 commit f99cfcf

15 files changed

Lines changed: 790 additions & 136 deletions

File tree

debug/org.eclipse.debug.tests/META-INF/MANIFEST.MF

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-SymbolicName: org.eclipse.debug.tests;singleton:=true
5-
Bundle-Version: 3.15.300.qualifier
5+
Bundle-Version: 3.15.400.qualifier
66
Bundle-Localization: plugin
7-
Require-Bundle: org.eclipse.ui;bundle-version="[3.6.0,4.0.0)",
8-
org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)",
9-
org.eclipse.debug.ui;bundle-version="[3.10.0,4.0.0)",
10-
org.eclipse.core.filesystem;bundle-version="[1.3.0,2.0.0)",
11-
org.eclipse.test.performance;bundle-version="3.6.0",
12-
org.eclipse.ui.externaltools;bundle-version="[3.3.0,4.0.0)",
13-
org.eclipse.ui.console;bundle-version="[3.7.0,4.0.0)",
14-
org.eclipse.jface.text;bundle-version="[3.5.0,4.0.0)",
15-
org.eclipse.ui.workbench.texteditor;bundle-version="[3.15.100,4.0.0)"
7+
Require-Bundle: org.eclipse.ui;bundle-version="[3.208.0,4.0.0)",
8+
org.eclipse.core.runtime;bundle-version="[3.34.0,4.0.0)",
9+
org.eclipse.debug.ui;bundle-version="[3.21.0,4.0.0)",
10+
org.eclipse.core.filesystem;bundle-version="[1.11.0,2.0.0)",
11+
org.eclipse.test.performance;bundle-version="[3.21.0,4.0.0)",
12+
org.eclipse.ui.externaltools;bundle-version="[3.7.0,4.0.0)",
13+
org.eclipse.ui.console;bundle-version="[3.17.0,4.0.0)",
14+
org.eclipse.jface.text;bundle-version="[3.30.0,4.0.0)",
15+
org.eclipse.ui.workbench.texteditor;bundle-version="[3.20.0,4.0.0)"
1616
Bundle-ActivationPolicy: lazy
1717
Bundle-RequiredExecutionEnvironment: JavaSE-21
1818
Bundle-Vendor: %providerName

debug/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.eclipse.debug.tests.breakpoint.BreakpointTests;
2020
import org.eclipse.debug.tests.breakpoint.SerialExecutorTest;
2121
import org.eclipse.debug.tests.console.ConsoleDocumentAdapterTests;
22+
import org.eclipse.debug.tests.console.ConsoleShowHideTests;
2223
import org.eclipse.debug.tests.console.ConsoleManagerTests;
2324
import org.eclipse.debug.tests.console.ConsoleTests;
2425
import org.eclipse.debug.tests.console.FileLinkTests;
@@ -117,6 +118,7 @@
117118

118119
// Console view
119120
ConsoleDocumentAdapterTests.class, //
121+
ConsoleShowHideTests.class, //
120122
ConsoleManagerTests.class, //
121123
ConsoleTests.class, //
122124
IOConsoleTests.class, //

debug/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ConsoleManagerTests.java

Lines changed: 8 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016, 2017 Andrey Loskutov and others.
2+
* Copyright (c) 2026 Andrey Loskutov and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -21,33 +21,26 @@
2121
import java.util.concurrent.ExecutorService;
2222
import java.util.concurrent.Executors;
2323
import java.util.concurrent.TimeUnit;
24-
import java.util.concurrent.atomic.AtomicInteger;
2524

2625
import org.eclipse.debug.tests.DebugTestExtension;
2726
import org.eclipse.debug.tests.TestUtil;
28-
import org.eclipse.jface.resource.ImageDescriptor;
29-
import org.eclipse.jface.util.IPropertyChangeListener;
30-
import org.eclipse.swt.SWT;
31-
import org.eclipse.swt.widgets.Composite;
3227
import org.eclipse.swt.widgets.Display;
3328
import org.eclipse.ui.IViewPart;
3429
import org.eclipse.ui.IWorkbenchPage;
3530
import org.eclipse.ui.PlatformUI;
3631
import org.eclipse.ui.console.ConsolePlugin;
3732
import org.eclipse.ui.console.IConsole;
3833
import org.eclipse.ui.console.IConsoleManager;
39-
import org.eclipse.ui.console.IConsoleView;
4034
import org.eclipse.ui.internal.console.ConsoleManager;
41-
import org.eclipse.ui.part.IPageBookViewPage;
42-
import org.eclipse.ui.part.MessagePage;
4335
import org.junit.jupiter.api.AfterEach;
4436
import org.junit.jupiter.api.BeforeEach;
4537
import org.junit.jupiter.api.Test;
4638
import org.junit.jupiter.api.TestInfo;
4739
import org.junit.jupiter.api.extension.ExtendWith;
4840

4941
/**
50-
* Tests console manager
42+
* Tests console manager behavior when multiple consoles are shown at the same
43+
* time.
5144
*/
5245
@ExtendWith(DebugTestExtension.class)
5346
public class ConsoleManagerTests {
@@ -58,6 +51,8 @@ public class ConsoleManagerTests {
5851
private CountDownLatch latch;
5952
private ConsoleMock[] consoles;
6053
ConsoleMock firstConsole;
54+
private IViewPart consoleView;
55+
private IWorkbenchPage activePage;
6156

6257
@BeforeEach
6358
public void setUp(TestInfo testInfo) throws Exception {
@@ -66,7 +61,7 @@ public void setUp(TestInfo testInfo) throws Exception {
6661
latch = new CountDownLatch(count);
6762
executorService = Executors.newFixedThreadPool(count);
6863
manager = ConsolePlugin.getDefault().getConsoleManager();
69-
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
64+
activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
7065
TestUtil.processUIEvents(100);
7166
consoles = new ConsoleMock[count];
7267
for (int i = 0; i < count; i++) {
@@ -76,7 +71,7 @@ public void setUp(TestInfo testInfo) throws Exception {
7671
// register consoles (this does *not* show anything)
7772
manager.addConsoles(consoles);
7873

79-
IViewPart consoleView = activePage.showView("org.eclipse.ui.console.ConsoleView"); //$NON-NLS-1$
74+
consoleView = activePage.showView("org.eclipse.ui.console.ConsoleView");
8075
activePage.activate(consoleView);
8176
TestUtil.processUIEvents(100);
8277

@@ -96,6 +91,7 @@ public void tearDown() throws Exception {
9691
executorService.shutdownNow();
9792
manager.removeConsoles(consoles);
9893
manager.removeConsoles(new ConsoleMock[] { firstConsole });
94+
activePage.hideView(consoleView);
9995
TestUtil.processUIEvents(100);
10096
}
10197

@@ -168,73 +164,4 @@ private void showConsole(final ConsoleMock console, String testName) {
168164
});
169165
}
170166

171-
/**
172-
* Dummy console page showing mock number and counting the numbers its
173-
* control was shown in the console view.
174-
*/
175-
static final class ConsoleMock implements IConsole {
176-
MessagePage page;
177-
final AtomicInteger showCalled;
178-
final int number;
179-
final static AtomicInteger allShownConsoles = new AtomicInteger();
180-
181-
public ConsoleMock(int number) {
182-
this.number = number;
183-
showCalled = new AtomicInteger();
184-
}
185-
186-
@Override
187-
public void removePropertyChangeListener(IPropertyChangeListener listener) {
188-
}
189-
190-
@Override
191-
public String getType() {
192-
return null;
193-
}
194-
195-
@Override
196-
public String getName() {
197-
return toString();
198-
}
199-
200-
@Override
201-
public ImageDescriptor getImageDescriptor() {
202-
return null;
203-
}
204-
205-
@Override
206-
public void addPropertyChangeListener(IPropertyChangeListener listener) {
207-
}
208-
209-
/**
210-
* Just a page showing the mock console name
211-
*/
212-
@Override
213-
public IPageBookViewPage createPage(IConsoleView view) {
214-
page = new MessagePage() {
215-
@Override
216-
public void createControl(Composite parent) {
217-
super.createControl(parent);
218-
// This listener is get called if the page is really shown
219-
// in the console view
220-
getControl().addListener(SWT.Show, event -> {
221-
int count = showCalled.incrementAndGet();
222-
if (count == 1) {
223-
count = allShownConsoles.incrementAndGet();
224-
System.out.println("Shown: " + ConsoleMock.this + ", overall: " + count); //$NON-NLS-1$ //$NON-NLS-2$
225-
}
226-
});
227-
}
228-
229-
};
230-
page.setMessage(toString());
231-
return page;
232-
}
233-
234-
@Override
235-
public String toString() {
236-
return "mock #" + number; //$NON-NLS-1$
237-
}
238-
}
239-
240167
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 Andrey Loskutov and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Andrey Loskutov <loskutov@gmx.de> - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.debug.tests.console;
15+
16+
import java.util.concurrent.atomic.AtomicInteger;
17+
18+
import org.eclipse.jface.resource.ImageDescriptor;
19+
import org.eclipse.jface.util.IPropertyChangeListener;
20+
import org.eclipse.swt.SWT;
21+
import org.eclipse.swt.widgets.Composite;
22+
import org.eclipse.ui.console.IConsole;
23+
import org.eclipse.ui.console.IConsoleView;
24+
import org.eclipse.ui.part.IPageBookViewPage;
25+
import org.eclipse.ui.part.MessagePage;
26+
27+
/**
28+
* Dummy console page showing mock number and counting the numbers its
29+
* control was shown in the console view.
30+
*/
31+
final class ConsoleMock implements IConsole {
32+
MessagePage page;
33+
final AtomicInteger showCalled;
34+
final AtomicInteger pageShownCalled;
35+
final AtomicInteger pageHiddenCalled;
36+
final int number;
37+
final static AtomicInteger allShownConsoles = new AtomicInteger();
38+
39+
public ConsoleMock(int number) {
40+
this.number = number;
41+
showCalled = new AtomicInteger();
42+
pageShownCalled = new AtomicInteger();
43+
pageHiddenCalled = new AtomicInteger();
44+
}
45+
46+
@Override
47+
public void pageShown() {
48+
pageShownCalled.incrementAndGet();
49+
}
50+
51+
@Override
52+
public void pageHidden() {
53+
pageHiddenCalled.incrementAndGet();
54+
}
55+
56+
@Override
57+
public void removePropertyChangeListener(IPropertyChangeListener listener) {
58+
}
59+
60+
@Override
61+
public String getType() {
62+
return null;
63+
}
64+
65+
@Override
66+
public String getName() {
67+
return toString();
68+
}
69+
70+
@Override
71+
public ImageDescriptor getImageDescriptor() {
72+
return null;
73+
}
74+
75+
@Override
76+
public void addPropertyChangeListener(IPropertyChangeListener listener) {
77+
}
78+
79+
/**
80+
* Just a page showing the mock console name
81+
*/
82+
@Override
83+
public IPageBookViewPage createPage(IConsoleView view) {
84+
page = new MessagePage() {
85+
@Override
86+
public void createControl(Composite parent) {
87+
super.createControl(parent);
88+
// This listener is get called if the page is really shown
89+
// in the console view
90+
getControl().addListener(SWT.Show, event -> {
91+
int count = showCalled.incrementAndGet();
92+
if (count == 1) {
93+
count = allShownConsoles.incrementAndGet();
94+
System.out.println("Shown: " + ConsoleMock.this + ", overall: " + count); //$NON-NLS-1$ //$NON-NLS-2$
95+
}
96+
});
97+
}
98+
99+
};
100+
page.setMessage(toString());
101+
return page;
102+
}
103+
104+
@Override
105+
public String toString() {
106+
return "mock #" + number; //$NON-NLS-1$
107+
}
108+
}

0 commit comments

Comments
 (0)