Delete index after each test in elasticsearch tests

Since change I6539845e0 the index is not deleted after each test method
because of a problem where the index was not deleted quickly enough and
the index for the next test could not be created due to the previous one
still existing. The indices are all kept and then only deleted at the
end of the run.

Leaving all the indices results in running out of file descriptors which
results in tests failing when many tests are run in sequence.

Since we now give each test index a unique name, we no longer suffer from
the original problem described above. We can safely attempt to delete the
index and it doesn't matter if it does not get deleted quickly enough and
still exists when the next test is started.

The tests for accounts, groups and projects are not currently affected by
this problem because they have far fewer test methods than the tests for
changes. The same fix is done for those tests anyway to make sure we do
not run into the same problem in future.

Bug: Issue 8816
Change-Id: I1646f5b802dd2d15b974d4c4d75ab337c4c6f462
This commit is contained in:
David Pursehouse
2018-04-21 18:30:21 +02:00
parent 3ecb519e43
commit 6dcaddf465
4 changed files with 69 additions and 5 deletions

View File

@@ -22,6 +22,7 @@ import com.google.inject.Guice;
import com.google.inject.Injector;
import java.util.concurrent.ExecutionException;
import org.eclipse.jgit.lib.Config;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -46,11 +47,22 @@ public class ElasticQueryAccountsTest extends AbstractQueryAccountsTest {
}
}
private String testName() {
return testName.getMethodName().toLowerCase() + "_";
}
@After
public void cleanupIndex() {
if (nodeInfo != null) {
ElasticTestUtils.deleteAllIndexes(nodeInfo, testName());
}
}
@Override
protected Injector createInjector() {
Config elasticsearchConfig = new Config(config);
InMemoryModule.setDefaults(elasticsearchConfig);
String indicesPrefix = testName.getMethodName().toLowerCase() + "_";
String indicesPrefix = testName();
ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix);
ElasticTestUtils.createAllIndexes(nodeInfo, indicesPrefix);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig, notesMigration));

View File

@@ -24,6 +24,7 @@ import com.google.inject.Injector;
import java.util.concurrent.ExecutionException;
import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.Config;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
@@ -53,11 +54,22 @@ public class ElasticQueryChangesTest extends AbstractQueryChangesTest {
}
}
private String testName() {
return testName.getMethodName().toLowerCase() + "_";
}
@After
public void cleanupIndex() {
if (nodeInfo != null) {
ElasticTestUtils.deleteAllIndexes(nodeInfo, testName());
}
}
@Override
protected Injector createInjector() {
Config elasticsearchConfig = new Config(config);
InMemoryModule.setDefaults(elasticsearchConfig);
String indicesPrefix = testName.getMethodName().toLowerCase() + "_";
String indicesPrefix = testName();
ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix);
ElasticTestUtils.createAllIndexes(nodeInfo, indicesPrefix);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig, notesMigration));

View File

@@ -22,6 +22,7 @@ import com.google.inject.Guice;
import com.google.inject.Injector;
import java.util.concurrent.ExecutionException;
import org.eclipse.jgit.lib.Config;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -46,11 +47,22 @@ public class ElasticQueryGroupsTest extends AbstractQueryGroupsTest {
}
}
private String testName() {
return testName.getMethodName().toLowerCase() + "_";
}
@After
public void cleanupIndex() {
if (nodeInfo != null) {
ElasticTestUtils.deleteAllIndexes(nodeInfo, testName());
}
}
@Override
protected Injector createInjector() {
Config elasticsearchConfig = new Config(config);
InMemoryModule.setDefaults(elasticsearchConfig);
String indicesPrefix = testName.getMethodName().toLowerCase() + "_";
String indicesPrefix = testName();
ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix);
ElasticTestUtils.createAllIndexes(nodeInfo, indicesPrefix);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig, notesMigration));