Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
100 lines (87 loc) · 3.83 KB
/
Copy pathscript.js
File metadata and controls
100 lines (87 loc) · 3.83 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { TestRegistration, TestPhoneRegistration, TestEmailRegistration } from './testCases/registerTest.js';
import { TestLogin, TestEmailLogin, TestPhoneLogin } from './testCases/loginTest.js';
import { TestUpdateAccount } from './testCases/updateAccountTest.js';
import { TestUpload } from './testCases/uploadFileTest.js';
import { TestLinkCredential, TestLinkEmail, TestLinkPhone } from './testCases/linkPhoneNumberOrEmailTest.js';
import { TestFriends } from './testCases/friendsTest.js';
import { TestPost } from './testCases/postTest.js';
import { TestPostComment } from './testCases/postCommentTest.js';
export const options = {
// A number specifying the number of VUs to run concurrently.
vus: 1,
// A string specifying the total duration of the test run.
iterations: 1,
};
// The function that defines VU logic.
//
// See https://grafana.com/docs/k6/latest/examples/get-started-with-k6/ to learn more
// about authoring k6 scripts.
//
export default function () {
// eslint-disable-next-line no-undef
const ONLY_POSITIVE_CASE = __ENV.ONLY_POSITIVE ? true : false
// eslint-disable-next-line no-undef
const REAL_WORLD_CASE = __ENV.REAL_WORLD_CASE ? true : false;
if (REAL_WORLD_CASE) {
// 30% of users have negative cases
const runPositiveCase = Math.random() > 0.3 ? true : false;
let userByPhone = null;
let userByEmail = null;
let user = null;
// 70% of users use phone registration
if (Math.random() > 0.3) {
userByPhone = TestPhoneRegistration(!runPositiveCase);
} else {
userByEmail = TestEmailRegistration(!runPositiveCase);
}
// for each of the user, run login once
if (userByPhone) {
userByPhone = TestPhoneLogin(userByPhone, !runPositiveCase);
}
if (userByEmail) {
userByEmail = TestEmailLogin(userByEmail, !runPositiveCase);
}
if ((userByPhone || userByEmail) && Math.random() > 0.5) {
// 50% of the user add a friend
TestFriends(userByPhone || userByEmail, !runPositiveCase);
if (Math.random() > 0.3) {
// 70% of the user that add a friend, post something
TestUpload(userByPhone || userByEmail, !runPositiveCase);
const usrPos = TestPost(userByPhone || userByEmail, !runPositiveCase);
if (Math.random() > 0.3) {
// 70% of the user that add a friend and post something, will comment
TestPostComment(usrPos, !runPositiveCase);
}
}
if ((userByPhone || userByEmail) && Math.random() > 0.5) {
// 50% of the user that registers and add a friend, change their credential
if (userByPhone) {
user = TestLinkEmail(userByPhone, !runPositiveCase);
}
if (userByEmail) {
user = TestLinkPhone(userByEmail, !runPositiveCase);
}
if (Math.random() > 0.5 && user) {
// 50% of the users that add a friend and link their credential, update their account
TestUpdateAccount(user, !runPositiveCase);
}
}
}
} else {
let userByPhone, userByEmail = null
// add loop in order to test add friend feature
for (let index = 0; index < 50; index++) {
[userByPhone, userByEmail] = TestRegistration(!ONLY_POSITIVE_CASE);
if (!userByPhone || !userByEmail) return;
[userByPhone, userByEmail] = TestLogin(userByPhone, userByEmail, !ONLY_POSITIVE_CASE);
if (!userByPhone || !userByEmail) return;
}
[userByPhone, userByEmail] = TestLinkCredential(userByPhone, userByEmail, !ONLY_POSITIVE_CASE);
if (!userByPhone || !userByEmail) return;
userByPhone = TestUpdateAccount(userByPhone, !ONLY_POSITIVE_CASE);
userByPhone = TestUpload(userByPhone, !ONLY_POSITIVE_CASE);
userByPhone = TestFriends(userByPhone, !ONLY_POSITIVE_CASE);
userByPhone = TestPost(userByPhone, !ONLY_POSITIVE_CASE);
userByPhone = TestPostComment(userByPhone, !ONLY_POSITIVE_CASE);
}
}