-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathrace.test.js
55 lines (41 loc) · 1.72 KB
/
race.test.js
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
const baseUrl = "https://js-slash-z.herokuapp.com";
async function generateNewMeeting() {
const response = await fetch(`${baseUrl}/api/endpoints/new-schedule-link`);
const result = await response.json();
return result.id;
}
// sends n parallel requests to schedule link with id
// returns the number of unique zoom calls that were started
async function openParallelCalls(n, id) {
const requests = [];
for (let i = 0; i < n; i++) {
const request = fetch(`${baseUrl}/api/endpoints/schedule-link?id=${id}`);
requests.push(request);
}
const responses = await Promise.all(requests);
const results = await Promise.all(responses.map(res => res.text()));
const zoomUrls = results.map(result => {
// find the index of the meta containing the zoom url
const matchZoom = new RegExp(/<meta property="og:url"+/);
const _result = matchZoom.exec(result);
// get the meta tag with the zoom call link
const zoomurl = result.slice(_result.index, _result.index + 110);
console.log("Zoom Meta = ", zoomurl);
console.log("-----------------------");
return zoomurl;
});
const urlSet = new Set(zoomUrls);
console.log("Unique calls = ", urlSet.size);
return urlSet.size;
}
// checks for the number of open meetings
async function getOpenMeetings() {
const omReq = await fetch(`${baseUrl}/api/endpoints/stats`);
const omRes = await omReq.json();
console.log("Open calls = ", omRes.hosts.open);
}
test("Concurrent join requests does not lead to different calls", async () => {
const meetingName = await generateNewMeeting();
const numCalls = await openParallelCalls(2, meetingName);
expect(numCalls).toBe(1);
}, 6000);