Occasional Date or timezone discrepancy in hudson or maven with jodatime

Posted by TheStijn on Stack Overflow See other posts from Stack Overflow or by TheStijn
Published on 2011-01-14T12:48:25Z Indexed on 2011/01/14 12:53 UTC
Read the original article Hit count: 397

hi,

I hope following explanation will make sense because it's a weird problem we're facing and hard to describe.

We have a maven project which gets build in hudson and that contains some unit tests where dates are used and asserted. The hudson server runs on solaris. Now, occasionally (like 30% of the times) the unit tests using dates fail because 3,5 hours are deducted from the specified time in the unit test and hence asserts start failing. The other 70% everything works fine although nothing at all changed in the code and we run the hudson job several times an hour.

I add following code to a unittest to check the time:

@Test
public void testDate() {
    System.out.println("new DateMidnight(2011, 1, 5).toDate();");
    System.out.println(new DateMidnight(2011, 1, 5).toDate());
    System.out.println(new DateMidnight(2011, 1, 5).toDate().getTime());

    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, 2011);
    cal.set(Calendar.MONTH, 0);
    cal.set(Calendar.DAY_OF_MONTH, 5);
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    System.out.println("cal.getTime();");
    System.out.println(cal.getTime());
    System.out.println(cal.getTime().getTime());
}

So basically it should print the same thing when using jodatime or plain old Calendar. This is the case in 70% of the runs; for the other 30% I get following printouts:

Running TestSuite
new DateMidnight(2011, 1, 5).toDate();
Tue Jan 04 21:30:00 MET 2011
1294173000000
cal.getTime();
Wed Jan 05 12:00:00 MET 2011
1294225200000

Local maven tests never appear the pose this problem and we can't figure out what could be the cause of it. Especially, we can't think of a single reason why the tests sometimes pass and sometimes fail without changing any code nor hudson or server setting.

Also, we run the maven install with cobertura which means that the unit tests are run twice. It happens also that they pass the first time and fail the second time or the other way around or that they fail both times.

Thanks for any help, Stijn

© Stack Overflow or respective owner

Related posts about unit-testing

Related posts about datetime