From: Volker Theile Date: Fri, 5 Oct 2018 09:20:35 +0000 (+0200) Subject: mgr/dashboard: Performance counter progress bar keeps infinitely looping X-Git-Tag: v14.0.1~87^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F24448%2Fhead;p=ceph.git mgr/dashboard: Performance counter progress bar keeps infinitely looping Fixes: https://tracker.ceph.com/issues/36325 Signed-off-by: Volker Theile --- diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.html index 862bf205c602..545ec3dff1f0 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.html @@ -3,7 +3,7 @@ [columns]="columns" columnMode="flex" [autoSave]="false" - (fetchData)="getCounters()"> + (fetchData)="getCounters($event)"> {{ row.value | dimless }} {{ row.unit }} diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.spec.ts index a71394fd0231..4e1cd0789680 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.spec.ts @@ -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; + 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(); + }); }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.ts index 5b9aa29cffec..704afb066c30 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.ts @@ -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(); } } ); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/api-interceptor.service.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/api-interceptor.service.spec.ts index f7513368c9da..7c01b8a30330 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/api-interceptor.service.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/api-interceptor.service.spec.ts @@ -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';