Skip to content

Commit 9d3a837

Browse files
committed
Add test assertions to ensure write bytes released
This is a follow-up to elastic#57573. This commit ensures that the bytes marked in `WriteMemoryLimits` are released by any test using an internal test cluster.
1 parent fd3de80 commit 9d3a837

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
3737
import org.elasticsearch.action.admin.indices.stats.CommonStatsFlags;
3838
import org.elasticsearch.action.admin.indices.stats.CommonStatsFlags.Flag;
39+
import org.elasticsearch.action.bulk.WriteMemoryLimits;
3940
import org.elasticsearch.action.support.replication.TransportReplicationAction;
4041
import org.elasticsearch.client.Client;
4142
import org.elasticsearch.cluster.ClusterName;
@@ -1154,10 +1155,34 @@ public void beforeIndexDeletion() throws Exception {
11541155
// and not all docs have been purged after the test) and inherit from
11551156
// ElasticsearchIntegrationTest must override beforeIndexDeletion() to avoid failures.
11561157
assertNoPendingIndexOperations();
1158+
assertAllPendingWriteLimitsReleased();
11571159
assertOpenTranslogReferences();
11581160
assertNoSnapshottedIndexCommit();
11591161
}
11601162

1163+
private void assertAllPendingWriteLimitsReleased() throws Exception {
1164+
assertBusy(() -> {
1165+
for (NodeAndClient nodeAndClient : nodes.values()) {
1166+
WriteMemoryLimits writeMemoryLimits = getInstance(WriteMemoryLimits.class, nodeAndClient.name);
1167+
final long coordinatingBytes = writeMemoryLimits.getCoordinatingBytes();
1168+
if (coordinatingBytes > 0) {
1169+
throw new AssertionError("pending coordinating write bytes [" + coordinatingBytes + "] bytes on node ["
1170+
+ nodeAndClient.name + "].");
1171+
}
1172+
final long primaryBytes = writeMemoryLimits.getPrimaryBytes();
1173+
if (primaryBytes > 0) {
1174+
throw new AssertionError("pending primary write bytes [" + coordinatingBytes + "] bytes on node ["
1175+
+ nodeAndClient.name + "].");
1176+
}
1177+
final long replicaBytes = writeMemoryLimits.getReplicaBytes();
1178+
if (replicaBytes > 0) {
1179+
throw new AssertionError("pending replica write bytes [" + coordinatingBytes + "] bytes on node ["
1180+
+ nodeAndClient.name + "].");
1181+
}
1182+
}
1183+
}, 60, TimeUnit.SECONDS);
1184+
}
1185+
11611186
private void assertNoPendingIndexOperations() throws Exception {
11621187
assertBusy(() -> {
11631188
for (NodeAndClient nodeAndClient : nodes.values()) {

0 commit comments

Comments
 (0)