From 3c6cbd40e297b397abe6d942b3c7d8f31062e348 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Mon, 2 Feb 2015 16:08:29 +0900 Subject: [PATCH] Fix an sporadic failure in ServerCookieEncoderTest In testEncodingSingleCookieV0(): Let's assume we encoded a cookie with MaxAge=50 when currentTimeMillis is 10999. Because the encoder will not encode the millisecond part for Expires, the timeMillis value of the encoded Expires field will be 60000. (If we did not dropped the millisecond part, it would be 60999.) Encoding a cookie will take some time, so currentTimeMillis will increase slightly, such as to 11001. diff = (60000 - 11001) / 1000 = 48999 / 1000 = 48 maxAge - diff = 50 - 48 = 2 Due to losing millisecond part twice, we end up with the precision problem illustrated above, and thus we should increase the tolerance from 1 second to 2 seconds. /cc @slandelle --- .../io/netty/handler/codec/http/ServerCookieEncoderTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/ServerCookieEncoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/ServerCookieEncoderTest.java index d30278ba4b..bcdee4e1b8 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/ServerCookieEncoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/ServerCookieEncoderTest.java @@ -46,8 +46,8 @@ public class ServerCookieEncoderTest { assertTrue(matcher.find()); Date expiresDate = HttpHeaderDateFormat.get().parse(matcher.group(1)); long diff = (expiresDate.getTime() - System.currentTimeMillis()) / 1000; - // 1 sec should be fine - assertTrue(Math.abs(diff - maxAge) <= 1); + // 2 secs should be fine + assertTrue(Math.abs(diff - maxAge) <= 2); } @Test