Merge ~ltrager/maas:lp1733015 into maas:master

Proposed by Lee Trager
Status: Merged
Approved by: Lee Trager
Approved revision: 1c75e207fba6800b9853fc9f542af2065c5c6c4d
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~ltrager/maas:lp1733015
Merge into: maas:master
Diff against target: 72 lines (+46/-5)
2 files modified
src/maasserver/static/js/angular/directives/script_runtime.js (+31/-5)
src/maasserver/static/js/angular/directives/tests/test_script_runtime.js (+15/-0)
Reviewer Review Type Date Requested Status
Mike Pontillo (community) Approve
MAAS Lander unittests Pending
Review via email: mp+333926@code.launchpad.net

Commit message

LP: #1733015 - Show days in runtime when tests run over 24 hours

To post a comment you must log in.
Revision history for this message
Mike Pontillo (mpontillo) wrote :

I'm +1 on this branch since it makes things correct and consistent.

But I think the final rendered string is a bit large. We might consider cutting out the days and just use the number of hours, to be more concise. Example:

https://usercontent.irccloud-cdn.com/file/ESWpb82l/getting-a-bit-too-big.png

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 3a198c3..f5ee0b4 100644
3--- a/src/maasserver/static/js/angular/directives/script_runtime.js
4+++ b/src/maasserver/static/js/angular/directives/script_runtime.js
5@@ -36,12 +36,38 @@ angular.module('MAAS').directive('maasScriptRunTime', function() {
6 function incrementCounter() {
7 if(($scope.scriptStatus === 1 || $scope.scriptStatus === 7) &&
8 $scope.startTime) {
9- var date = new Date(null);
10- date.setSeconds((Date.now()/1000) - $scope.startTime);
11- $scope.counter = date.toISOString().substr(11, 8);
12- if($scope.counter.indexOf('00:') === 0) {
13- $scope.counter = $scope.counter.substr(1);
14+ var start_date = new Date(null);
15+ start_date.setSeconds($scope.startTime);
16+ var seconds = Math.floor((Date.now() - start_date) / 1000);
17+ var minutes = Math.floor(seconds / 60);
18+ var hours = Math.floor(minutes / 60);
19+ var days = Math.floor(hours / 24);
20+ hours = hours - (days * 24);
21+ minutes = minutes - (days * 24 * 60) - (hours * 60);
22+ seconds = seconds - (days * 24 * 60 * 60) -
23+ (hours * 60 * 60) - (minutes * 60);
24+ var new_counter = "";
25+ // This outputs the same format used by Python. It is
26+ // import to use the same format as when scripts are not
27+ // running runtime is taken from the region using Python's
28+ // format.
29+ if(days === 1) {
30+ new_counter = days + " day, ";
31+ }else if(days > 1) {
32+ new_counter = days + " days, ";
33 }
34+ new_counter += hours + ":";
35+ if(minutes < 10) {
36+ new_counter += "0" + minutes + ":";
37+ } else {
38+ new_counter += minutes + ":";
39+ }
40+ if(seconds < 10) {
41+ new_counter += "0" + seconds;
42+ } else {
43+ new_counter += seconds;
44+ }
45+ $scope.counter = new_counter;
46 }
47 }
48
49diff --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
50index 5839f3f..f5343ca 100644
51--- a/src/maasserver/static/js/angular/directives/tests/test_script_runtime.js
52+++ b/src/maasserver/static/js/angular/directives/tests/test_script_runtime.js
53@@ -86,4 +86,19 @@ describe("maasScriptRunTime", function() {
54 expect(spanElement).toBeDefined();
55 expect(spanElement.text()).toEqual('0:00:05 of ~' + estimatedRunTime);
56 });
57+
58+ it('shows day when over 24 hours', function() {
59+ // Regression test for LP:1733015
60+ var startTime = (Date.now() / 1000) - (2 * 24 * 60 * 60); // 2 days ago
61+ var estimatedRunTime = '1 day, 0:00:35';
62+ var scriptStatus = 1;
63+ var directive = compileDirective(
64+ startTime, null, estimatedRunTime, scriptStatus);
65+ // Flush should not cause the passed time to change.
66+ $interval.flush(1000);
67+ var spanElement = directive.find('span');
68+ expect(spanElement).toBeDefined();
69+ expect(spanElement.text()).toEqual(
70+ '2 days, 0:00:00 of ~' + estimatedRunTime);
71+ });
72 });

Subscribers

People subscribed via source and target branches