Skip to content

Commit

Permalink
test: #1645 Fix random failure in WordContributionEventDaoTest
Browse files Browse the repository at this point in the history
  • Loading branch information
jo-elimu committed Feb 2, 2024
1 parent 5f0f06c commit 09b0da9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions src/test/java/ai/elimu/dao/WordContributionEventDaoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ public class WordContributionEventDaoTest {

@Test
public void testReadMostRecent() {
logger.info("testReadMostRecent");
List<WordContributionEvent> wordContributionEvents = wordContributionEventDao.readMostRecent(10);
int numberOfWordContributionEventsBefore = wordContributionEvents.size();
logger.info("numberOfWordContributionEventsBefore: " + numberOfWordContributionEventsBefore);

Contributor contributor = new Contributor();
contributorDao.create(contributor);
Expand All @@ -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<WordContributionEvent> wordContributionEvents = wordContributionEventDao.readMostRecentPerWord();
int numberOfWordContributionEventsBefore = wordContributionEvents.size();
logger.info("numberOfWordContributionEventsBefore: " + numberOfWordContributionEventsBefore);

Contributor contributor = new Contributor();
contributorDao.create(contributor);
Expand All @@ -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");
Expand All @@ -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();
Expand All @@ -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));
}
}
2 changes: 1 addition & 1 deletion src/test/resources/jdbc.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 09b0da9

Please sign in to comment.