Tests: move thread stacks on failure to a RunListener, so it actually works
This commit is contained in:
parent
b1d4cec7ab
commit
101ea31fdf
|
@ -34,6 +34,7 @@ import org.elasticsearch.common.util.concurrent.EsExecutors;
|
||||||
import org.elasticsearch.test.CurrentTestFailedMarker;
|
import org.elasticsearch.test.CurrentTestFailedMarker;
|
||||||
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||||
import org.elasticsearch.test.ElasticsearchTestCase;
|
import org.elasticsearch.test.ElasticsearchTestCase;
|
||||||
|
import org.elasticsearch.test.PrintAllThreadStacksOnFailure;
|
||||||
import org.elasticsearch.test.junit.listeners.ReproduceInfoPrinter;
|
import org.elasticsearch.test.junit.listeners.ReproduceInfoPrinter;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -58,7 +59,8 @@ import java.util.logging.Logger;
|
||||||
@Listeners({
|
@Listeners({
|
||||||
ReproduceInfoPrinter.class,
|
ReproduceInfoPrinter.class,
|
||||||
FailureMarker.class,
|
FailureMarker.class,
|
||||||
CurrentTestFailedMarker.class
|
CurrentTestFailedMarker.class,
|
||||||
|
PrintAllThreadStacksOnFailure.class
|
||||||
})
|
})
|
||||||
@RunWith(value = com.carrotsearch.randomizedtesting.RandomizedRunner.class)
|
@RunWith(value = com.carrotsearch.randomizedtesting.RandomizedRunner.class)
|
||||||
@SuppressCodecs(value = "Lucene3x")
|
@SuppressCodecs(value = "Lucene3x")
|
||||||
|
|
|
@ -606,12 +606,8 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase
|
||||||
logger.info("[{}#{}]: cleaned up after test", getTestClass().getSimpleName(), getTestName());
|
logger.info("[{}#{}]: cleaned up after test", getTestClass().getSimpleName(), getTestName());
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
|
// TODO: it looks like CurrentTestFailedMarker is never set at this point, so testFailed() will always be false?
|
||||||
if (!success || CurrentTestFailedMarker.testFailed()) {
|
if (!success || CurrentTestFailedMarker.testFailed()) {
|
||||||
|
|
||||||
logger.info("[{}#{}]: now dump all thread stacks on failure", getTestClass().getSimpleName(), getTestName());
|
|
||||||
ElasticsearchTestCase.printStackDump(logger);
|
|
||||||
logger.info("[{}#{}]: done dump all thread stacks on failure", getTestClass().getSimpleName(), getTestName());
|
|
||||||
|
|
||||||
// if we failed that means that something broke horribly so we should
|
// if we failed that means that something broke horribly so we should
|
||||||
// clear all clusters and if the current cluster is the global we shut that one
|
// clear all clusters and if the current cluster is the global we shut that one
|
||||||
// down as well to prevent subsequent tests from failing due to the same problem.
|
// down as well to prevent subsequent tests from failing due to the same problem.
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* Licensed to Elasticsearch under one or more contributor
|
||||||
|
* license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright
|
||||||
|
* ownership. Elasticsearch licenses this file to you under
|
||||||
|
* the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
* not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.elasticsearch.test;
|
||||||
|
|
||||||
|
import org.elasticsearch.common.logging.ESLogger;
|
||||||
|
import org.elasticsearch.common.logging.Loggers;
|
||||||
|
import org.junit.runner.Description;
|
||||||
|
import org.junit.runner.notification.Failure;
|
||||||
|
import org.junit.runner.notification.RunListener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@link RunListener} that detects test failures. We need it because we need
|
||||||
|
* to reset the global / suite level cluster if a test fails but don't wanna reset it
|
||||||
|
* for every subsequent test.
|
||||||
|
*/
|
||||||
|
public class PrintAllThreadStacksOnFailure extends RunListener {
|
||||||
|
|
||||||
|
private final ESLogger logger = Loggers.getLogger(getClass());
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void testFailure(Failure failure) throws Exception {
|
||||||
|
logger.info("now dump all thread stacks on failure");
|
||||||
|
ElasticsearchTestCase.printStackDump(logger);
|
||||||
|
logger.info("done dump all thread stacks on failure");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue