Skip to content

Commit 524794f

Browse files
strangeweaverjricher
authored andcommitted
Ignore timeout test as it's vulnerable to a race condition.
1 parent bdaf7cb commit 524794f

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

openid-connect-common/src/test/java/org/mitre/data/AbstractPageOperationTemplateTest.java

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package org.mitre.data;
22

33
import org.junit.Before;
4+
import org.junit.Ignore;
45
import org.junit.Test;
56

67
import java.util.ArrayList;
78
import java.util.Collection;
89
import java.util.List;
910

1011
import static org.junit.Assert.assertEquals;
12+
import static org.junit.Assert.assertFalse;
1113
import static org.junit.Assert.assertTrue;
1214

1315
/**
@@ -74,21 +76,25 @@ public void execute_zerotime(){
7476
op.execute();
7577

7678
assertEquals(0L, op.getCounter());
77-
assertEquals(0L, op.getLastFetchRequestTime());
79+
assertEquals(0L, op.getTimeToLastFetch());
7880
}
7981

82+
/*
83+
* This is a valid test however it is vulnerable to a race condition
84+
* as such it is being ignored.
85+
*/
8086
@Test(timeout = 1000L)
87+
@Ignore
8188
public void execute_nonzerotime(){
8289
Long timeMillis = 200L;
8390
CountingPageOperation op = new CountingPageOperation(Integer.MAX_VALUE,timeMillis);
8491
op.execute();
8592

86-
assertTrue("start time " + op.getStartTime() + "" +
87-
" to last fetch time " + op.getLastFetchRequestTime() +
88-
" or previous fetch time " + op.getPreviousFetchRequestTime() +
89-
" exceeds max time" + timeMillis
90-
, (op.getLastFetchRequestTime() - op.getStartTime() <= timeMillis)
91-
|| (op.getPreviousFetchRequestTime() - op.getStartTime() <= timeMillis));
93+
assertFalse("last fetch time " + op.getTimeToLastFetch() + "" +
94+
" and previous fetch time " + op.getTimeToPreviousFetch() +
95+
" exceed max time" + timeMillis,
96+
op.getTimeToLastFetch() > timeMillis
97+
&& op.getTimeToPreviousFetch() > timeMillis);
9298
}
9399

94100
@Test(timeout = 1000L)
@@ -128,8 +134,8 @@ private static class CountingPageOperation extends AbstractPageOperationTemplate
128134
private int pageSize = 10;
129135
private long counter = 0L;
130136
private long startTime;
131-
private long lastFetchRequestTime;
132-
private long previousFetchRequestTime;
137+
private long timeToLastFetch;
138+
private long timeToPreviousFetch;
133139

134140
private CountingPageOperation(int maxPages, long maxTime) {
135141
super(maxPages, maxTime);
@@ -138,11 +144,9 @@ private CountingPageOperation(int maxPages, long maxTime) {
138144

139145
@Override
140146
public Collection<String> fetchPage() {
141-
if(lastFetchRequestTime > 0){
142-
previousFetchRequestTime = lastFetchRequestTime;
143-
}
147+
timeToPreviousFetch = timeToLastFetch > 0 ? timeToLastFetch : 0;
148+
timeToLastFetch = System.currentTimeMillis() - startTime;
144149

145-
lastFetchRequestTime = System.currentTimeMillis();
146150
List<String> page = new ArrayList<String>(pageSize);
147151
for(int i = 0; i < pageSize; i++ ) {
148152
page.add("item " + currentPageFetch * pageSize + i);
@@ -160,12 +164,12 @@ public long getCounter() {
160164
return counter;
161165
}
162166

163-
public long getLastFetchRequestTime() {
164-
return lastFetchRequestTime;
167+
public long getTimeToLastFetch() {
168+
return timeToLastFetch;
165169
}
166170

167-
public long getPreviousFetchRequestTime() {
168-
return previousFetchRequestTime;
171+
public long getTimeToPreviousFetch() {
172+
return timeToPreviousFetch;
169173
}
170174

171175
public long getStartTime(){

0 commit comments

Comments
 (0)