为什么在Jenkins部署期间的12点至1点之间会导致JUnit测试失败?

huangapple 未分类评论55阅读模式
英文:

Why would a JUnit Test fail between 12 - 1pm during Jenkins deployment?

问题

以下是您提供的内容的翻译部分:

我有一个 JUnit 测试,用于查找在过去的 355 天内未更改密码的用户。在测试中,我将用户的最后密码更新日期保存为系统的日期/时间 - 355 天。然后我运行应该处理该用户的附加处理的函数。

这个测试在本地通过,无论是单独运行测试还是运行整个测试套件时都通过。然而,由于某种原因,在将我们的代码部署到 Jenkins 中时,在中午 12 点到下午 1 点之间测试会失败。这并不是一次性的失败。有时候,仅仅再次部署相同的代码而没有任何更改就可以使测试成功。是什么原因导致了这个问题呢?

供参考,该测试如下:

@Test
public void passwordExpiryTest() {
    Timestamp currentTimeMinus355Days = new Timestamp(System.currentTimeMillis() - 30672000000L);
    createUser("expiringUser", currentTimeMinus355Days);
    createUser("recentUser", new Timestamp(System.currentTimeMillis() - 864000000L));
    List<User> passwordExpiringUsers = userDao.getUsersWithPasswordExpiringInTenDays();
    Assert.assertEquals(1, passwordExpiringUsers.size());
}

而 userDao.getUsersWithPasswordExpiringInTenDays 是一个 SQL 查询(查询一个 Postgres 表):

SELECT * FROM users WHERE last_password_update IS NOT NULL AND EXTRACT(epoch FROM (NOW() - last_password_update))/86400 >= 355 AND EXTRACT(epoch FROM (NOW() - last_password_update))/86400 <= 356")
英文:

I have a JUnit test that looks for a user that hasn't changed their password in the past 355 days. In the test, I save a user with their last password update date to the system's date/time - 355 days. Then I run the function that should pick up that user for additional processing.

The test passes locally, both when the test is run on its own AND when the entire test suite is run. However, for some reason, the test fails between 12 - 1pm when deploying our code in Jenkins. It's not a consistent failure, either. Sometimes, simply running the deployment again with no changes allows the test to succeed. What could be causing this issue?

For reference, the test looks like:

@Test
   public void passwordExpiryTest() {
    Timestamp currentTimeMinus355Days = new Timestamp(System.currentTimeMillis() - 30672000000L);
    createUser(&quot;expiringUser&quot;, currentTimeMinus355Days);
    createUser(&quot;recentUser&quot;, new Timestamp(System.currentTimeMillis() - 864000000L));
    List&lt;User&gt; passwordExpiringUsers = userDao.getUsersWithPasswordExpiringInTenDays();
    Assert.assertEquals(1, passwordExpiringUsers.size());
}

And userDao.getUsersWithPasswordExpiringInTenDays is a SQL query (into a Postgres table):

SELECT * FROM users WHERE last_password_update IS NOT NULL AND EXTRACT(epoch FROM (NOW() - last_password_update))/86400 &gt;= 355 AND EXTRACT(epoch FROM (NOW() - last_password_update))/86400 &lt;= 356&quot;)

答案1

得分: 0

我会调查userDao.getUsersWithPasswordExpiringInTenDays()方法中的逻辑。关于“天”的概念取决于解释——是指24小时,还是下一天的编号(例如四月的11号与12号之间)?时间区域是否会产生影响?例如,您在印度进行测试,但服务器位于美国(相差12小时的时区)?

英文:

I would investigate the logic in userDao.getUsersWithPasswordExpiringInTenDays(). The concept of a "day" depends on an interpretation - is it 24 hours, or the next day number (e.g. 11 vs 12 of April?)? And is there an impact of time zones? e.g. are you testing in India, but the server lives in the US (12 hours time difference?)

huangapple
  • 本文由 发表于 2020年4月7日 22:05:13
  • 转载请务必保留本文链接:https://java.coder-hub.com/61081878.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定