]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/dashboard: Performance counter progress bar keeps infinitely looping
authorVolker Theile <vtheile@suse.com>
Fri, 5 Oct 2018 09:20:35 +0000 (11:20 +0200)
committerVolker Theile <vtheile@suse.com>
Tue, 9 Oct 2018 06:26:09 +0000 (08:26 +0200)
Fixes: https://tracker.ceph.com/issues/36325
Signed-off-by: Volker Theile <vtheile@suse.com>
src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.html
src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/services/api-interceptor.service.spec.ts

index 862bf205c602977f2b7c5ad7fbb86ce74cdb95e1..545ec3dff1f06e4ceb1b19c336eec6ea8467aa1d 100644 (file)
@@ -3,7 +3,7 @@
           [columns]="columns"
           columnMode="flex"
           [autoSave]="false"
-          (fetchData)="getCounters()">
+          (fetchData)="getCounters($event)">
   <ng-template #valueTpl let-row="row">
     {{ row.value | dimless }} {{ row.unit }}
   </ng-template>
index a71394fd02310a9cc2156fad7d0319b8c6fd7e47..4e1cd078968089877cd9311a1c38bd6fb57e2a2e 100644 (file)
@@ -1,26 +1,58 @@
-import { HttpClientTestingModule } from '@angular/common/http/testing';
+import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
 import { ComponentFixture, TestBed } from '@angular/core/testing';
 
 import { configureTestBed } from '../../../../testing/unit-test-helper';
-import { SharedModule } from '../../../shared/shared.module';
+import { AppModule } from '../../../app.module';
+import { CdTableFetchDataContext } from '../../../shared/models/cd-table-fetch-data-context';
 import { TablePerformanceCounterComponent } from './table-performance-counter.component';
 
 describe('TablePerformanceCounterComponent', () => {
   let component: TablePerformanceCounterComponent;
   let fixture: ComponentFixture<TablePerformanceCounterComponent>;
+  let httpTesting: HttpTestingController;
 
   configureTestBed({
-    declarations: [TablePerformanceCounterComponent],
-    imports: [SharedModule, HttpClientTestingModule]
+    imports: [AppModule, HttpClientTestingModule]
   });
 
   beforeEach(() => {
     fixture = TestBed.createComponent(TablePerformanceCounterComponent);
     component = fixture.componentInstance;
+    httpTesting = TestBed.get(HttpTestingController);
     fixture.detectChanges();
   });
 
   it('should create', () => {
     expect(component).toBeTruthy();
+    expect(component.counters).toEqual([]);
+  });
+
+  describe('Error handling', () => {
+    const context = new CdTableFetchDataContext(() => {});
+
+    beforeEach(() => {
+      spyOn(context, 'error');
+      component.serviceType = 'osd';
+      component.serviceId = '3';
+      component.getCounters(context);
+    });
+
+    it('should display 404 warning', () => {
+      httpTesting
+        .expectOne('api/perf_counters/osd/3')
+        .error(new ErrorEvent('osd.3 not found'), { status: 404 });
+      httpTesting.verify();
+      expect(component.counters).toBeNull();
+      expect(context.error).not.toHaveBeenCalled();
+    });
+
+    it('should call error function of context', () => {
+      httpTesting
+        .expectOne('api/perf_counters/osd/3')
+        .error(new ErrorEvent('Unknown error'), { status: 500 });
+      httpTesting.verify();
+      expect(component.counters).toEqual([]);
+      expect(context.error).toHaveBeenCalled();
+    });
   });
 });
index 5b9aa29cffec313a05a98c7f745f0cf0daf0da37..704afb066c302279f3b4795c9bcb32fd7c14f40b 100644 (file)
@@ -2,6 +2,7 @@ import { Component, Input, OnInit, TemplateRef, ViewChild } from '@angular/core'
 
 import { PerformanceCounterService } from '../../../shared/api/performance-counter.service';
 import { CdTableColumn } from '../../../shared/models/cd-table-column';
+import { CdTableFetchDataContext } from '../../../shared/models/cd-table-fetch-data-context';
 
 /**
  * Display the specified performance counters in a datatable.
@@ -52,7 +53,7 @@ export class TablePerformanceCounterComponent implements OnInit {
     ];
   }
 
-  getCounters() {
+  getCounters(context: CdTableFetchDataContext) {
     this.performanceCounterService.get(this.serviceType, this.serviceId).subscribe(
       (resp: object[]) => {
         this.counters = resp;
@@ -61,6 +62,8 @@ export class TablePerformanceCounterComponent implements OnInit {
         if (error.status === 404) {
           error.preventDefault();
           this.counters = null;
+        } else {
+          context.error();
         }
       }
     );
index f7513368c9dabbbdcc427a26922246c91b61dfb0..7c01b8a303304662c20f9c5b70f7f5f3f0c1be5e 100644 (file)
@@ -1,4 +1,4 @@
-import { HTTP_INTERCEPTORS, HttpClient, HttpErrorResponse } from '@angular/common/http';
+import { HttpClient, HttpErrorResponse } from '@angular/common/http';
 import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
 import { TestBed } from '@angular/core/testing';
 import { Router } from '@angular/router';