]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/dashboard: Fix duplicate tasks
authorTiago Melo <tmelo@suse.com>
Mon, 5 Nov 2018 11:39:29 +0000 (11:39 +0000)
committerTiago Melo <tmelo@suse.com>
Mon, 5 Nov 2018 12:31:34 +0000 (12:31 +0000)
In certain situations a new task is already in the current summary before we
manually push it to the running task list.
Since we were not checking that, at the end of the operation we would have 2
entries for the same task and that would be displayed in the UI.

Signed-off-by: Tiago Melo <tmelo@suse.com>
src/pybind/mgr/dashboard/frontend/src/app/shared/services/summary.service.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/services/summary.service.ts

index 4dd03110c13ff11c7d68eb233d68cc2f7160fa0e..1c31f414c404a8e52278987f58bacbed35c88792 100644 (file)
@@ -95,5 +95,22 @@ describe('SummaryService', () => {
         name: 'rbd/delete'
       });
     });
+
+    it('should call addRunningTask with duplicate task', () => {
+      let result = summaryService.getCurrentSummary();
+      const exec_task = new ExecutingTask('rbd/delete', {
+        pool_name: 'somePool',
+        image_name: 'someImage'
+      });
+
+      result.executing_tasks = [exec_task];
+      summaryService['summaryDataSource'].next(result);
+      result = summaryService.getCurrentSummary();
+      expect(result.executing_tasks.length).toBe(1);
+
+      summaryService.addRunningTask(exec_task);
+      result = summaryService.getCurrentSummary();
+      expect(result.executing_tasks.length).toBe(1);
+    });
   });
 });
index fad4dd9435ac83e16ab6d4259989d0c37ccad737..d90c16f74c742bcdf0e7275cfb7cbb14f75933b7 100644 (file)
@@ -76,7 +76,12 @@ export class SummaryService {
     }
 
     if (_.isArray(current.executing_tasks)) {
-      current.executing_tasks.push(task);
+      const exists = current.executing_tasks.find((element) => {
+        return element.name === task.name && _.isEqual(element.metadata, task.metadata);
+      });
+      if (!exists) {
+        current.executing_tasks.push(task);
+      }
     } else {
       current.executing_tasks = [task];
     }