From 09b0da91a2e02a20c7e115ee1d393acb76761b05 Mon Sep 17 00:00:00 2001 From: jo-elimu <1451036+jo-elimu@users.noreply.github.com> Date: Fri, 2 Feb 2024 17:46:44 +0800 Subject: [PATCH] test: #1645 Fix random failure in WordContributionEventDaoTest --- .../dao/WordContributionEventDaoTest.java | 19 +++++++++++++++---- src/test/resources/jdbc.properties | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/test/java/ai/elimu/dao/WordContributionEventDaoTest.java b/src/test/java/ai/elimu/dao/WordContributionEventDaoTest.java index 0720dee4e..a28aa1a3a 100644 --- a/src/test/java/ai/elimu/dao/WordContributionEventDaoTest.java +++ b/src/test/java/ai/elimu/dao/WordContributionEventDaoTest.java @@ -36,8 +36,10 @@ public class WordContributionEventDaoTest { @Test public void testReadMostRecent() { + logger.info("testReadMostRecent"); List wordContributionEvents = wordContributionEventDao.readMostRecent(10); int numberOfWordContributionEventsBefore = wordContributionEvents.size(); + logger.info("numberOfWordContributionEventsBefore: " + numberOfWordContributionEventsBefore); Contributor contributor = new Contributor(); contributorDao.create(contributor); @@ -56,13 +58,16 @@ public void testReadMostRecent() { wordContributionEvents = wordContributionEventDao.readMostRecent(10); int numberOfWordContributionEventsAfter = wordContributionEvents.size(); + logger.info("numberOfWordContributionEventsAfter: " + numberOfWordContributionEventsAfter); assertThat(numberOfWordContributionEventsAfter, is(numberOfWordContributionEventsBefore + 1)); } @Test public void testReadMostRecentPerWord() { + logger.info("testReadMostRecentPerWord"); List wordContributionEvents = wordContributionEventDao.readMostRecentPerWord(); int numberOfWordContributionEventsBefore = wordContributionEvents.size(); + logger.info("numberOfWordContributionEventsBefore: " + numberOfWordContributionEventsBefore); Contributor contributor = new Contributor(); contributorDao.create(contributor); @@ -80,7 +85,9 @@ public void testReadMostRecentPerWord() { wordContributionEventDao.create(wordContributionEvent2); wordContributionEvents = wordContributionEventDao.readMostRecentPerWord(); - assertThat(wordContributionEvents.size(), is(numberOfWordContributionEventsBefore + 1)); + int numberOfWordContributionEventsAfter = wordContributionEvents.size(); + logger.info("numberOfWordContributionEventsAfter: " + numberOfWordContributionEventsAfter); + assertThat(numberOfWordContributionEventsAfter, is(numberOfWordContributionEventsBefore + 1)); Word word3 = new Word(); word3.setText("word3"); @@ -95,7 +102,9 @@ public void testReadMostRecentPerWord() { wordContributionEventDao.create(wordContributionEvent3); wordContributionEvents = wordContributionEventDao.readMostRecentPerWord(); - assertThat(wordContributionEvents.size(), is(numberOfWordContributionEventsBefore + 2)); + numberOfWordContributionEventsAfter = wordContributionEvents.size(); + logger.info("numberOfWordContributionEventsAfter: " + numberOfWordContributionEventsAfter); + assertThat(numberOfWordContributionEventsAfter, is(numberOfWordContributionEventsBefore + 2)); // Re-use a word (word3) that was used in a previous contribution event WordContributionEvent wordContributionEvent4 = new WordContributionEvent(); @@ -106,8 +115,10 @@ public void testReadMostRecentPerWord() { wordContributionEvent4.setTimeSpentMs(10_000L); wordContributionEventDao.create(wordContributionEvent4); - // The number of contribution events returned should not increase + // The number of contribution events returned should remain the same (since word3 was used twice) wordContributionEvents = wordContributionEventDao.readMostRecentPerWord(); - assertThat(wordContributionEvents.size(), is(numberOfWordContributionEventsBefore + 2)); + numberOfWordContributionEventsAfter = wordContributionEvents.size(); + logger.info("numberOfWordContributionEventsAfter: " + numberOfWordContributionEventsAfter); + assertThat(numberOfWordContributionEventsAfter, is(numberOfWordContributionEventsBefore + 2)); } } diff --git a/src/test/resources/jdbc.properties b/src/test/resources/jdbc.properties index 47876375f..aaef14cbc 100644 --- a/src/test/resources/jdbc.properties +++ b/src/test/resources/jdbc.properties @@ -2,7 +2,7 @@ jpa.database=HSQL jpa.databasePlatform=org.hibernate.dialect.HSQLDialect jpa.generateDdl=true -jpa.showSql=true +jpa.showSql=false # JDBC Settings jdbc.driverClassName=org.hsqldb.jdbcDriver