Sandbox parallell websocket load tester user/berick/websocket-parallel-tester
authorBill Erickson <berickxx@gmail.com>
Mon, 6 Mar 2023 15:37:56 +0000 (10:37 -0500)
committerBill Erickson <berickxx@gmail.com>
Mon, 6 Mar 2023 15:37:56 +0000 (10:37 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html
Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts

index 6127891..3231e29 100644 (file)
@@ -2,6 +2,20 @@
 <eg-staff-banner bannerText="Sandbox" i18n-bannerText>
 </eg-staff-banner>
 
+<div class="row mt-2 mb-2">
+  <div class="col-lg-2">
+    <button (click)="testWebsockets()" class="btn btn-success">
+      Test Parallel Websockets
+    </button>
+  </div>
+  <div class="col-lg-2">
+    Sent = {{wsSent}}, received = {{wsReceived}}
+  </div>
+  <div class="col-lg-8">
+    <eg-progress-inline [max]="wsSendCount" value="0" #wsProgress></eg-progress-inline>
+  </div>
+</div>
+
 <eg-title 
   i18n-prefix i18n-suffix
   prefix=":) {{dynamicTitleText}}"
index edc35ac..b0d1053 100644 (file)
@@ -2,6 +2,7 @@
 import {timer as observableTimer, Observable, of} from 'rxjs';
 import {Component, OnInit, ViewChild, Input, TemplateRef} from '@angular/core';
 import {ProgressDialogComponent} from '@eg/share/dialog/progress.component';
+import {ProgressInlineComponent} from '@eg/share/dialog/progress-inline.component';
 import {ToastService} from '@eg/share/toast/toast.service';
 import {StringService} from '@eg/share/string/string.service';
 import {map, take} from 'rxjs/operators';
@@ -32,6 +33,8 @@ import {HtmlToTxtService} from '@eg/share/util/htmltotxt.service';
 })
 export class SandboxComponent implements OnInit {
 
+    @ViewChild('wsProgress') private wsDialog: ProgressInlineComponent;
+
     @ViewChild('progressDialog', { static: true })
     private progressDialog: ProgressDialogComponent;
 
@@ -54,6 +57,9 @@ export class SandboxComponent implements OnInit {
 
     @ViewChild('penaltyDialog', {static: false}) penaltyDialog;
 
+    wsSendCount = 500;
+    wsSent = 0;
+    wsReceived = 0;
 
     // @ViewChild('helloStr') private helloStr: StringComponent;
 
@@ -507,5 +513,21 @@ export class SandboxComponent implements OnInit {
         this.penaltyDialog.open()
         .subscribe(val => console.log('penalty value', val));
     }
+
+    testWebsockets() {
+        this.wsSent = 0;
+        this.wsReceived = 0;
+        this.wsDialog.update({value: 0});
+
+        while (this.wsSent < this.wsSendCount) {
+            this.wsSent++;
+
+            // Firing requests in parallel
+            this.pcrud.retrieve('aou', 1).toPromise().then(o => {
+                this.wsReceived++;
+                this.wsDialog.increment();
+            });
+        }
+    }
 }