Skip to content

Commit 63e22d0

Browse files
authored
improve flaky tests (#2956)
1 parent 0eca67e commit 63e22d0

2 files changed

Lines changed: 23 additions & 16 deletions

File tree

  • tika-integration-tests
    • tika-pipes-es-integration-tests/src/test/java/org/apache/tika/pipes/elasticsearch/tests
    • tika-pipes-opensearch-integration-tests/src/test/java/org/apache/tika/pipes/opensearch/tests

tika-integration-tests/tika-pipes-es-integration-tests/src/test/java/org/apache/tika/pipes/elasticsearch/tests/ElasticsearchTest.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,18 +178,21 @@ public void testBasicFSToElasticsearch(
178178
assertEquals(1, (int) statusCounts.get("EMIT_SUCCESS"),
179179
"should have had 1 emit success: " + statusCounts);
180180
assertEquals(2, numberOfCrashes(statusCounts),
181-
"should have had 2 OOM or 1 OOM and 1 timeout: " + statusCounts);
181+
"should have had 2 forked-process crashes (OOM/TIMEOUT/UNSPECIFIED_CRASH): " +
182+
statusCounts);
182183
}
183184

184185
private int numberOfCrashes(Map<String, Integer> statusCounts) {
185-
Integer oom = statusCounts.get("OOM");
186-
Integer timeout = statusCounts.get("TIMEOUT");
186+
// oom.xml (a real heap exhaustion) and fake_oom.xml both crash the fork; how a genuine OOM
187+
// surfaces -- OOM vs UNSPECIFIED_CRASH vs TIMEOUT -- is nondeterministic under load, but all
188+
// three are PipesResult PROCESS_CRASH statuses. Count the whole category so the assertion is
189+
// deterministic and doesn't flake on the exact sub-classification.
187190
int sum = 0;
188-
if (oom != null) {
189-
sum += oom;
190-
}
191-
if (timeout != null) {
192-
sum += timeout;
191+
for (String crashStatus : new String[]{"OOM", "TIMEOUT", "UNSPECIFIED_CRASH"}) {
192+
Integer cnt = statusCounts.get(crashStatus);
193+
if (cnt != null) {
194+
sum += cnt;
195+
}
193196
}
194197
return sum;
195198
}

tika-integration-tests/tika-pipes-opensearch-integration-tests/src/test/java/org/apache/tika/pipes/opensearch/tests/OpenSearchTest.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,19 +155,23 @@ public void testBasicFSToOpenSearch(@TempDir Path pipesDirectory, @TempDir Path
155155
assertEquals(1, (int) statusCounts.get("PARSE_SUCCESS_WITH_EXCEPTION"), "should have had 1 parse exception: " + statusCounts);
156156
//the embedded docx is emitted directly
157157
assertEquals(1, (int) statusCounts.get("EMIT_SUCCESS"), "should have had 1 emit success: " + statusCounts);
158-
assertEquals(2, numberOfCrashes(statusCounts), "should have had 2 OOM or 1 OOM and 1 timeout: " + statusCounts);
158+
assertEquals(2, numberOfCrashes(statusCounts),
159+
"should have had 2 forked-process crashes (OOM/TIMEOUT/UNSPECIFIED_CRASH): " +
160+
statusCounts);
159161

160162
}
161163

162164
private int numberOfCrashes(Map<String, Integer> statusCounts) {
163-
Integer oom = statusCounts.get("OOM");
164-
Integer timeout = statusCounts.get("TIMEOUT");
165+
// oom.xml (a real heap exhaustion) and fake_oom.xml both crash the fork; how a genuine OOM
166+
// surfaces -- OOM vs UNSPECIFIED_CRASH vs TIMEOUT -- is nondeterministic under load, but all
167+
// three are PipesResult PROCESS_CRASH statuses. Count the whole category so the assertion is
168+
// deterministic and doesn't flake on the exact sub-classification.
165169
int sum = 0;
166-
if (oom != null) {
167-
sum += oom;
168-
}
169-
if (timeout != null) {
170-
sum += timeout;
170+
for (String crashStatus : new String[]{"OOM", "TIMEOUT", "UNSPECIFIED_CRASH"}) {
171+
Integer cnt = statusCounts.get(crashStatus);
172+
if (cnt != null) {
173+
sum += cnt;
174+
}
171175
}
172176
return sum;
173177
}

0 commit comments

Comments
 (0)