Skip to content

Commit 7ebd26a

Browse files
committed
test case
1 parent 07c632a commit 7ebd26a

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

api/src/org/labkey/api/data/dialect/SqlDialect.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
import java.util.regex.Pattern;
9999

100100
import static org.junit.Assert.assertEquals;
101+
import static org.junit.Assert.assertFalse;
101102
import static org.junit.Assert.assertThrows;
102103
import static org.junit.Assert.assertTrue;
103104

@@ -2460,5 +2461,37 @@ public void testProcedureIdentifierQuoting()
24602461
// A dotted name is rejected: schema and procedure are separate parameters, so a '.' in a single component is an ambiguous schema-qualified reference
24612462
assertThrows(IllegalArgumentException.class, () -> dialect.buildProcedureCall(core.getName(), "a.b", 0, false, false, scope));
24622463
}
2464+
2465+
// GH Issue #1223: Verify the server/database clock-skew arithmetic and warning threshold
2466+
@Test
2467+
public void testServerDatabaseTimeDifference()
2468+
{
2469+
LocalDateTime base = LocalDateTime.of(2026, 7, 6, 12, 0, 0);
2470+
2471+
// Identical times: zero difference, no warning
2472+
ServerDatabaseTimeDifference equal = new ServerDatabaseTimeDifference(base, base);
2473+
assertEquals(0, equal.getSeconds());
2474+
assertFalse(equal.exceedsWarningThreshold());
2475+
2476+
// Comfortably below the threshold: no warning
2477+
ServerDatabaseTimeDifference below = new ServerDatabaseTimeDifference(base, base.plusSeconds(5));
2478+
assertEquals(5, below.getSeconds());
2479+
assertFalse(below.exceedsWarningThreshold());
2480+
2481+
// Exactly at the threshold: no warning (comparison is strictly greater-than)
2482+
ServerDatabaseTimeDifference atThreshold = new ServerDatabaseTimeDifference(base, base.plusSeconds(TIME_DIFFERENCE_WARNING_SECONDS));
2483+
assertEquals(TIME_DIFFERENCE_WARNING_SECONDS, atThreshold.getSeconds());
2484+
assertFalse(atThreshold.exceedsWarningThreshold());
2485+
2486+
// Just past the threshold: warning
2487+
ServerDatabaseTimeDifference over = new ServerDatabaseTimeDifference(base, base.plusSeconds(TIME_DIFFERENCE_WARNING_SECONDS + 1));
2488+
assertEquals(TIME_DIFFERENCE_WARNING_SECONDS + 1, over.getSeconds());
2489+
assertTrue(over.exceedsWarningThreshold());
2490+
2491+
// Difference is absolute: database clock behind the web server is treated the same as ahead
2492+
ServerDatabaseTimeDifference behind = new ServerDatabaseTimeDifference(base, base.minusSeconds(TIME_DIFFERENCE_WARNING_SECONDS + 1));
2493+
assertEquals(TIME_DIFFERENCE_WARNING_SECONDS + 1, behind.getSeconds());
2494+
assertTrue(behind.exceedsWarningThreshold());
2495+
}
24632496
}
24642497
}

0 commit comments

Comments
 (0)