Skip to content

Commit b759947

Browse files
committed
Fix random failure in SearchRequestTests#testRandomVersionSerialization (elastic#42069)
This commit fixes a test bug that ends up comparing the result of two consecutive calls to System.currentTimeMillis that can be different on slow CIs. Closes elastic#42064
1 parent 0ec7986 commit b759947

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

server/src/main/java/org/elasticsearch/action/search/SearchRequest.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,19 @@ boolean isFinalReduce() {
302302
* ensure that the same value, determined by the coordinating node, is used on all nodes involved in the execution of the search
303303
* request. When created through {@link #crossClusterSearch(SearchRequest, String[], String, long, boolean)}, this method returns
304304
* the provided current time, otherwise it will return {@link System#currentTimeMillis()}.
305-
*
306305
*/
307306
long getOrCreateAbsoluteStartMillis() {
308307
return absoluteStartMillis == DEFAULT_ABSOLUTE_START_MILLIS ? System.currentTimeMillis() : absoluteStartMillis;
309308
}
310309

310+
/**
311+
* Returns the provided <code>absoluteStartMillis</code> when created through {@link #crossClusterSearch} and
312+
* -1 otherwise.
313+
*/
314+
long getAbsoluteStartMillis() {
315+
return absoluteStartMillis;
316+
}
317+
311318
/**
312319
* Sets the indices the search will be executed on.
313320
*/

server/src/test/java/org/elasticsearch/action/search/SearchRequestTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public void testRandomVersionSerialization() throws IOException {
9494
assertTrue(deserializedRequest.isFinalReduce());
9595
} else {
9696
assertEquals(searchRequest.getLocalClusterAlias(), deserializedRequest.getLocalClusterAlias());
97-
assertEquals(searchRequest.getOrCreateAbsoluteStartMillis(), deserializedRequest.getOrCreateAbsoluteStartMillis());
97+
assertEquals(searchRequest.getAbsoluteStartMillis(), deserializedRequest.getAbsoluteStartMillis());
9898
assertEquals(searchRequest.isFinalReduce(), deserializedRequest.isFinalReduce());
9999
}
100100
}

0 commit comments

Comments
 (0)