From 250d055f07e60af0ba518bff0732bf9cae5d9c36 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Stephan=20M=C3=BCller?= Date: Wed, 9 Oct 2019 17:47:36 +0200 Subject: [PATCH] mgr/dashboard: Fixes random cephfs tab test failure MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Fixes: https://tracker.ceph.com/issues/42077 Signed-off-by: Stephan Müller --- .../cephfs-tabs/cephfs-tabs.component.spec.ts | 45 +++++++++++-------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-tabs/cephfs-tabs.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-tabs/cephfs-tabs.component.spec.ts index 68895dc05af..e0b3258b90f 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-tabs/cephfs-tabs.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-tabs/cephfs-tabs.component.spec.ts @@ -1,5 +1,5 @@ import { HttpClientTestingModule } from '@angular/common/http/testing'; -import { Component, Input, NgZone } from '@angular/core'; +import { Component, Input } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import * as _ from 'lodash'; @@ -29,6 +29,24 @@ describe('CephfsTabsComponent', () => { clients: { status: ViewCacheStatus; data: any[] }; }; + let old: any; + const getReload = () => component['reloadSubscriber']; + const setReload = (sth?) => (component['reloadSubscriber'] = sth); + const mockRunOutside = () => { + component['subscribeInterval'] = () => { + // It's mocked because the rxjs timer subscription ins't called through the use of 'tick'. + setReload({ + unsubscribed: false, + unsubscribe: () => { + old = getReload(); + getReload().unsubscribed = true; + setReload(); + } + }); + component.refresh(); + }; + }; + const setSelection = (selection: object[]) => { component.selection.selected = selection; component.selection.update(); @@ -89,8 +107,10 @@ describe('CephfsTabsComponent', () => { }; service = TestBed.get(CephfsService); spyOn(service, 'getTabs').and.callFake(() => of(data)); - selectFs(1, 'firstMds'); + fixture.detectChanges(); + mockRunOutside(); + setReload(); // Clears rxjs timer subscription }); it('should create', () => { @@ -126,6 +146,7 @@ describe('CephfsTabsComponent', () => { data: [], status: ViewCacheStatus.ValueNone }; + component['subscribeInterval'] = () => {}; updateData(); expect(component.clients).not.toEqual(defaultClients); expect(component.details).not.toEqual(defaultDetails); @@ -144,23 +165,7 @@ describe('CephfsTabsComponent', () => { }); describe('handling of id change', () => { - let old: any; - const getReload = () => component['reloadSubscriber']; - const setReload = (sth?) => (component['reloadSubscriber'] = sth); - beforeEach(() => { - spyOn(TestBed.get(NgZone), 'runOutsideAngular').and.callFake(() => { - // It's mocked because the rxjs timer subscription ins't called through the use of 'tick'. - setReload({ - unsubscribed: false, - unsubscribe: () => { - old = getReload(); - getReload().unsubscribed = true; - setReload(); - } - }); - component.refresh(); - }); setReload(); // Clears rxjs timer subscription selectFs(2, 'otherMds'); old = getReload(); // Gets current subscription @@ -172,7 +177,11 @@ describe('CephfsTabsComponent', () => { }); it('should not subscribe to an new interval for the same selection', () => { + expect(component.id).toBe(2); + expect(component.grafanaId).toBe('otherMds'); selectFs(2, 'otherMds'); + expect(component.id).toBe(2); + expect(component.grafanaId).toBe('otherMds'); expect(getReload()).toBe(old); }); -- 2.39.5