]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Fixes random cephfs tab test failure 30814/head
authorStephan Müller <smueller@suse.com>
Wed, 9 Oct 2019 15:47:36 +0000 (17:47 +0200)
committerStephan Müller <smueller@suse.com>
Thu, 10 Oct 2019 08:36:47 +0000 (10:36 +0200)
Fixes: https://tracker.ceph.com/issues/42077
Signed-off-by: Stephan Müller <smueller@suse.com>
src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-tabs/cephfs-tabs.component.spec.ts

index 68895dc05af8a15e8a9ffc9bf19069a1b625ae47..e0b3258b90fa4f833882ec03706441b92e56e25c 100644 (file)
@@ -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);
     });