Fix object explorer session fails (#5256)

* only start session if response successful

* added return type

* fixed OE tests

* format doc
This commit is contained in:
Aditya Bist
2019-04-30 11:45:52 -07:00
committed by GitHub
parent f7fc94520a
commit f70369c2a6
2 changed files with 13 additions and 7 deletions

View File

@@ -227,7 +227,13 @@ export class ObjectExplorerService implements IObjectExplorerService {
* Gets called when session is created
*/
public onSessionCreated(handle: number, session: azdata.ObjectExplorerSession): void {
this.handleSessionCreated(session);
if (session && session.success) {
this.handleSessionCreated(session);
} else {
let errorMessage = session && session.errorMessage ? session.errorMessage :
nls.localize('OeSessionFailedError', 'Failed to create Object Explorer session');
error(errorMessage);
}
}
private async handleSessionCreated(session: azdata.ObjectExplorerSession): Promise<void> {
@@ -237,7 +243,7 @@ export class ObjectExplorerService implements IObjectExplorerService {
if (this._sessions[session.sessionId]) {
connection = this._sessions[session.sessionId].connection;
if (session && session.success && session.rootNode) {
if (session.success && session.rootNode) {
let server = this.toTreeNode(session.rootNode, null);
server.connection = connection;
server.session = session;

View File

@@ -33,7 +33,7 @@ suite('SQL Object Explorer Service tests', () => {
let objectExplorerExpandInfoRefresh: NodeExpandInfoWithProviderId;
let sessionId = '1234';
let failedSessionId = '12345';
let numberOfFailedSession: number = 0;
let numberOfSuccessfulSessions: number = 0;
let serverTreeView: TypeMoq.Mock<ServerTreeView>;
const providerId = 'MSSQL';
@@ -286,8 +286,8 @@ suite('SQL Object Explorer Service tests', () => {
sqlOEProvider.setup(x => x.closeSession(TypeMoq.It.isAny())).returns(() => Promise.resolve(objectExplorerCloseSessionResponse));
objectExplorerService.onUpdateObjectExplorerNodes(args => {
if (args && args.errorMessage !== undefined) {
numberOfFailedSession++;
if (args && args.errorMessage === undefined) {
numberOfSuccessfulSessions++;
}
});
@@ -320,11 +320,11 @@ suite('SQL Object Explorer Service tests', () => {
objectExplorerService.createNewSession('MSSQL', connectionToFail).then(session => {
assert.equal(session !== null || session !== undefined, true);
assert.equal(session.sessionId, failedSessionId);
let currentNumberOfFailedSession = numberOfFailedSession;
let currentNumberOfSuccessfulSessions = numberOfSuccessfulSessions;
objectExplorerService.onSessionCreated(1, objectExplorerFailedSession);
let node = objectExplorerService.getObjectExplorerNode(connection);
assert.equal(node, undefined);
assert.equal(currentNumberOfFailedSession + 1, numberOfFailedSession);
assert.equal(currentNumberOfSuccessfulSessions, numberOfSuccessfulSessions);
done();
}, err => {
// Must call done here so test indicates it's finished if errors occur