Skip to content

Commit 72adcdc

Browse files
authored
Merge pull request #18 from webxdc/simon/fix17
add test for Duplicated Updates Race
2 parents 4add6f7 + fdacf5c commit 72adcdc

2 files changed

Lines changed: 70 additions & 0 deletions

File tree

duplicated_updates_race.html

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>test webxdc - duplicated updates race test</title>
8+
<script src="webxdc.js"></script>
9+
</head>
10+
<body>
11+
<a href="./index.html">&lt; Back</a>
12+
13+
<h1>Duplicated Updates Race Test</h1>
14+
<p>
15+
At the time of writing this test desktop has a bug that each update causes
16+
sending all new update from the update's serial onwards, which results in
17+
updates getting processed multiple times, which can confuse your webxdc
18+
app if it does not account for it.
19+
<br /><br />Read More deltachat-desktop#3296
20+
</p>
21+
22+
<div id="updates" style="max-height: 50vh; overflow-y: scroll"></div>
23+
24+
<script>
25+
const updatesDiv = document.getElementById("updates");
26+
let known_ids = [];
27+
let batch = [];
28+
let active = false;
29+
window.webxdc.setUpdateListener((update) => {
30+
batch.push(update.serial);
31+
32+
if (!known_ids.includes(update.serial)) {
33+
known_ids.push(update.serial);
34+
} else {
35+
const note = document.createElement("div");
36+
note.innerText = `(Processing duplicated update ${update.serial})`;
37+
updatesDiv.appendChild(note);
38+
}
39+
40+
if (update.serial === update.max_serial) {
41+
if (active) {
42+
const updateBatch = document.createElement("div");
43+
updateBatch.innerText = `[${batch.join(",")}]`;
44+
updatesDiv.appendChild(updateBatch);
45+
}
46+
batch = [];
47+
updatesDiv.scrollTop = updatesDiv.scrollHeight;
48+
}
49+
}, 0);
50+
function try_to_trigger_update_race() {
51+
active = true;
52+
window.webxdc.sendUpdate({ payload: "race test" }, "race test");
53+
window.webxdc.sendUpdate({ payload: "race test" }, "race test");
54+
window.webxdc.sendUpdate({ payload: "race test" }, "race test");
55+
}
56+
</script>
57+
<button onclick="try_to_trigger_update_race()">
58+
Try to trigger update race
59+
</button>
60+
</body>
61+
</html>

index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@
4646
<script src="js/webrtc.js"></script>
4747
<iframe src="./iframe-webrtc-test.html" sandbox="allow-scripts" width="100%" height="200"></iframe>
4848

49+
<div class="card">
50+
<header class="container"><h2>Webxdc Status Update Tests</h2></header>
51+
<div class="container">
52+
<a href="./duplicated_updates_race.html">
53+
Duplicated Status Updates Race Test
54+
</a>
55+
</div>
56+
</div>
57+
4958
<!-- debugging -->
5059
<script src="js/eruda.min.js"></script>
5160
<script>window.addEventListener("load", () => eruda.init());</script>

0 commit comments

Comments
 (0)