LP#1739504 - create prototype of latency test tool in webstaff
authorCesar Velez <cesar.velez@equinoxinitiative.org>
Wed, 20 Dec 2017 23:38:28 +0000 (18:38 -0500)
committerCesar Velez <cesar.velez@equinoxinitiative.org>
Thu, 21 Dec 2017 19:22:30 +0000 (14:22 -0500)
Basic websocket latency tester. Just pings opensrf.system.echo.
Initial first test runs 10 pings, calculates average each time.

Signed-off by: Cesar Velez <cesar.velez@equinoxinitiative.org>

Open-ILS/src/templates/staff/admin/workstation/t_splash.tt2
Open-ILS/src/templates/staff/admin/workstation/t_tests.tt2 [new file with mode: 0644]
Open-ILS/web/js/ui/default/staff/admin/workstation/app.js

index 94c1140..345f7db 100644 (file)
       </div>
 
       <div class="row new-entry">
+        <div class="col-md-6">
+          <span class="glyphicon glyphicon-wrench"></span>
+          <a target="_self" href="./admin/workstation/tests">
+            [% l('Tests') %]
+          </a>
+        </div>
+      </div>
+
+      <div class="row new-entry">
         <div class="col-md-4">
           <div class="checkbox">
             <label>
diff --git a/Open-ILS/src/templates/staff/admin/workstation/t_tests.tt2 b/Open-ILS/src/templates/staff/admin/workstation/t_tests.tt2
new file mode 100644 (file)
index 0000000..767a80c
--- /dev/null
@@ -0,0 +1,41 @@
+<div class="container-fluid text-center">
+  <div class="alert alert-info alert-less-pad strong-text-2">
+    <span>[% l('Webclient Latency Test') %]</span>
+  </div>
+</div>
+
+<div class="row">
+  <div class="col-md-8">
+    <div class="panel panel-default">
+      <div class="panel-heading">[% l('Server Details') %]</div>
+      <div class="panel-body">
+       <!-- <div class="row pad-vert nav-pills-like-tabs">
+          <div class="col-md-6">[% l('Evergreen Version') %]</div>
+          <div class="col-md-6">{{context.version}}</div>
+        </div> -->
+        <div class="row pad-vert">
+          <div class="col-md-6">[% l('Hostname') %]</div>
+          <div class="col-md-6">{{hostname}}</div>
+        </div>
+      </div>
+    </div><!--panel-->
+   </div>
+</div>
+<div class="row">
+  <div class="col-md-8">
+    <h2>[% l('Latency Test') %]</h2>
+    <p>[% |l %]This will measure the websocket latency between your workstation client and the Evergreen server at the host above.[% END %]
+    </p>
+    <button ng-disable="isTesting" ng-click="testLatency()" type="button" class="btn btn-primary">Start Test</button>
+    <button ng-click='clearTestData()' type="button" class="btn btn-secondary">Clear</button>
+    <ol id="pingData">
+      <p>Latency results for {{hostname}}. Average Latency: <span ng-bind="avrg"></span> ms</p>
+      <li ng-show="tests.length" ng-repeat="t in tests">Time: {{t.t}} Latency: {{t.l}} ms</li>
+    </ol>
+    <button ng-disabled="!canCopyCommand" ng-click="copyTests()" type="button" class="btn btn-light btn-sm">Copy to Clipboard</button>
+  </div>
+</div>
+
+
+
+
index 71e9117..b42503b 100644 (file)
@@ -44,6 +44,12 @@ angular.module('egWorkstationAdmin',
         resolve : resolver
     });
 
+    $routeProvider.when('/admin/workstation/tests', {
+        templateUrl: './admin/workstation/t_tests',
+        controller: 'testsCtrl',
+        resolve : resolver
+    });
+    
     // default page 
     $routeProvider.otherwise({
         templateUrl : './admin/workstation/t_splash',
@@ -926,4 +932,80 @@ function($scope , egCore , ngToast) {
 
 }])
 
+/*
+ * Home of the Latency tester
+ * */
+.controller('testsCtrl', ['$scope', '$location', 'egCore', function($scope, $location, egCore) {
+    $scope.hostname = $location.host();
+
+    $scope.tests = [];
+    $scope.clearTestData = function(){
+        $scope.tests = [];
+        numPings = 0;
+    }
+
+    $scope.isTesting = false;
+    $scope.avrg = 0; // avrg latency
+    $scope.canCopyCommand = document.queryCommandSupported('copy');
+    var numPings = 0;
+    // fetch first 10
+
+    function calcAverage(){
+
+        if ($scope.tests.length == 0) return 0;
+
+        if ($scope.tests.length == 1) return $scope.tests[0].l;
+
+        var sum = 0;
+        angular.forEach($scope.tests, function(t){
+            sum += t.l;
+        });
+
+        return sum / $scope.tests.length;
+    }
+
+    function ping(){
+        $scope.isTesting = true;
+        var t = Date.now();
+        egCore.net.request(
+            "open-ils.pcrud", "opensrf.system.echo", "ping"
+        ).then(function(resp){
+            var t2 = Date.now();
+            var latency = t2 - t;
+            $scope.tests.push({t: new Date(t), l: latency});
+            console.log("Start: " + t + " and end: " + t2);
+            console.log("Latency: " + latency);
+            console.log(resp);
+        }).then(function(){
+            $scope.avrg = calcAverage();
+            numPings++;
+            $scope.isTesting = false;
+        });
+    }
+
+    $scope.testLatency = function(){
+
+        if (numPings >= 10){
+            ping(); // just ping once after the initial ten
+        } else {
+            for (var i=0; i<10; i++){
+                ping();
+            }
+        }
+    }
+
+    $scope.copyTests = function(){
+
+        var lNode = document.querySelector('#pingData');
+        var r = document.createRange();
+        r.selectNode(lNode);
+        var sel = window.getSelection();
+        sel.removeAllRanges();
+        sel.addRange(r);
+        document.execCommand('copy');
+    }
+
+}])
+
+