diff --git a/pom.xml b/pom.xml
index caa46ead1..7da7e58fa 100644
--- a/pom.xml
+++ b/pom.xml
@@ -331,6 +331,11 @@
datasource.default
${datasource.default}
+
+
+ dbClockDelta
+ ${dbClockDelta}
+
diff --git a/src/test/java/io/ebean/BaseTestCase.java b/src/test/java/io/ebean/BaseTestCase.java
index a7cbb0644..bdef878cf 100644
--- a/src/test/java/io/ebean/BaseTestCase.java
+++ b/src/test/java/io/ebean/BaseTestCase.java
@@ -22,7 +22,23 @@ public abstract class BaseTestCase {
protected static Logger logger = LoggerFactory.getLogger(BaseTestCase.class);
+ /**
+ * this is the clock delta that may occur between testing machine and db server.
+ * If the clock delta of DB server is in future, an "asOf" query may not find the
+ * correct entry.
+ *
+ * Note: That some tests may use a Thread.sleep to wait, so that the local system clock
+ * can catch up. So don't set that to a too high value.
+ */
+ public static final int DB_CLOCK_DELTA;
+
static {
+ String s = System.getProperty("dbClockDelta");
+ if (s != null && !s.isEmpty()) {
+ DB_CLOCK_DELTA = Integer.parseInt(s);
+ } else {
+ DB_CLOCK_DELTA = 100;
+ }
logger.debug("... preStart");
if (!AgentLoader.loadAgentFromClasspath("ebean-agent", "debug=1")) {
logger.info("avaje-ebeanorm-agent not found in classpath - not dynamically loaded");
diff --git a/src/test/java/org/tests/history/TestHistoryInsert.java b/src/test/java/org/tests/history/TestHistoryInsert.java
index 2331c26f1..bdbcb873d 100644
--- a/src/test/java/org/tests/history/TestHistoryInsert.java
+++ b/src/test/java/org/tests/history/TestHistoryInsert.java
@@ -34,7 +34,7 @@ public class TestHistoryInsert extends BaseTestCase {
Ebean.save(user);
logger.info("-- initial save");
- Thread.sleep(100);
+ Thread.sleep(DB_CLOCK_DELTA); // wait, so that our system clock can catch up
Timestamp afterInsert = new Timestamp(System.currentTimeMillis());
List history = fetchHistory(user);
diff --git a/src/test/java/org/tests/model/history/TestHistoryExclude.java b/src/test/java/org/tests/model/history/TestHistoryExclude.java
index b7b11bbb3..a8b4c746f 100644
--- a/src/test/java/org/tests/model/history/TestHistoryExclude.java
+++ b/src/test/java/org/tests/model/history/TestHistoryExclude.java
@@ -44,7 +44,7 @@ public class TestHistoryExclude extends BaseTestCase {
prepare();
HeLink linkFound = Ebean.find(HeLink.class)
- .asOf(new Timestamp(System.currentTimeMillis()))
+ .asOf(new Timestamp(System.currentTimeMillis() + DB_CLOCK_DELTA))
.setId(link.getId())
.findOne();
diff --git a/src/test/java/org/tests/model/history/TestHistoryInclude.java b/src/test/java/org/tests/model/history/TestHistoryInclude.java
index f556ad7d0..1ba178b70 100644
--- a/src/test/java/org/tests/model/history/TestHistoryInclude.java
+++ b/src/test/java/org/tests/model/history/TestHistoryInclude.java
@@ -44,7 +44,7 @@ public class TestHistoryInclude extends BaseTestCase {
prepare();
HiLink linkFound = Ebean.find(HiLink.class)
- .asOf(new Timestamp(System.currentTimeMillis()))
+ .asOf(new Timestamp(System.currentTimeMillis() + DB_CLOCK_DELTA))
.setId(link.getId())
.findOne();