diff --git a/DocService/sources/databaseConnectors/baseConnector.js b/DocService/sources/databaseConnectors/baseConnector.js index d482ec6c..cfdd5bf3 100644 --- a/DocService/sources/databaseConnectors/baseConnector.js +++ b/DocService/sources/databaseConnectors/baseConnector.js @@ -297,11 +297,13 @@ function getExpired(ctx, maxCount, expireSeconds) { }, false, false, values); }); } -function getCountWithStatus(ctx, status) { +function getCountWithStatus(ctx, status, expireMs) { return new Promise(function(resolve, reject) { const values = []; - const sqlParam = addSqlParameter(status, values); - const sqlCommand = `SELECT COUNT(id) AS count FROM ${cfgTableResult} WHERE status=${sqlParam};`; + const expireDate = new Date(Date.now() - expireMs); + const sqlStatus = addSqlParameter(status, values); + const sqlDate = addSqlParameter(expireDate, values); + const sqlCommand = `SELECT COUNT(id) AS count FROM ${cfgTableResult} WHERE status=${sqlStatus} AND last_open_date>${sqlDate};`; dbInstance.sqlQuery(ctx, sqlCommand, function(error, result) { if (error) { reject(error); diff --git a/DocService/sources/shutdown.js b/DocService/sources/shutdown.js index 3c6e2783..273889f6 100644 --- a/DocService/sources/shutdown.js +++ b/DocService/sources/shutdown.js @@ -78,7 +78,7 @@ exports.shutdown = function(ctx, editorStat, status) { break; } var remainingFiles = yield editorStat.getShutdownCount(redisKeyShutdown); - let inSavingStatus = yield sqlBase.getCountWithStatus(ctx, commonDefines.FileStatus.SaveVersion); + let inSavingStatus = yield sqlBase.getCountWithStatus(ctx, commonDefines.FileStatus.SaveVersion, EXEC_TIMEOUT); ctx.logger.debug('shutdown remaining files editorStat:%d, db:%d', remainingFiles, inSavingStatus); if (!isStartWait && (remainingFiles + inSavingStatus) <= 0) { break; diff --git a/tests/integration/databaseTests/baseConnector.tests.js b/tests/integration/databaseTests/baseConnector.tests.js index 53037bc1..cc4022a0 100644 --- a/tests/integration/databaseTests/baseConnector.tests.js +++ b/tests/integration/databaseTests/baseConnector.tests.js @@ -38,6 +38,7 @@ const operationContext = require('../../../Common/sources/operationContext'); const taskResult = require('../../../DocService/sources/taskresult'); const commonDefines = require('../../../Common/sources/commondefines'); const constants = require('../../../Common/sources/constants'); +const utils = require("../../../Common/sources/utils"); const configSql = config.get('services.CoAuthoring.sql'); const ctx = new operationContext.Context(); @@ -420,14 +421,15 @@ describe('Base database connector', function () { test('Get Count With Status', async function () { let countWithStatus; let unknownStatus = 99;//to avoid collision with running server - countWithStatus = await baseConnector.getCountWithStatus(ctx, unknownStatus); + let EXEC_TIMEOUT = 30000 + utils.getConvertionTimeout(undefined); + countWithStatus = await baseConnector.getCountWithStatus(ctx, unknownStatus, EXEC_TIMEOUT); expect(countWithStatus).toEqual(0); for (const id of getCountWithStatusCase) { const task = createTask(id); task.status = unknownStatus; await insertIntoResultTable(date, task); } - countWithStatus = await baseConnector.getCountWithStatus(ctx, unknownStatus); + countWithStatus = await baseConnector.getCountWithStatus(ctx, unknownStatus, EXEC_TIMEOUT); expect(countWithStatus).toEqual(getCountWithStatusCase.length); }); });