|
@@ -1,47 +1,67 @@
|
1
|
|
-import EventEmitter from 'events';
|
2
|
1
|
|
3
|
|
-import JitsiConference from '../../JitsiConference';
|
4
|
2
|
import * as JitsiConferenceEvents from '../../JitsiConferenceEvents';
|
5
|
3
|
import browser from '../browser';
|
|
4
|
+import Listenable from '../util/Listenable';
|
6
|
5
|
|
7
|
6
|
import Statistics from './statistics';
|
8
|
7
|
|
9
|
8
|
/**
|
10
|
9
|
* Mock object to be used in place of a real conference.
|
11
|
10
|
*
|
12
|
|
- * @constructor
|
13
|
11
|
*/
|
14
|
|
-function MockConference() {
|
15
|
|
- this.eventEmitter = new EventEmitter();
|
|
12
|
+class MockConference extends Listenable {
|
|
13
|
+ /**
|
|
14
|
+ * constructor
|
|
15
|
+ */
|
|
16
|
+ constructor() {
|
|
17
|
+ super();
|
|
18
|
+ this.options = {
|
|
19
|
+ config: {}
|
|
20
|
+ };
|
|
21
|
+ }
|
16
|
22
|
}
|
17
|
|
-MockConference.prototype = Object.create(JitsiConference.prototype);
|
18
|
|
-MockConference.prototype.constructor = JitsiConference;
|
19
|
23
|
|
20
|
24
|
describe('PerformanceObserverStats', () => {
|
|
25
|
+ let mockConference, statistics;
|
|
26
|
+
|
21
|
27
|
beforeEach(() => {
|
22
|
28
|
// works only on chrome.
|
23
|
29
|
spyOn(browser, 'isChrome').and.returnValue(true);
|
|
30
|
+ mockConference = new MockConference();
|
|
31
|
+ Statistics.init({ longTasksStatsInterval: 1000 });
|
|
32
|
+ statistics = new Statistics();
|
|
33
|
+ jasmine.clock().install();
|
24
|
34
|
});
|
25
|
35
|
|
26
|
|
- it('Emits performance stats every sec', () => {
|
27
|
|
- const mockConference = new MockConference();
|
28
|
|
- const statistics = new Statistics();
|
29
|
|
-
|
|
36
|
+ it('Conference events start/stop observer', () => {
|
30
|
37
|
statistics.attachLongTasksStats(mockConference);
|
31
|
|
-
|
32
|
38
|
const startObserverSpy = spyOn(statistics.performanceObserverStats, 'startObserver');
|
33
|
39
|
const stopObserverSpy = spyOn(statistics.performanceObserverStats, 'stopObserver');
|
34
|
|
- const addNextSpy = spyOn(statistics.performanceObserverStats.stats, 'addNext');
|
35
|
40
|
|
36
|
41
|
mockConference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_JOINED);
|
37
|
42
|
expect(startObserverSpy).toHaveBeenCalled();
|
38
|
|
- expect(statistics.performanceObserverStats.getLongTasksStats()).toBeTruthy();
|
39
|
|
-
|
40
|
|
- setTimeout(() => {
|
41
|
|
- expect(addNextSpy).toHaveBeenCalled();
|
42
|
|
- }, 1000);
|
43
|
43
|
|
44
|
44
|
mockConference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_LEFT);
|
45
|
45
|
expect(stopObserverSpy).toHaveBeenCalled();
|
46
|
46
|
});
|
|
47
|
+
|
|
48
|
+ it('Emits long tasks stats every sec', () => {
|
|
49
|
+ statistics.attachLongTasksStats(mockConference);
|
|
50
|
+ statistics.performanceObserverStats.eventEmitter = {
|
|
51
|
+ // eslint-disable-next-line no-empty-function
|
|
52
|
+ emit: () => {}
|
|
53
|
+ };
|
|
54
|
+ statistics.performanceObserverStats.startObserver();
|
|
55
|
+ const eventEmitSpy = spyOn(statistics.performanceObserverStats.eventEmitter, 'emit');
|
|
56
|
+
|
|
57
|
+ expect(statistics.performanceObserverStats.getLongTasksStats()).toBeTruthy();
|
|
58
|
+ expect(eventEmitSpy).not.toHaveBeenCalled();
|
|
59
|
+
|
|
60
|
+ jasmine.clock().tick(1000);
|
|
61
|
+ expect(eventEmitSpy).toHaveBeenCalled();
|
|
62
|
+ });
|
|
63
|
+
|
|
64
|
+ afterEach(() => {
|
|
65
|
+ jasmine.clock().uninstall();
|
|
66
|
+ });
|
47
|
67
|
});
|