No effective change - modify TestHistoryInsert for more wait time and logging (PG test failing sometimes in CI)

This commit is contained in:
Rob Bygrave
2016-11-08 00:25:13 +13:00
parent ae69fcb80a
commit b41238ddbb
2 changed files with 13 additions and 3 deletions
@@ -5,9 +5,10 @@ import com.avaje.ebean.Ebean;
import com.avaje.ebean.SqlQuery;
import com.avaje.ebean.SqlRow;
import com.avaje.ebean.Version;
import com.avaje.ebeaninternal.api.SpiEbeanServer;
import com.avaje.tests.model.converstation.User;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.Timestamp;
import java.util.List;
@@ -16,6 +17,8 @@ import static org.assertj.core.api.Assertions.assertThat;
public class TestHistoryInsert extends BaseTestCase {
private final Logger logger = LoggerFactory.getLogger(TestHistoryInsert.class);
@Test
public void test() throws InterruptedException {
@@ -29,6 +32,7 @@ public class TestHistoryInsert extends BaseTestCase {
user.setPasswordHash("someHash");
Ebean.save(user);
logger.info("-- initial save");
Timestamp afterInsert = new Timestamp(System.currentTimeMillis());
@@ -40,7 +44,8 @@ public class TestHistoryInsert extends BaseTestCase {
user.setName("Jim v2");
user.setPasswordHash("anotherHash");
Thread.sleep(10); // wait, to ensure that whenModified differs
Thread.sleep(50); // wait, to ensure that whenModified differs
logger.info("-- update v2");
Ebean.save(user);
history = fetchHistory(user);
@@ -53,7 +58,9 @@ public class TestHistoryInsert extends BaseTestCase {
user.setName("Jim v3");
user.setEmail("three@email.com");
Thread.sleep(10); // otherwise the timestamp of "whenModified" may not change
Thread.sleep(50); // otherwise the timestamp of "whenModified" may not change
logger.info("-- update v3");
Ebean.save(user);
history = fetchHistory(user);
@@ -65,6 +72,7 @@ public class TestHistoryInsert extends BaseTestCase {
assertThat(versions).hasSize(3);
assertThat(versions.get(0).getDiff()).containsKeys("name", "email", "version", "whenModified");
logger.info("-- delete");
Ebean.delete(user);
User earlyVersion = Ebean.find(User.class).setId(user.getId()).asOf(afterInsert).findUnique();
@@ -73,6 +81,7 @@ public class TestHistoryInsert extends BaseTestCase {
Ebean.find(User.class).setId(user.getId()).asOf(afterInsert).findUnique();
logger.info("-- last fetchHistory");
history = fetchHistory(user);
assertThat(history).hasSize(3);