-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* GLSP-1116: Folllow-up fixes - Refactor diagramLoader+modelsource: Avoid concurrency/timing issues between diagramloader & modelsource. In some cases the loader did send actions before the model source was fully configured. Now the loader explictly configures the model source before dispatching the model request actions. - Ensure that client session is disposed if `GlspModelSource` is disposed - Ensure that the `dispatch` method correctly awaits the super result - Fix typing of `requstUntil`. This method can actually also return undefined if the timeout was reached and `rejectOnTimeout` is false + adapt affected code - Refactor `handleAction` method to allow dispatching of received responses - Rename that contains `GLSPContextMenuMouseListener` to reflect class name - Refactor `IContextMenuServiceProvider` to return an no-op implementation if no `IContextMenuService` is bound instead of rejecting the promise - Fix typing for Request actions (see eclipse-sprotty/sprotty#378) - Add test cases - Remove deprecated code - Fix return type of `ExportSvgAction.is` Follow up for eclipse-glsp/glsp/issues/1116 * Add early-exit condition to `FeedbackActionDispatcher` Add early-exit condition to `FeedbackActionDispatcher` to avoid unnecesary feedback dispatching (and logging) when the actions array is empty
- Loading branch information
Showing
20 changed files
with
199 additions
and
134 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,87 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2023 EclipseSource 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 | ||
********************************************************************************/ | ||
import { expect } from 'chai'; | ||
import { Container } from 'inversify'; | ||
import { ActionHandlerRegistry, IActionHandler, RequestAction, ResponseAction, TYPES } from '~glsp-sprotty'; | ||
import { IDiagramOptions } from '..'; | ||
import { GLSPActionDispatcher } from './action-dispatcher'; | ||
import { defaultModule } from './default.module'; | ||
|
||
const container = new Container(); | ||
container.load(defaultModule); | ||
container.bind(TYPES.IDiagramOptions).toConstantValue(<IDiagramOptions>(<unknown>{ | ||
clientId: 'client1', | ||
diagramType: 'diagramType', | ||
glspClientProvider: async () => ({} as any) | ||
})); | ||
const registry = container.get(ActionHandlerRegistry); | ||
const actionDispatcher = container.get(GLSPActionDispatcher); | ||
|
||
let testHandlerDelay = 0; | ||
const testHandler: IActionHandler = { | ||
handle: action => { | ||
const request = action as RequestAction<ResponseAction>; | ||
new Promise(resolve => setTimeout(resolve, testHandlerDelay)).then(() => | ||
actionDispatcher.dispatch(<ResponseAction>{ | ||
kind: 'response', | ||
responseId: request.requestId | ||
}) | ||
); | ||
} | ||
}; | ||
registry.register('request', testHandler); | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
registry.register('response', { handle: () => {} }); | ||
actionDispatcher.initialize().then(() => { | ||
actionDispatcher['blockUntil'] = undefined; | ||
}); | ||
|
||
describe('GLSPActionDispatcher', () => { | ||
describe('requestUntil', () => { | ||
it('should resolve successfully if response dispatched within timeout', async () => { | ||
testHandlerDelay = 15; | ||
const requestAction = { kind: 'request', requestId: '' }; | ||
const response = await actionDispatcher.requestUntil(requestAction, 150); | ||
expect(response?.responseId).to.be.equal(requestAction.requestId); | ||
}); | ||
it('should resolve to `undefined` if no response dispatched within timeout & `rejectOnTimeout` flag is false', async () => { | ||
testHandlerDelay = 30; | ||
const requestAction = { kind: 'request', requestId: '' }; | ||
const response = await actionDispatcher.requestUntil(requestAction, 5); | ||
expect(response).to.be.undefined; | ||
}); | ||
it('should be rejected if no response dispatched within timeout & `rejectOnTimeout` flag is true', async () => { | ||
testHandlerDelay = 30; | ||
const requestAction = { kind: 'request', requestId: '' }; | ||
const gotRejected = await actionDispatcher.requestUntil(requestAction, 5, true).then( | ||
() => false, | ||
() => true | ||
); | ||
expect(gotRejected, 'Response promise should be rejected').to.be.true; | ||
}); | ||
}); | ||
describe('request & re-dispatch', () => { | ||
it('should be possible to re-dispatch the response of a `request` call', async () => { | ||
const requestAction = { kind: 'request', requestId: '' }; | ||
const response = await actionDispatcher.request(requestAction); | ||
const dispatchSuccessful = await actionDispatcher.dispatch(response).then( | ||
() => true, | ||
err => false | ||
); | ||
expect(dispatchSuccessful, 'Promise of re-dispatch should resolve successfully').to.be.true; | ||
}); | ||
}); | ||
}); |
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
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
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
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
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
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
Oops, something went wrong.