Skip to content

Commit

Permalink
Fix randomized test failure NRTReplicationEngineTests.testUpdateSegments
Browse files Browse the repository at this point in the history
Overload `generateHistoryOnReplica` to be able to generate only a specific `Engine.Operation.TYPE` operations as required by the `testUpdateSegments` test

Signed-off-by: Rabi Panda <adnapibar@gmail.com>
  • Loading branch information
adnapibar committed Sep 1, 2022
1 parent 4a6e937 commit abd82f3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Add timeout on Mockito.verify to reduce flakyness in testReplicationOnDone test([#4314](https://github.com/opensearch-project/OpenSearch/pull/4314))
- Commit workflow for dependabot changelog helper ([#4331](https://github.com/opensearch-project/OpenSearch/pull/4331))
- Fixed cancellation of segment replication events ([#4225](https://github.com/opensearch-project/OpenSearch/pull/4225))
- Bugs for dependabot changelog verifier workflow ([#4364](https://github.com/opensearch-project/OpenSearch/pull/4364))
- Bugs for dependabot changelog verifier workflow ([#4364](https://github.com/opensearch-project/OpenSearch/pull/4364))
- Fix flaky random test `NRTReplicationEngineTests.testUpdateSegments` ([#4352](https://github.com/opensearch-project/OpenSearch/pull/4352))

### Security
- CVE-2022-25857 org.yaml:snakeyaml DOS vulnerability ([#4341](https://github.com/opensearch-project/OpenSearch/pull/4341))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,14 @@ public void testUpdateSegments() throws Exception {
final NRTReplicationEngine nrtEngine = buildNrtReplicaEngine(globalCheckpoint, nrtEngineStore)
) {
// add docs to the primary engine.
List<Engine.Operation> operations = generateHistoryOnReplica(between(1, 500), randomBoolean(), randomBoolean(), randomBoolean())
.stream()
.filter(op -> op.operationType().equals(Engine.Operation.TYPE.INDEX))
.collect(Collectors.toList());
List<Engine.Operation> operations = generateHistoryOnReplica(
between(1, 500),
randomBoolean(),
randomBoolean(),
randomBoolean(),
Engine.Operation.TYPE.INDEX
);

for (Engine.Operation op : operations) {
applyOperation(engine, op);
applyOperation(nrtEngine, op);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1070,14 +1070,29 @@ public List<Engine.Operation> generateHistoryOnReplica(
boolean allowGapInSeqNo,
boolean allowDuplicate,
boolean includeNestedDocs
) throws Exception {
return generateHistoryOnReplica(
numOps,
allowGapInSeqNo,
allowDuplicate,
includeNestedDocs,
randomFrom(Engine.Operation.TYPE.values())
);
}

public List<Engine.Operation> generateHistoryOnReplica(
int numOps,
boolean allowGapInSeqNo,
boolean allowDuplicate,
boolean includeNestedDocs,
Engine.Operation.TYPE opType
) throws Exception {
long seqNo = 0;
final int maxIdValue = randomInt(numOps * 2);
final List<Engine.Operation> operations = new ArrayList<>(numOps);
CheckedBiFunction<String, Integer, ParsedDocument, IOException> nestedParsedDocFactory = nestedParsedDocFactory();
for (int i = 0; i < numOps; i++) {
final String id = Integer.toString(randomInt(maxIdValue));
final Engine.Operation.TYPE opType = randomFrom(Engine.Operation.TYPE.values());
final boolean isNestedDoc = includeNestedDocs && opType == Engine.Operation.TYPE.INDEX && randomBoolean();
final int nestedValues = between(0, 3);
final long startTime = threadPool.relativeTimeInNanos();
Expand Down

0 comments on commit abd82f3

Please sign in to comment.