Test: extra debugging for refresh listeners stats

This test failed in CI but didn't give us enough information to
debug it:
https://elasticsearch-ci.elastic.co/job/elastic+elasticsearch+master+nfs/223/consoleFull

This turns on more debugging and make the test fail more quickly
if something is obviously wrong.
This commit is contained in:
Nik Everett 2017-05-01 11:45:43 -04:00
parent eefcad94b8
commit 62712bf653
1 changed files with 16 additions and 4 deletions

View File

@ -23,6 +23,7 @@ import org.elasticsearch.action.ListenableActionFuture;
import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.ShardOperationFailedException;
import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; import org.elasticsearch.action.support.WriteRequest.RefreshPolicy;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
@ -30,8 +31,10 @@ import org.elasticsearch.index.engine.CommitStats;
import org.elasticsearch.index.engine.SegmentsStats; import org.elasticsearch.index.engine.SegmentsStats;
import org.elasticsearch.index.translog.Translog; import org.elasticsearch.index.translog.Translog;
import org.elasticsearch.test.ESSingleNodeTestCase; import org.elasticsearch.test.ESSingleNodeTestCase;
import org.elasticsearch.test.junit.annotations.TestLogging;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.greaterThan;
@ -115,6 +118,7 @@ public class IndicesStatsTests extends ESSingleNodeTestCase {
} }
} }
@TestLogging("_root:debug")
public void testRefreshListeners() throws Exception { public void testRefreshListeners() throws Exception {
// Create an index without automatic refreshes // Create an index without automatic refreshes
createIndex("test", Settings.builder().put("refresh_interval", -1).build()); createIndex("test", Settings.builder().put("refresh_interval", -1).build());
@ -124,11 +128,19 @@ public class IndicesStatsTests extends ESSingleNodeTestCase {
.setRefreshPolicy(RefreshPolicy.WAIT_UNTIL).execute(); .setRefreshPolicy(RefreshPolicy.WAIT_UNTIL).execute();
// Wait for the refresh listener to appear in the stats // Wait for the refresh listener to appear in the stats
assertBusy(() -> { long end = System.nanoTime() + TimeUnit.SECONDS.toNanos(10);
IndicesStatsResponse stats = client().admin().indices().prepareStats("test").clear().setRefresh(true).get(); while (true) {
IndicesStatsResponse stats = client().admin().indices().prepareStats("test").clear().setRefresh(true).setDocs(true).get();
CommonStats common = stats.getIndices().get("test").getTotal(); CommonStats common = stats.getIndices().get("test").getTotal();
assertEquals(1, common.refresh.getListeners()); // There shouldn't be a doc. If there is then we did *something* weird.
}); assertEquals(0, common.docs.getCount());
if (1 == common.refresh.getListeners()) {
break;
}
if (end - System.nanoTime() < 0) {
fail("didn't get a refresh listener in time: " + Strings.toString(common));
}
}
// Refresh the index and wait for the request to come back // Refresh the index and wait for the request to come back
client().admin().indices().prepareRefresh("test").get(); client().admin().indices().prepareRefresh("test").get();