From 61b1a8733fdf464539595648e529e2dff214c1fb Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 22 Aug 2018 23:17:41 +0200 Subject: [PATCH] Fixed issue #2204 - Max size of tabs is not recognised --- .../javascripts/app/controllers/test.coffee | 10 +++- .../app/lib/app_post/task_manager.coffee | 34 ++++++++--- public/assets/tests/taskbar.js | 57 +++++++++++++++++-- test/browser/aab_unit_test.rb | 12 ++-- 4 files changed, 94 insertions(+), 19 deletions(-) diff --git a/app/assets/javascripts/app/controllers/test.coffee b/app/assets/javascripts/app/controllers/test.coffee index 64fe57aeb..c1886ff79 100644 --- a/app/assets/javascripts/app/controllers/test.coffee +++ b/app/assets/javascripts/app/controllers/test.coffee @@ -1,9 +1,10 @@ class App.TestController1 extends App.Controller constructor: -> super - @showState = false - @hideState = false - @activeState = false + @showState = false + @hideState = false + @activeState = false + @changedState ||= false @render() meta: -> @@ -21,6 +22,9 @@ class App.TestController1 extends App.Controller @activeState = state @render() + changed: => + @changedState + render: -> @html "
some test controller message:'#{@message}',show:'#{@showState}',hide:'#{@hideState}',active:'#{@activeState}'
" diff --git a/app/assets/javascripts/app/lib/app_post/task_manager.coffee b/app/assets/javascripts/app/lib/app_post/task_manager.coffee index affb98afc..3696c2dae 100644 --- a/app/assets/javascripts/app/lib/app_post/task_manager.coffee +++ b/app/assets/javascripts/app/lib/app_post/task_manager.coffee @@ -83,6 +83,18 @@ class App.TaskManager return if !_instance _instance.preferencesTrigger(key) + @tasksAutoCleanupDelayTime: (key) -> + return if !_instance + if !key + return _instance.tasksAutoCleanupDelayTime + _instance.tasksAutoCleanupDelayTime = key + + @tasksAutoCleanupTaskMax: (key) -> + return if !_instance + if !key + return _instance.maxTaskCount + _instance.maxTaskCount = key + class _taskManagerSingleton extends App.Controller @include App.LogInclude @@ -108,9 +120,11 @@ class _taskManagerSingleton extends App.Controller @tasksToUpdate = {} @tasksPreferences = {} @tasksPreferencesCallbacks = {} + @tasksAutoCleanupDelayTime = 12000 @activeTaskHistory = [] @queue = [] @queueRunning = false + @maxTaskCount = 30 all: -> @@ -599,7 +613,7 @@ class _taskManagerSingleton extends App.Controller tasksAutoCleanupDelay: => delay = => @tasksAutoCleanup() - App.Delay.set(delay, 12000, 'task-autocleanup', undefined, true) + App.Delay.set(delay, @tasksAutoCleanupDelayTime, 'task-autocleanup', undefined, true) tasksAutoCleanup: => @@ -607,13 +621,19 @@ class _taskManagerSingleton extends App.Controller currentTaskCount = => Object.keys(@allTasksByKey).length - maxTaskCount = 30 - if currentTaskCount() > maxTaskCount - for task in App.Taskbar.search(sortBy:'updated_at', order:'ASC') - if currentTaskCount() > maxTaskCount + if currentTaskCount() > @maxTaskCount + if @offlineModus + tasks = @all() + else + tasks = App.Taskbar.search(sortBy:'updated_at', order:'ASC') + for task in tasks + if currentTaskCount() > @maxTaskCount if !task.active - if _.isEmpty(task.state) || (_.isEmpty(task.state.ticket) && _.isEmpty(task.state.article)) - @log 'notice', "More then #{maxTaskCount} tasks open, close oldest untouched task #{task.key}" + worker = App.TaskManager.worker(task.key) + if worker + if worker.changed && worker.changed() + continue + @log 'notice', "More then #{@maxTaskCount} tasks open, close oldest untouched task #{task.key}" @remove(task.key) tasksInitial: => diff --git a/public/assets/tests/taskbar.js b/public/assets/tests/taskbar.js index 2a02dec93..87c6af8a7 100644 --- a/public/assets/tests/taskbar.js +++ b/public/assets/tests/taskbar.js @@ -40,7 +40,6 @@ test( "taskbar basic tests", function() { deepEqual(task.state, 'abc') deepEqual(task.params, { "a": 12 }) - App.TaskManager.execute({ key: 'TestKey2', controller: 'TestController1', @@ -258,12 +257,60 @@ test( "taskbar basic tests", function() { equal(App.TaskManager.nextTaskUrl(), false) equal(App.TaskManager.nextTaskUrl(), false) - // destroy task bar - App.TaskManager.reset() + // check max tabs + var times = 5; + App.TaskManager.tasksAutoCleanupDelayTime(200) + App.TaskManager.tasksAutoCleanupTaskMax(3) - // check if any taskar exists - equal($('#taskbars .content').length, 0, "check available active contents") + for(var i=0; i < times; i++){ + App.TaskManager.execute({ + key: 'TestKeyLoop' + i, + controller: 'TestController1', + params: { + message: "#" + i, + }, + show: true, + persistent: false, + }) + } + equal(App.TaskManager.all().length, 5) }) +App.Delay.set(function() { + test( "taskbar check max tabs 2", function() { + + equal(App.TaskManager.all().length, 3) + + var times = 5; + for(var i=0; i < times; i++){ + App.TaskManager.execute({ + key: 'TestKeyLoop2' + i, + controller: 'TestController1', + params: { + message: "#" + i, + changedState: true + }, + show: true, + persistent: false, + }) + } + equal(App.TaskManager.all().length, 8) + + }) +}, 1000); + +App.Delay.set(function() { + test( "taskbar check max tabs 5", function() { + + equal(App.TaskManager.all().length, 5) + + // destroy task bar + App.TaskManager.reset() + + // check if any taskar exists + equal($('#taskbars .content').length, 0, "check available active contents") + }) +}, 2000); + } diff --git a/test/browser/aab_unit_test.rb b/test/browser/aab_unit_test.rb index 76394834c..86d7bee2c 100644 --- a/test/browser/aab_unit_test.rb +++ b/test/browser/aab_unit_test.rb @@ -5,10 +5,11 @@ class AAbUnitTest < TestCase def test_core @browser = browser_instance location(url: browser_url + '/tests_core') + sleep 5 watch_for( css: '.result', value: 'Tests completed', - timeout: 8, + timeout: 4, ) match( css: '.result .failed', @@ -30,10 +31,11 @@ class AAbUnitTest < TestCase ) location(url: browser_url + '/tests_model') + sleep 5 watch_for( css: '.result', value: 'Tests completed', - timeout: 8, + timeout: 3, ) match( css: '.result .failed', @@ -77,10 +79,11 @@ class AAbUnitTest < TestCase def test_form @browser = browser_instance location(url: browser_url + '/tests_form') + sleep 5 watch_for( css: '.result', value: 'Tests completed', - timeout: 8, + timeout: 2, ) match( css: '.result .failed', @@ -212,10 +215,11 @@ class AAbUnitTest < TestCase ) location(url: browser_url + '/tests_taskbar') + sleep 5 watch_for( css: '.result', value: 'Tests completed', - timeout: 8, + timeout: 3, ) match( css: '.result .failed',