Skip to content

Commit

Permalink
fix: Fix Random Unit Test fail - Meeds-io/MIPs#119 (#970)
Browse files Browse the repository at this point in the history
Prior to this change, the `DraftPageDAOTest` unit Test randomly fails when
two draft pages are added at the same millisecond on CI. This change
ensures to added both draft pages in different period of time to make
the unit test independent from Tests execution performances.
  • Loading branch information
boubaker authored and exo-swf committed May 8, 2024
1 parent c87580a commit 3ad9f42
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public void testDeleteDraftPagesByName() {
}

@Test
public void testFindLatestDraftPageByTargetPage() {
public void testFindLatestDraftPageByTargetPage() throws InterruptedException {
// Given
WikiEntity wiki = new WikiEntity();
wiki.setType("portal");
Expand All @@ -349,13 +349,19 @@ public void testFindLatestDraftPageByTargetPage() {
dp1.setUpdatedDate(new Date());
draftPageDAO.create(dp1);
persist();

// Added to fix random fail when draft pages
// are added at the same time
Thread.sleep(10);

DraftPageEntity dp2 = new DraftPageEntity();
dp2.setName("draft2");
dp2.setTargetPage(page);
dp2.setAuthor("user1");
dp2.setCreatedDate(new Date());
dp2.setUpdatedDate(new Date());
draftPageDAO.create(dp2);
persist();

// When
DraftPageEntity latestDraft = draftPageDAO.findLatestDraftPageByTargetPage(page.getId());
Expand Down

0 comments on commit 3ad9f42

Please sign in to comment.