mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Fix clock sync (#1287)
Test only change - Fix clock sync timing issues with tests using -DdbClockDelta
This commit is contained in:
committed by
Rob Bygrave
parent
10f3d85d9f
commit
3f8b9529e1
@@ -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");
|
||||
|
||||
@@ -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<SqlRow> history = fetchHistory(user);
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user