-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CI] [browser tests] Fix find-replace test suite
That test suite was still experiencing intermittent failures. Playing around with it, I found-out that there were sometimes exceptions thrown when we do not let the language server finish its startup, before we close the editor. The LS would then start its initialization from scratch when the editor was re-opened, increasing the chances we would cause issues. The solution: When opening an editor, wait until the LS has finished starting before proceeding. This causes a small delay the first time, but is instantaneous the following times. Also, added a new browser test file: explorer-open-close.spec.js. I suspected that there was some flakiness in the find-replace suite, potentially caused by the mix of opening and closing both the explorer and an editor. I was not able to find anything but with this new test file we might, if there's any, now or later. Signed-off-by: Marc Dumais <[email protected]>
- Loading branch information
1 parent
afdae63
commit fa1db70
Showing
2 changed files
with
212 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
// ***************************************************************************** | ||
// Copyright (C) 2023 Ericsson and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0. | ||
// | ||
// This Source Code may also be made available under the following Secondary | ||
// Licenses when the conditions for such availability set forth in the Eclipse | ||
// Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
// with the GNU Classpath Exception which is available at | ||
// https://www.gnu.org/software/classpath/license.html. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
// ***************************************************************************** | ||
|
||
// @ts-check | ||
describe('Explorer and Editor - open and close', function () { | ||
this.timeout(90_000); | ||
const { assert } = chai; | ||
|
||
const { DisposableCollection } = require('@theia/core/lib/common/disposable'); | ||
const { EditorManager } = require('@theia/editor/lib/browser/editor-manager'); | ||
const { WorkspaceService } = require('@theia/workspace/lib/browser/workspace-service'); | ||
const { FileNavigatorContribution } = require('@theia/navigator/lib/browser/navigator-contribution'); | ||
const { ApplicationShell } = require('@theia/core/lib/browser/shell/application-shell'); | ||
const { HostedPluginSupport } = require('@theia/plugin-ext/lib/hosted/browser/hosted-plugin'); | ||
const { ProgressStatusBarItem } = require('@theia/core/lib/browser/progress-status-bar-item'); | ||
const { EXPLORER_VIEW_CONTAINER_ID } = require('@theia/navigator/lib/browser/navigator-widget-factory'); | ||
const { MonacoEditor } = require('@theia/monaco/lib/browser/monaco-editor'); | ||
const container = window.theia.container; | ||
const editorManager = container.get(EditorManager); | ||
const workspaceService = container.get(WorkspaceService); | ||
const navigatorContribution = container.get(FileNavigatorContribution); | ||
const shell = container.get(ApplicationShell); | ||
const rootUri = workspaceService.tryGetRoots()[0].resource; | ||
const pluginService = container.get(HostedPluginSupport); | ||
const progressStatusBarItem = container.get(ProgressStatusBarItem); | ||
|
||
|
||
const fileUri = rootUri.resolve('webpack.config.js'); | ||
const toTearDown = new DisposableCollection(); | ||
|
||
function pause(ms = 500) { | ||
console.debug(`pause test for: ${ms} ms`); | ||
return new Promise(resolve => setTimeout(resolve, ms)); | ||
} | ||
|
||
before(async () => { | ||
await pluginService.didStart; | ||
await editorManager.closeAll({ save: false }); | ||
}); | ||
|
||
afterEach(async () => { | ||
await editorManager.closeAll({ save: false }); | ||
await navigatorContribution.closeView(); | ||
}); | ||
|
||
after(async () => { | ||
toTearDown.dispose(); | ||
}); | ||
|
||
for (var i = 0; i < 5; i++) { | ||
let ordering = 0; | ||
it('Open/Close explorer and editor - ordering: ' + ordering++ + ', iteration #' + i, async function () { | ||
await openExplorer(); | ||
await openEditor(); | ||
await closeEditor(); | ||
await closeExplorer(); | ||
}); | ||
|
||
it('Open/Close explorer and editor - ordering: ' + ordering++ + ', iteration #' + i, async function () { | ||
await openExplorer(); | ||
await openEditor(); | ||
await closeExplorer(); | ||
await closeEditor(); | ||
}); | ||
|
||
it('Open/Close editor, explorer - ordering: ' + ordering++ + ', iteration - #' + i, async function () { | ||
await openEditor(); | ||
await openExplorer(); | ||
await closeEditor(); | ||
await closeExplorer(); | ||
}); | ||
|
||
it('Open/Close editor, explorer - ordering: ' + ordering++ + ', iteration - #' + i, async function () { | ||
await openEditor(); | ||
await openExplorer(); | ||
await closeExplorer(); | ||
await closeEditor(); | ||
}); | ||
|
||
it('Open/Close explorer #' + i, async function () { | ||
await openExplorer(); | ||
await closeExplorer(); | ||
}); | ||
} | ||
|
||
it('open/close explorer in quick succession', async function () { | ||
for (let i = 0; i < 20; i++) { | ||
await openExplorer(); | ||
await closeExplorer(); | ||
} | ||
}); | ||
|
||
it('open/close editor in quick succession', async function () { | ||
await openExplorer(); | ||
for (let i = 0; i < 20; i++) { | ||
await openEditor(); | ||
await closeEditor(); | ||
} | ||
}); | ||
|
||
async function openExplorer() { | ||
await navigatorContribution.openView({ activate: true }); | ||
const widget = await shell.revealWidget(EXPLORER_VIEW_CONTAINER_ID); | ||
assert.isDefined(widget, 'Explorer widget should exist'); | ||
} | ||
async function closeExplorer() { | ||
await navigatorContribution.closeView(); | ||
assert.isUndefined(await shell.revealWidget(EXPLORER_VIEW_CONTAINER_ID), 'Explorer widget should not exist'); | ||
} | ||
|
||
async function openEditor() { | ||
await editorManager.open(fileUri, { mode: 'activate' }); | ||
await waitLanguageServerReady(); | ||
const activeEditor = /** @type {MonacoEditor} */ MonacoEditor.get(editorManager.activeEditor); | ||
assert.isDefined(activeEditor); | ||
assert.equal(activeEditor.uri.resolveToAbsolute().toString(), fileUri.resolveToAbsolute().toString()); | ||
} | ||
|
||
async function closeEditor() { | ||
await editorManager.closeAll({ save: false }); | ||
const activeEditor = /** @type {MonacoEditor} */ MonacoEditor.get(editorManager.activeEditor); | ||
assert.isUndefined(activeEditor); | ||
} | ||
|
||
async function waitLanguageServerReady() { | ||
// quite a bit of jitter in the "Initializing LS" status bar entry, | ||
// so we want to read a few times in a row that it's done (undefined) | ||
const MAX_N = 5 | ||
let n = MAX_N; | ||
while (n > 0) { | ||
await pause(1); | ||
if (progressStatusBarItem.currentProgress) { | ||
n = MAX_N; | ||
} else { | ||
n--; | ||
} | ||
if (n < MAX_N) { | ||
console.debug('n = ' + n); | ||
} | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters