Skip to content

Commit b88c065

Browse files
committed
Browserstack tests for session ID
1 parent 36f417b commit b88c065

File tree

3 files changed

+46
-12
lines changed

3 files changed

+46
-12
lines changed

automation/compat/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
<title>Glean Benchmarks Sample</title>
88
</head>
99
<body>
10-
<p id="msg"></p>
10+
<p id="ping_msg"></p>
11+
<p id="session_msg"></p>
1112
<script src="./dist/index.js"></script>
1213
</body>
1314
</html>

automation/compat/index.js

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,12 @@ import Glean from "@mozilla/glean/web";
88
import { benchmark } from "./generated/pings.js";
99
import * as metrics from "./generated/sample.js";
1010

11-
Glean.setSourceTags(["automation"]);
12-
Glean.initialize("glean-compat-benchmark", true, {
13-
enableAutoPageLoadEvents: true
14-
});
15-
16-
metrics.pageLoaded.set();
17-
benchmark.submit();
18-
1911
// !BIG HACK!
2012
//
2113
// Overwrite the console.info function in order to know when (and if) the benchmark ping was sent.
2214
// If a success ping message is logged we show that in the document.
2315
let pingSubmissionCount = 0;
16+
let sessionId = "";
2417
console.info = function () {
2518
var message = "";
2619
for (var i = 0; i < arguments.length; i++) {
@@ -30,6 +23,7 @@ console.info = function () {
3023
message += " ";
3124
}
3225
}
26+
3327
console.log(message);
3428
if (/successfully sent 200.$/.test(message)) {
3529
pingSubmissionCount++;
@@ -38,8 +32,40 @@ console.info = function () {
3832
// 1. The built-in page_load event, which submits an events ping.
3933
// 2. The benchmark ping.
4034
if (pingSubmissionCount == 2) {
41-
var elem = document.getElementById("msg");
35+
var elem = document.getElementById("ping_msg");
4236
elem.innerHTML = "Pings submitted successfully.";
4337
}
4438
}
39+
40+
const sessionRegex = /"session_id": .+"/;
41+
const sessionInfo = sessionRegex.exec(message);
42+
if (!!sessionInfo) {
43+
const currSessionId = sessionInfo?.[0].split(`"`)?.[3];
44+
if (!!sessionId) {
45+
if (currSessionId !== sessionId) {
46+
var elem = document.getElementById("session_msg");
47+
elem.innerHTML = "Session IDs updated successfully.";
48+
} else {
49+
console.log("Something went wrong...");
50+
}
51+
}
52+
53+
sessionId = currSessionId;
54+
}
4555
}
56+
57+
Glean.setSourceTags(["automation"]);
58+
59+
// This needs to be set so we can pull the session ID from the log messages.
60+
Glean.setLogPings(true);
61+
62+
Glean.initialize("glean-compat-benchmark", true, {
63+
enableAutoPageLoadEvents: true,
64+
// Setting the override to 0 means every action will trigger
65+
// a new session. We use this to check that the session ID
66+
// changes whenever a session has expired.
67+
sessionLengthInMinutesOverride: 0
68+
});
69+
70+
metrics.pageLoaded.set();
71+
benchmark.submit();

automation/compat/tests/utils.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export async function runWebTest(driver) {
7373
// will receive the text "Ping submitted successfully."
7474
await driver.get(`http://localhost:${PORT}/`);
7575
// Give it time to send the ping request.
76-
const successTextContainer = await driver.findElement(By.id("msg"));
76+
const pingTextContainer = await driver.findElement(By.id("ping_msg"));
7777

7878
const areGleanWindowVarsSet = await driver.executeScript(() => {
7979
// Verify that all Glean `window` vars are properly set.
@@ -100,10 +100,17 @@ export async function runWebTest(driver) {
100100

101101
await driver.wait(
102102
until.elementTextIs(
103-
successTextContainer,
103+
pingTextContainer,
104104
"Pings submitted successfully."
105105
), 11_000); // 1s more than the default upload timeout in Glean.
106106

107+
const sessionTextContainer = await driver.findElement(By.id("session_msg"));
108+
await driver.wait(
109+
until.elementTextIs(
110+
sessionTextContainer,
111+
"Session IDs updated successfully."
112+
), 1000);
113+
107114
console.log("Test passed.");
108115
} catch(e) {
109116
console.log("Test failed.", e);

0 commit comments

Comments
 (0)