-
Notifications
You must be signed in to change notification settings - Fork 6
/
memory.spec
78 lines (67 loc) · 2.82 KB
/
memory.spec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// In your test suite, use this code to include the test library.
// var sgpt = require('sg-protractor-tools');
// Using the local version of the code from this project.
var sgpt = require('../../../');
/**
* Note: Do not run both test cases simultaneously, as even after page reload memory consumption might be influenced
* from previous pages. This might falsify the results.
* Best results with memory measurement will be revealed when running this test suite using ddescribe() and
* only one test case by commenting the other one(s) using xit().
*/
describe('Demonstrate the use of memory measuring tool', function () {
// Get the messager object to display current test execution status inside the browser
var msg = sgpt.messager.msg;
// Set to a high value to avoid timeout by Protractor for this it test.
var itTimeout = 1000000;
function leakFunction() {
var leakProduceButton = element(by.css('#leakProducer'));
leakProduceButton.click();
}
function nonLeakFunction() {
var nonLeakingProduceButton = element(by.css('#m_1'));
nonLeakingProduceButton.click();
}
it('should increase the memory consumption when invoking a leaking function', function () {
var iterations = 250;
browser.sleep(1000);
var that = this;
browser.get('#/memoryTest', 30000).then(function () {
sgpt.memory.runTestFunction(that, iterations, function (i) {
if (i % 10 === 0) {
// Every ten iterations update the label
msg(browser, 'Button click iteration ' + i, undefined, 0);
}
leakFunction();
},
// pass in override for default options
{
preTestInitFunction: function () {
leakFunction();
}
}
);
});
}, itTimeout);
xit('should not increase the memory consumption when invoking a non-leaking function', function () {
var iterations = 250;
//Set A Baseline for memory consumption
browser.sleep(1000);
var that = this;
browser.get('#/memoryTest', 30000).then(function () {
sgpt.memory.runTestFunction(that, iterations, function (i) {
if (i % 10 === 0) {
// Every ten iterations update the label
msg(browser, 'Button click iteration ' + i, undefined, 0);
}
nonLeakFunction();
},
// pass in override for default options
{
preTestInitFunction: function () {
nonLeakFunction();
}
}
);
});
}, itTimeout);
});