Skip to content

Commit e4ab052

Browse files
Jake ChampionJakeChampion
authored andcommitted
Add test to confirm Math.random generates different first 3 decimal places
https://fastly.atlassian.net/browse/ECP-745
1 parent 61fdf4c commit e4ab052

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# This file describes a Fastly Compute@Edge package. To learn more visit:
2+
# https://developer.fastly.com/reference/fastly-toml/
3+
4+
authors = ["[email protected]"]
5+
description = ""
6+
language = "javascript"
7+
manifest_version = 2
8+
name = "random"
9+
service_id = ""
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function random3Decimals() {
2+
return String(Math.random()).slice(0, 5);
3+
}
4+
5+
let a = random3Decimals();
6+
let b = random3Decimals();
7+
8+
addEventListener("fetch", event => {
9+
if (a === b) {
10+
return event.respondWith(new Response('The first 4 digits were repeated in sequential calls to Math.random() during wizening\n\n' + JSON.stringify({ a, b }, undefined, 4), { status: 500 }));
11+
}
12+
13+
let c = random3Decimals();
14+
let d = random3Decimals();
15+
if (c === d) {
16+
return event.respondWith(new Response('The first 4 digits were repeated in sequential calls to Math.random() during request handling\n\n' + JSON.stringify({ c, d }, undefined, 4), { status: 500 }));
17+
}
18+
19+
20+
return event.respondWith(new Response(JSON.stringify({ initialisedResults: [a, b], results: [c, d] }, undefined, 4)));
21+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"GET /": {
3+
"environments": ["viceroy", "c@e"],
4+
"downstream_request": {
5+
"method": "GET",
6+
"pathname": "/"
7+
},
8+
"downstream_response": {
9+
"status": 200,
10+
"body": ""
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)