Aggro on the streets: Armed police arrest England and Argentina fans in Atlanta as fans cause chaos in London following Three Lions' loss
Cruz Beckham's Brazilian girlfriend Jackie Apostel, 30, proves her loyalty to England in a Three Lions shirt as she consoles boyfriend, 21, and his family during World Cup semi-final defeat
CodeSOD: Wait Longer
Karen was maintaining some specification tests that were flaky. Not extremely flaky, but three or four times out of a thousand, the tests would just fail. The tests were complicated, and some of the operations were timing sensitive, so it wasn't precisely surprising- but the problem was that they were actually generous with their timing windows. The unit tests passed consistently, it was only these functional, specification-based tests that failed.
So, for example, there were sections in the tests where they wanted to wait at least 2ms. Since the code and tests were in TypeScript, they used the setTimeout function, which per standard JavaScript documentation warns that it may wait longer. But again, Karen was fine with longer.
Unfortunately for Karen, the documentation for NodeJS is less specific, as it makes no guarantees about when the timeout function gets invoked. This means that it can fire the timeout before the time has elapsed.
After many, many hours of debugging, that was exactly the situation that Karen found herself in. Which is why her very simple wait function went from:
export const wait = (ms:number) => new Promise((complete) => setTimeout(complete, ms));To the much more awkward:
export const wait = (ms: number) { const target = performance.now() + ms; return new Promise((complete) => { const checkReady = () => { if (performance.now() > target) { complete(); } else { setTimeout(checkReady, 1); } } setTimeout(checkReady, 1); }); }This version of the function checks the time every millisecond, and only completes the operation if we've waited at least as long as our target duration. This ensures that the timeout never fires too soon and it fixes the janky tests. But it's also terrible. Terrible that it exists. Terrible that this is the best solution. Terrible that our functional tests need to be so time sensitive. And terrible that the Node runtime actually breaks the one consistent scheduling guarantee that pretty much every other scheduler does: that it'll wait at least as long as you asked, but might wait much longer.
At best, we can say, "at least it's only testing code."
[Advertisement] Picking up NuGet is easy. Getting good at it takes time. Download our guide to learn the best practice of NuGet for the Enterprise.Tech support scam caused massive data breach at Australian airline Qantas
US unleashes strikes near Tehran and targets a ship breaking the blockade as Trump threatens to 'finish it off'
School term dates in Essex could be changed to make family holidays cheaper
JANE FRYER: History, politics, national pride... for so many reasons, we won't EVER cry for you, Argentina
They came, they saw and they roared. Then that all-too-familiar silence descended, writes FRED KELLY
Get hitched at home, in the pub or on the beach under major reforms of marriage laws - but no skydiving or rollercoaster ceremonies allowed
Even HP resellers thought the price of toner and ink was too high – so HP India facilitated an illegal cartel
Essex nurse sacked after multiple incidents that 'harmed patients'
Albanian serial burglar who returned to Britain each winter to steal from more victims is jailed for 10 years
England WAGs weep in the stands: Megan Pickford consoles her husband Jordan after Argentina World Cup semi-final defeat
11 gull chicks released into the wild after weeks of hand-rearing
Epic 39-hour 100-mile trek sees Essex friends conquer castles for charity
The Essex road 'like a racetrack' residents say is a 'tragedy waiting to happen'
US Suffered a Major Power Outage Every Month of 2026
Read more of this story at Slashdot.