|
| 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">< 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> |
0 commit comments