From e28e5f131397aaa09dec9e11ccafa1f3c7629013 Mon Sep 17 00:00:00 2001 From: Tim Brooks Date: Sun, 17 Oct 2021 14:06:06 -0500 Subject: [PATCH] Fix errors in RefreshListenersTests Recent modifications to the RefreshListenersTests added tests for sequence number listeners. This made it possible that more listeners were added over the course of a test. We must not always allow a minimum of 2 listeners. Additionally, there was a broken assertion in the concurrent test which caused a listener to possibly be completed immediately due to a concurrent refresh. An assertion must be deleted to reflect this possibility. --- .../org/elasticsearch/index/shard/RefreshListeners.java | 6 +++--- .../elasticsearch/index/shard/RefreshListenersTests.java | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/index/shard/RefreshListeners.java b/server/src/main/java/org/elasticsearch/index/shard/RefreshListeners.java index 1c72a42be0af0..8e957c9a004ab 100644 --- a/server/src/main/java/org/elasticsearch/index/shard/RefreshListeners.java +++ b/server/src/main/java/org/elasticsearch/index/shard/RefreshListeners.java @@ -13,11 +13,11 @@ import org.apache.lucene.store.AlreadyClosedException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.ContextPreservingActionListener; -import org.elasticsearch.core.Tuple; -import org.elasticsearch.core.Releasable; -import org.elasticsearch.core.Releasables; import org.elasticsearch.common.metrics.MeanMetric; import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.core.Releasable; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.core.Tuple; import org.elasticsearch.index.seqno.SequenceNumbers; import org.elasticsearch.index.translog.Translog; diff --git a/server/src/test/java/org/elasticsearch/index/shard/RefreshListenersTests.java b/server/src/test/java/org/elasticsearch/index/shard/RefreshListenersTests.java index cfa5e6a7e7d77..dbdb946eabac4 100644 --- a/server/src/test/java/org/elasticsearch/index/shard/RefreshListenersTests.java +++ b/server/src/test/java/org/elasticsearch/index/shard/RefreshListenersTests.java @@ -25,7 +25,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.concurrent.ThreadContext; -import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.core.Nullable; import org.elasticsearch.core.Releasable; import org.elasticsearch.core.TimeValue; @@ -57,6 +56,7 @@ import org.elasticsearch.threadpool.TestThreadPool; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool.Names; +import org.elasticsearch.xcontent.XContentType; import org.junit.After; import org.junit.Before; @@ -92,7 +92,7 @@ public class RefreshListenersTests extends ESTestCase { @Before public void setupListeners() throws Exception { // Setup dependencies of the listeners - maxListeners = randomIntBetween(1, 1000); + maxListeners = randomIntBetween(2, 1000); // Now setup the InternalEngine which is much more complicated because we aren't mocking anything threadPool = new TestThreadPool(getTestName()); refreshMetric = new MeanMetric(); @@ -360,7 +360,6 @@ public void testConcurrentRefresh() throws Exception { doneSupplier = () -> listener.forcedRefresh.get() != null; if (immediate) { assertNotNull(listener.forcedRefresh.get()); - assertTrue(listener.forcedRefresh.get()); listener.assertNoError(); } } else {