Skip to content

Commit f7a4f92

Browse files
authored
Fix random failure in SearchRequestTests#testRandomVersionSerialization (#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 #42064
1 parent 5fe1fda commit f7a4f92

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
@@ -286,12 +286,19 @@ boolean isFinalReduce() {
286286
* ensure that the same value, determined by the coordinating node, is used on all nodes involved in the execution of the search
287287
* request. When created through {@link #crossClusterSearch(SearchRequest, String[], String, long, boolean)}, this method returns
288288
* the provided current time, otherwise it will return {@link System#currentTimeMillis()}.
289-
*
290289
*/
291290
long getOrCreateAbsoluteStartMillis() {
292291
return absoluteStartMillis == DEFAULT_ABSOLUTE_START_MILLIS ? System.currentTimeMillis() : absoluteStartMillis;
293292
}
294293

294+
/**
295+
* Returns the provided <code>absoluteStartMillis</code> when created through {@link #crossClusterSearch} and
296+
* -1 otherwise.
297+
*/
298+
long getAbsoluteStartMillis() {
299+
return absoluteStartMillis;
300+
}
301+
295302
/**
296303
* Sets the indices the search will be executed on.
297304
*/

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void testRandomVersionSerialization() throws IOException {
8080
SearchRequest deserializedRequest = copyWriteable(searchRequest, namedWriteableRegistry, SearchRequest::new, version);
8181
assertEquals(searchRequest.isCcsMinimizeRoundtrips(), deserializedRequest.isCcsMinimizeRoundtrips());
8282
assertEquals(searchRequest.getLocalClusterAlias(), deserializedRequest.getLocalClusterAlias());
83-
assertEquals(searchRequest.getOrCreateAbsoluteStartMillis(), deserializedRequest.getOrCreateAbsoluteStartMillis());
83+
assertEquals(searchRequest.getAbsoluteStartMillis(), deserializedRequest.getAbsoluteStartMillis());
8484
assertEquals(searchRequest.isFinalReduce(), deserializedRequest.isFinalReduce());
8585
}
8686

0 commit comments

Comments
 (0)