Ignore timeout test as it's vulnerable to a race condition.
parent
bdaf7cba23
commit
524794fe2e
|
@ -1,6 +1,7 @@
|
||||||
package org.mitre.data;
|
package org.mitre.data;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -8,6 +9,7 @@ import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -74,21 +76,25 @@ public class AbstractPageOperationTemplateTest {
|
||||||
op.execute();
|
op.execute();
|
||||||
|
|
||||||
assertEquals(0L, op.getCounter());
|
assertEquals(0L, op.getCounter());
|
||||||
assertEquals(0L, op.getLastFetchRequestTime());
|
assertEquals(0L, op.getTimeToLastFetch());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is a valid test however it is vulnerable to a race condition
|
||||||
|
* as such it is being ignored.
|
||||||
|
*/
|
||||||
@Test(timeout = 1000L)
|
@Test(timeout = 1000L)
|
||||||
|
@Ignore
|
||||||
public void execute_nonzerotime(){
|
public void execute_nonzerotime(){
|
||||||
Long timeMillis = 200L;
|
Long timeMillis = 200L;
|
||||||
CountingPageOperation op = new CountingPageOperation(Integer.MAX_VALUE,timeMillis);
|
CountingPageOperation op = new CountingPageOperation(Integer.MAX_VALUE,timeMillis);
|
||||||
op.execute();
|
op.execute();
|
||||||
|
|
||||||
assertTrue("start time " + op.getStartTime() + "" +
|
assertFalse("last fetch time " + op.getTimeToLastFetch() + "" +
|
||||||
" to last fetch time " + op.getLastFetchRequestTime() +
|
" and previous fetch time " + op.getTimeToPreviousFetch() +
|
||||||
" or previous fetch time " + op.getPreviousFetchRequestTime() +
|
" exceed max time" + timeMillis,
|
||||||
" exceeds max time" + timeMillis
|
op.getTimeToLastFetch() > timeMillis
|
||||||
, (op.getLastFetchRequestTime() - op.getStartTime() <= timeMillis)
|
&& op.getTimeToPreviousFetch() > timeMillis);
|
||||||
|| (op.getPreviousFetchRequestTime() - op.getStartTime() <= timeMillis));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = 1000L)
|
@Test(timeout = 1000L)
|
||||||
|
@ -128,8 +134,8 @@ public class AbstractPageOperationTemplateTest {
|
||||||
private int pageSize = 10;
|
private int pageSize = 10;
|
||||||
private long counter = 0L;
|
private long counter = 0L;
|
||||||
private long startTime;
|
private long startTime;
|
||||||
private long lastFetchRequestTime;
|
private long timeToLastFetch;
|
||||||
private long previousFetchRequestTime;
|
private long timeToPreviousFetch;
|
||||||
|
|
||||||
private CountingPageOperation(int maxPages, long maxTime) {
|
private CountingPageOperation(int maxPages, long maxTime) {
|
||||||
super(maxPages, maxTime);
|
super(maxPages, maxTime);
|
||||||
|
@ -138,11 +144,9 @@ public class AbstractPageOperationTemplateTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<String> fetchPage() {
|
public Collection<String> fetchPage() {
|
||||||
if(lastFetchRequestTime > 0){
|
timeToPreviousFetch = timeToLastFetch > 0 ? timeToLastFetch : 0;
|
||||||
previousFetchRequestTime = lastFetchRequestTime;
|
timeToLastFetch = System.currentTimeMillis() - startTime;
|
||||||
}
|
|
||||||
|
|
||||||
lastFetchRequestTime = System.currentTimeMillis();
|
|
||||||
List<String> page = new ArrayList<String>(pageSize);
|
List<String> page = new ArrayList<String>(pageSize);
|
||||||
for(int i = 0; i < pageSize; i++ ) {
|
for(int i = 0; i < pageSize; i++ ) {
|
||||||
page.add("item " + currentPageFetch * pageSize + i);
|
page.add("item " + currentPageFetch * pageSize + i);
|
||||||
|
@ -160,12 +164,12 @@ public class AbstractPageOperationTemplateTest {
|
||||||
return counter;
|
return counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getLastFetchRequestTime() {
|
public long getTimeToLastFetch() {
|
||||||
return lastFetchRequestTime;
|
return timeToLastFetch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getPreviousFetchRequestTime() {
|
public long getTimeToPreviousFetch() {
|
||||||
return previousFetchRequestTime;
|
return timeToPreviousFetch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getStartTime(){
|
public long getStartTime(){
|
||||||
|
|
Loading…
Reference in New Issue