Strict context check for tomcat and jetty (#3923)
This commit is contained in:
parent
6ba91989a7
commit
a2928663f4
|
@ -10,11 +10,13 @@ import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEn
|
||||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||||
|
import static org.awaitility.Awaitility.await
|
||||||
|
|
||||||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
||||||
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
|
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
|
||||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||||
import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpRequest
|
import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpRequest
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
import javax.servlet.Servlet
|
import javax.servlet.Servlet
|
||||||
|
|
||||||
abstract class AbstractServlet3Test<SERVER, CONTEXT> extends HttpServerTest<SERVER> implements AgentTestTrait {
|
abstract class AbstractServlet3Test<SERVER, CONTEXT> extends HttpServerTest<SERVER> implements AgentTestTrait {
|
||||||
|
@ -45,6 +47,25 @@ abstract class AbstractServlet3Test<SERVER, CONTEXT> extends HttpServerTest<SERV
|
||||||
addServlet(context, INDEXED_CHILD.path, servlet)
|
addServlet(context, INDEXED_CHILD.path, servlet)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def cleanup() {
|
||||||
|
// wait for async request threads to complete
|
||||||
|
await()
|
||||||
|
.atMost(15, TimeUnit.SECONDS)
|
||||||
|
.until({ !isRequestRunning() })
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean isRequestRunning() {
|
||||||
|
def result = Thread.getAllStackTraces().values().find {stackTrace ->
|
||||||
|
def element = stackTrace.find {
|
||||||
|
return ((it.className == "org.apache.catalina.core.AsyncContextImpl\$RunnableWrapper" && it.methodName == "run")
|
||||||
|
|| ((it.className == "org.eclipse.jetty.server.AsyncContinuation\$1" && it.methodName == "run"))
|
||||||
|
|| ((it.className == "org.eclipse.jetty.server.AsyncContextState\$1" && it.methodName == "run")))
|
||||||
|
}
|
||||||
|
element != null
|
||||||
|
}
|
||||||
|
return result != null
|
||||||
|
}
|
||||||
|
|
||||||
protected ServerEndpoint lastRequest
|
protected ServerEndpoint lastRequest
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -21,7 +21,3 @@ dependencies {
|
||||||
testLibrary("org.apache.tomcat.embed:tomcat-embed-core:10.0.0")
|
testLibrary("org.apache.tomcat.embed:tomcat-embed-core:10.0.0")
|
||||||
testLibrary("org.apache.tomcat.embed:tomcat-embed-jasper:10.0.0")
|
testLibrary("org.apache.tomcat.embed:tomcat-embed-jasper:10.0.0")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType<Test>().configureEach {
|
|
||||||
jvmArgs("-Dio.opentelemetry.javaagent.shaded.io.opentelemetry.context.enableStrictContext=false")
|
|
||||||
}
|
|
||||||
|
|
|
@ -10,12 +10,14 @@ import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEn
|
||||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||||
|
import static org.awaitility.Awaitility.await
|
||||||
|
|
||||||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
||||||
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
|
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
|
||||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||||
import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpRequest
|
import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpRequest
|
||||||
import jakarta.servlet.Servlet
|
import jakarta.servlet.Servlet
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
abstract class AbstractServlet5Test<SERVER, CONTEXT> extends HttpServerTest<SERVER> implements AgentTestTrait {
|
abstract class AbstractServlet5Test<SERVER, CONTEXT> extends HttpServerTest<SERVER> implements AgentTestTrait {
|
||||||
@Override
|
@Override
|
||||||
|
@ -45,6 +47,24 @@ abstract class AbstractServlet5Test<SERVER, CONTEXT> extends HttpServerTest<SERV
|
||||||
addServlet(context, INDEXED_CHILD.path, servlet)
|
addServlet(context, INDEXED_CHILD.path, servlet)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def cleanup() {
|
||||||
|
// wait for async request threads to complete
|
||||||
|
await()
|
||||||
|
.atMost(15, TimeUnit.SECONDS)
|
||||||
|
.until({ !isRequestRunning() })
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean isRequestRunning() {
|
||||||
|
def result = Thread.getAllStackTraces().values().find {stackTrace ->
|
||||||
|
def element = stackTrace.find {
|
||||||
|
return ((it.className == "org.apache.catalina.core.AsyncContextImpl\$RunnableWrapper" && it.methodName == "run")
|
||||||
|
|| ((it.className == "org.eclipse.jetty.server.AsyncContextState\$1" && it.methodName == "run")))
|
||||||
|
}
|
||||||
|
element != null
|
||||||
|
}
|
||||||
|
return result != null
|
||||||
|
}
|
||||||
|
|
||||||
protected ServerEndpoint lastRequest
|
protected ServerEndpoint lastRequest
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -17,7 +17,3 @@ dependencies {
|
||||||
// Make sure nothing breaks due to both 7.0 and 10.0 modules being present together
|
// Make sure nothing breaks due to both 7.0 and 10.0 modules being present together
|
||||||
testInstrumentation(project(":instrumentation:tomcat:tomcat-7.0:javaagent"))
|
testInstrumentation(project(":instrumentation:tomcat:tomcat-7.0:javaagent"))
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType<Test>().configureEach {
|
|
||||||
jvmArgs("-Dio.opentelemetry.javaagent.shaded.io.opentelemetry.context.enableStrictContext=false")
|
|
||||||
}
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEn
|
||||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||||
|
import static org.awaitility.Awaitility.await
|
||||||
|
|
||||||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
||||||
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
|
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
|
||||||
|
@ -20,6 +21,7 @@ import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||||
import jakarta.servlet.Servlet
|
import jakarta.servlet.Servlet
|
||||||
import jakarta.servlet.ServletException
|
import jakarta.servlet.ServletException
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
import org.apache.catalina.Context
|
import org.apache.catalina.Context
|
||||||
import org.apache.catalina.startup.Tomcat
|
import org.apache.catalina.startup.Tomcat
|
||||||
import org.apache.tomcat.JarScanFilter
|
import org.apache.tomcat.JarScanFilter
|
||||||
|
@ -67,6 +69,23 @@ class TomcatAsyncTest extends HttpServerTest<Tomcat> implements AgentTestTrait {
|
||||||
server.destroy()
|
server.destroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def cleanup() {
|
||||||
|
// wait for async request threads to complete
|
||||||
|
await()
|
||||||
|
.atMost(15, TimeUnit.SECONDS)
|
||||||
|
.until({ !isRequestRunning() })
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean isRequestRunning() {
|
||||||
|
def result = Thread.getAllStackTraces().values().find {stackTrace ->
|
||||||
|
def element = stackTrace.find {
|
||||||
|
return it.className == "org.apache.catalina.core.AsyncContextImpl\$RunnableWrapper" && it.methodName == "run"
|
||||||
|
}
|
||||||
|
element != null
|
||||||
|
}
|
||||||
|
return result != null
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
String getContextPath() {
|
String getContextPath() {
|
||||||
return "/tomcat-context"
|
return "/tomcat-context"
|
||||||
|
|
|
@ -13,11 +13,13 @@ import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEn
|
||||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||||
|
import static org.awaitility.Awaitility.await
|
||||||
|
|
||||||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
||||||
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
|
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
|
||||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
import javax.servlet.Servlet
|
import javax.servlet.Servlet
|
||||||
import javax.servlet.ServletException
|
import javax.servlet.ServletException
|
||||||
import org.apache.catalina.Context
|
import org.apache.catalina.Context
|
||||||
|
@ -26,7 +28,6 @@ import org.apache.tomcat.JarScanFilter
|
||||||
import org.apache.tomcat.JarScanType
|
import org.apache.tomcat.JarScanType
|
||||||
import spock.lang.Unroll
|
import spock.lang.Unroll
|
||||||
|
|
||||||
|
|
||||||
@Unroll
|
@Unroll
|
||||||
class TomcatAsyncTest extends HttpServerTest<Tomcat> implements AgentTestTrait {
|
class TomcatAsyncTest extends HttpServerTest<Tomcat> implements AgentTestTrait {
|
||||||
|
|
||||||
|
@ -68,6 +69,23 @@ class TomcatAsyncTest extends HttpServerTest<Tomcat> implements AgentTestTrait {
|
||||||
server.destroy()
|
server.destroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def cleanup() {
|
||||||
|
// wait for async request threads to complete
|
||||||
|
await()
|
||||||
|
.atMost(15, TimeUnit.SECONDS)
|
||||||
|
.until({ !isRequestRunning() })
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean isRequestRunning() {
|
||||||
|
def result = Thread.getAllStackTraces().values().find {stackTrace ->
|
||||||
|
def element = stackTrace.find {
|
||||||
|
return it.className == "org.apache.catalina.core.AsyncContextImpl\$RunnableWrapper" && it.methodName == "run"
|
||||||
|
}
|
||||||
|
element != null
|
||||||
|
}
|
||||||
|
return result != null
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
String getContextPath() {
|
String getContextPath() {
|
||||||
return "/tomcat-context"
|
return "/tomcat-context"
|
||||||
|
|
Loading…
Reference in New Issue