Merge ~ltrager/maas:lp1757153 into maas:master

Proposed by Lee Trager
Status: Merged
Approved by: Lee Trager
Approved revision: 6a20dd51d7123fad6cf01ac2243648c0b901ef4a
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~ltrager/maas:lp1757153
Merge into: maas:master
Diff against target: 50 lines (+17/-5)
2 files modified
src/maasserver/static/js/angular/directives/script_runtime.js (+3/-4)
src/maasserver/static/js/angular/directives/tests/test_script_runtime.js (+14/-1)
Reviewer Review Type Date Requested Status
MAAS Lander Approve
Newell Jensen (community) Approve
Blake Rouse (community) Approve
Review via email: mp+342124@code.launchpad.net

Commit message

LP: #1757153 - Fix script runtime while running.

To post a comment you must log in.
Revision history for this message
Blake Rouse (blake-rouse) wrote :

Looks good.

review: Approve
Revision history for this message
Newell Jensen (newell-jensen) wrote :

+1

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1757153 lp:~ltrager/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 6a20dd51d7123fad6cf01ac2243648c0b901ef4a

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/static/js/angular/directives/script_runtime.js b/src/maasserver/static/js/angular/directives/script_runtime.js
2index f5ee0b4..66c053e 100644
3--- a/src/maasserver/static/js/angular/directives/script_runtime.js
4+++ b/src/maasserver/static/js/angular/directives/script_runtime.js
5@@ -1,4 +1,4 @@
6-/* Copyright 2017 Canonical Ltd. This software is licensed under the
7+/* Copyright 2017-2018 Canonical Ltd. This software is licensed under the
8 * GNU Affero General Public License version 3 (see the file LICENSE).
9 *
10 * Script runtime counter directive.
11@@ -36,9 +36,8 @@ angular.module('MAAS').directive('maasScriptRunTime', function() {
12 function incrementCounter() {
13 if(($scope.scriptStatus === 1 || $scope.scriptStatus === 7) &&
14 $scope.startTime) {
15- var start_date = new Date(null);
16- start_date.setSeconds($scope.startTime);
17- var seconds = Math.floor((Date.now() - start_date) / 1000);
18+ var seconds = Math.floor(
19+ (Date.now() / 1000) - $scope.startTime);
20 var minutes = Math.floor(seconds / 60);
21 var hours = Math.floor(minutes / 60);
22 var days = Math.floor(hours / 24);
23diff --git a/src/maasserver/static/js/angular/directives/tests/test_script_runtime.js b/src/maasserver/static/js/angular/directives/tests/test_script_runtime.js
24index f26fb53..b5048fe 100644
25--- a/src/maasserver/static/js/angular/directives/tests/test_script_runtime.js
26+++ b/src/maasserver/static/js/angular/directives/tests/test_script_runtime.js
27@@ -1,4 +1,4 @@
28-/* Copyright 2017 Canonical Ltd. This software is licensed under the
29+/* Copyright 2017-2018 Canonical Ltd. This software is licensed under the
30 * GNU Affero General Public License version 3 (see the file LICENSE).
31 *
32 * Unit tests for script runtime directive.
33@@ -111,4 +111,17 @@ describe("maasScriptRunTime", function() {
34 expect(spanElement.text()).toEqual(
35 '2 days, 0:00:00 of ~' + estimatedRunTime);
36 });
37+
38+ it('regression test for LP:1757153', function() {
39+ var startTime = (Date.now() / 1000) - 1;
40+ var estimatedRunTime = '0:00:54';
41+ var scriptStatus = 1;
42+ var directive = compileDirective(
43+ startTime, null, estimatedRunTime, scriptStatus);
44+ // Flush should not cause the passed time to change.
45+ var spanElement = directive.find('span');
46+ expect(spanElement).toBeDefined();
47+ expect(spanElement.text()).toEqual(
48+ '0:00:01 of ~' + estimatedRunTime);
49+ });
50 });

Subscribers

People subscribed via source and target branches