Skip to content

Commit

Permalink
Test http server requests in parallel (#8222)
Browse files Browse the repository at this point in the history
* Test http server requests in parallel

* use executor service

* exclude some parallel
  • Loading branch information
amarziali authored Jan 16, 2025
1 parent 679f9e2 commit f1d359b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,11 @@ class JettyServlet3TestSyncDispatchOnAsyncTimeout extends JettyServlet3Test {
true
}

@Override
boolean testParallelRequest() {
false
}

@Override
void handlerSpan(TraceAssert trace, ServerEndpoint endpoint = SUCCESS) {
dispatchSpan(trace, endpoint)
Expand Down Expand Up @@ -474,6 +479,11 @@ class JettyServlet3TestAsyncDispatchOnAsyncTimeout extends JettyServlet3Test {
true
}

@Override
boolean testParallelRequest() {
false
}

@Override
void handlerSpan(TraceAssert trace, ServerEndpoint endpoint = SUCCESS) {
dispatchSpan(trace, endpoint)
Expand Down Expand Up @@ -532,6 +542,11 @@ class JettyServlet3ServeFromAsyncTimeout extends JettyServlet3Test {
boolean testException() {
false
}

@Override
boolean testParallelRequest() {
false
}
}

class IastJettyServlet3ForkedTest extends JettyServlet3TestSync {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ import org.slf4j.Logger
import org.slf4j.LoggerFactory

import javax.annotation.Nonnull
import java.util.concurrent.ExecutorCompletionService
import java.util.concurrent.Executors
import java.util.function.BiFunction
import java.util.function.Function
import java.util.function.Supplier
Expand Down Expand Up @@ -382,6 +384,10 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
false // not all servers support session ids
}

boolean testParallelRequest() {
true
}

@Override
int version() {
return 0
Expand Down Expand Up @@ -528,10 +534,21 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
@Flaky(value = "https://github.com/DataDog/dd-trace-java/issues/4690", suites = ["MuleHttpServerForkedTest"])
def "test success with #count requests"() {
setup:
def responses
def request = request(SUCCESS, method, body).build()
List<Response> responses = (1..count).collect {
return client.newCall(request).execute()
if (testParallelRequest()) {
def executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())
def completionService = new ExecutorCompletionService(executor)
(1..count).each {
completionService.submit {
client.newCall(request).execute()
}
}
responses = (1..count).collect { completionService.take().get() }
} else {
responses = (1..count).collect {client.newCall(request).execute()}
}

if (isDataStreamsEnabled()) {
TEST_DATA_STREAMS_WRITER.waitForGroups(1)
}
Expand Down

0 comments on commit f1d359b

Please sign in to comment.