Urgent.News

What's breaking now, across thousands of outlets.

Tech

The test that failed every morning and passed every afternoon

Originally published on the WatchNext blog . While making an unrelated change — adding a processor to a privacy page and a link to a footer — the test suite came back with eleven passes and one failure: - 1 + 2 ❯ tests/airDate.test.ts:125:47 125| expect(getAirDateDaysDiff(plus(1), "US")).toBe(1); | ^ An episode airing tomorrow was being counted as two days away. That is about as load-bearing as a…

The test suite in a software application failed unexpectedly after a seemingly unrelated change was made. The failure occurred because a test case was counting the next episode airing as two days away instead of one, due to a mismatch between how dates were being measured in the test and the actual function. The test was designed to check the day arithmetic for an episode's air date, but it was using UTC time while the function calculated days based on the show's location in the United States.

This discrepancy caused the test to fail intermittently during specific time windows when the UTC date rolled over to a new day while the Los Angeles time did not. The issue was traced to the test using the `toISOString()` method, which always formats dates in UTC, while the function used the `DateTime.now().setZone(zone)` method to calculate days based on the user's timezone.

The fix involved adjusting the test to use the same timezone as the function, ensuring both measured days consistently. However, this fix also rendered the test unable to catch future issues related to the timezone mapping, as it now derived the timezone from the same table the code used. Despite this limitation, the fix successfully eliminated the intermittent failure, ensuring that the test accurately reflected the intended behavior of the day arithmetic function.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

A Dialog Can Now Be a Native Desktop Window

Last week's native-window release could open an editor, inspector, and tool palette as separate operating-system windows.

  • Dialogs can now function as native desktop windows in Codename One framework.
  • Dialog.setDefaultNativeWindowMode(true) enables dialog to be a native window.
  • Transition handling and accessibility state preserved across Windows and Mac platforms.

Why Timestamps Lie in Distributed Systems (and How Logical Clocks Fix It)

There's a line of code in almost every service that stores replicated data: def resolve ( incoming , stored ): # keep whichever write is "newer" return incoming if incoming . timestamp > stored . timestamp else stored It passes review. It passes tests. It behaves perfectly on your laptop, in CI, and in staging.

  • Timestamps lie in distributed systems, leading to last-write-wins (LWW) corruption
  • Lamport clocks introduce causal order using integer per process, resolving conflicts

More from Saturday 12 September →