Fix a number of broken connection detection scenarios.

This commit is contained in:
Akshay Joshi
2018-03-21 08:38:18 +00:00
committed by Dave Page
parent d358369ed5
commit 637f3b9d1a
12 changed files with 191 additions and 110 deletions

View File

@@ -42,6 +42,7 @@ describe('ExecuteQuery', () => {
'_init_polling_flags',
'save_state',
'init_transaction',
'handle_connection_lost',
]);
sqlEditorMock.transId = 123;
sqlEditorMock.rows_affected = 1000;
@@ -49,6 +50,10 @@ describe('ExecuteQuery', () => {
isNewTransactionRequiredMock = spyOn(transaction, 'is_new_transaction_required');
});
afterEach(() => {
networkMock.restore();
});
describe('#poll', () => {
let cancelButtonSpy;
let response;
@@ -62,9 +67,6 @@ describe('ExecuteQuery', () => {
executeQuery.delayedPoll = jasmine.createSpy('ExecuteQuery.delayedPoll');
});
afterEach(() => {
});
context('when SQLEditor is the query tool', () => {
beforeEach(() => {
sqlEditorMock.is_query_tool = true;
@@ -569,8 +571,7 @@ describe('ExecuteQuery', () => {
describe('when cannot reach the Python Server', () => {
beforeEach(() => {
response = {readyState: 0};
networkMock.onGet('/sqleditor/query_tool/poll/123').reply(401, response);
networkMock.onGet('/sqleditor/query_tool/poll/123').reply(404, undefined);
executeQuery.poll();
});
@@ -972,8 +973,7 @@ describe('ExecuteQuery', () => {
describe('when cannot reach the Python Server', () => {
beforeEach(() => {
response = {readyState: 0};
networkMock.onGet('/sqleditor/query_tool/poll/123').reply(401, response);
networkMock.onGet('/sqleditor/query_tool/poll/123').reply(404, undefined);
executeQuery.poll();
});
@@ -1143,9 +1143,9 @@ describe('ExecuteQuery', () => {
describe('when HTTP return 200', () => {
describe('when backend informs that query started successfully', () => {
beforeEach(() => {
networkMock.onAny('/sqleditor/query_tool/start/123').reply(200, response);
networkMock.onPost('/sqleditor/query_tool/start/123?connect=1').reply(200, response);
pollSpy = spyOn(executeQuery, 'delayedPoll');
executeQuery.execute('some sql query', '');
executeQuery.execute('some sql query', '', true);
});
it('should changes the loading message to "Waiting for the query execution to complete"', (done) => {
@@ -1310,10 +1310,7 @@ describe('ExecuteQuery', () => {
describe('when cannot reach the Python Server', () => {
beforeEach(() => {
response = {
readyState: 0,
};
networkMock.onAny('/sqleditor/query_tool/start/123').reply(500, response);
networkMock.onAny('/sqleditor/query_tool/start/123').reply(500, undefined);
executeQuery.execute('some sql query', '');
@@ -1657,7 +1654,32 @@ describe('ExecuteQuery', () => {
}, 0);
});
});
describe('when connection to database is lost', () => {
beforeEach(() => {
isNewTransactionRequiredMock.and.returnValue(false);
response.info = 'CONNECTION_LOST';
networkMock.onAny('/sqleditor/query_tool/start/123').reply(503, response);
executeQuery.execute('some sql query', '');
});
it('saves state', () => {
setTimeout(() => {
expect(sqlEditorMock.save_state).toHaveBeenCalledWith(
'execute',
['']
);
}, 0);
});
it('calls handle_connection_lost', () => {
setTimeout(() => {
expect(sqlEditorMock.handle_connection_lost).toHaveBeenCalled();
}, 0);
});
});
});
});
});

View File

@@ -19,7 +19,7 @@ describe('#is_new_transaction_required', () => {
});
describe('when status is 404', () => {
describe('when responseJSON is not present', () => {
describe('when data is not present', () => {
it('should return false', () => {
expect(is_new_transaction_required({
status: 404,
@@ -27,22 +27,22 @@ describe('#is_new_transaction_required', () => {
});
});
describe('when responseJSON is present', () => {
describe('when info is not present inside responseJSON', () => {
describe('when data is present', () => {
describe('when info is not present inside data', () => {
it('should return false', () => {
expect(is_new_transaction_required({
status: 404,
responseJSON: {},
data: {},
})).toBeFalsy();
});
});
describe('when info is present inside responseJSON', () => {
describe('when info is present inside data', () => {
describe('when info value is not "DATAGRID_TRANSACTION_REQUIRED"', () => {
it('should return false', () => {
expect(is_new_transaction_required({
status: 404,
responseJSON: {
data: {
info: 'some information',
},
})).toBe(false);
@@ -53,7 +53,7 @@ describe('#is_new_transaction_required', () => {
it('should return false', () => {
expect(is_new_transaction_required({
status: 404,
responseJSON: {
data: {
info: 'DATAGRID_TRANSACTION_REQUIRED',
},
})).toBe(true);