001
014
015 package com.liferay.portal.test.rule.callback;
016
017 import com.liferay.portal.kernel.test.rule.callback.BaseTestCallback;
018 import com.liferay.portal.kernel.test.util.TestPropsValues;
019
020 import org.junit.Assert;
021 import org.junit.runner.Description;
022
023
026 public class CITimeoutTestCallback extends BaseTestCallback<Long, Object> {
027
028 public static final CITimeoutTestCallback INSTANCE =
029 new CITimeoutTestCallback();
030
031 @Override
032 public void afterClass(Description description, Long startTime) {
033 long testTime = System.currentTimeMillis() - startTime;
034
035 if (testTime <= TestPropsValues.CI_TEST_TIMEOUT_TIME) {
036 return;
037 }
038
039 String message =
040 description.getClassName() + " spent " + testTime +
041 "ms and surpassed the timeout threshold " +
042 TestPropsValues.CI_TEST_TIMEOUT_TIME + "ms.";
043
044 System.setProperty(_CI_TIMEOUT_TEST_CLASS_MESSAGE, message);
045
046 Assert.fail(
047 message + " Marked it as failed and aborting subsequent tests.");
048 }
049
050 @Override
051 public Long beforeClass(Description description) {
052 String message = System.getProperty(_CI_TIMEOUT_TEST_CLASS_MESSAGE);
053
054 if (message != null) {
055 Assert.fail(
056 "Abort running " + description.getClassName() + " due to : " +
057 message);
058 }
059
060 return System.currentTimeMillis();
061 }
062
063 private CITimeoutTestCallback() {
064 }
065
066 private static final String _CI_TIMEOUT_TEST_CLASS_MESSAGE =
067 "CI_TIMEOUT_TEST_CLASS_MESSAGE";
068
069 }