Skip to content

Commit

Permalink
Open Model Thread Group: interrupt pending HTTP requests and other In…
Browse files Browse the repository at this point in the history
…terruptible test elements on test stop

Previously, OMTG was just issuing java.lang.Thread.interrupt(),
however certain samplers require special treatment.

So now OMTG calls JMeterThread.interrupt() as well, so Interruptible
elements are interrupted as well.
  • Loading branch information
vlsi committed Jun 15, 2023
1 parent 34e3848 commit 1498605
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ public class OpenModelThreadGroup :
log.info("Terminating thread {}", thread)
// Safe stop the thread
thread.stop()
thread.interrupt()
// Interrupt it
future.cancel(true)
}
Expand Down Expand Up @@ -261,6 +262,12 @@ public class OpenModelThreadGroup :
// Graceful stop
stop()
log.info("Interrupting the threads")
activeThreads.forEach { (thread, future) ->
log.info("Interrupting thread {}", thread)
// Interrupting the thread
thread.interrupt()
future.cancel(true)
}
// Interrupting all the threads
// shutdownNow will interrupt the threads
executorService?.shutdownNow()?.forEach {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.apache.jmeter.protocol.http

import com.github.tomakehurst.wiremock.client.WireMock.aResponse
import com.github.tomakehurst.wiremock.client.WireMock.get
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo
import com.github.tomakehurst.wiremock.junit5.WireMockTest
import org.apache.jmeter.junit.JMeterTestCase
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy
import org.apache.jmeter.samplers.SampleEvent
import org.apache.jmeter.test.assertions.executePlanAndCollectEvents
import org.apache.jmeter.threads.openmodel.OpenModelThreadGroup
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Timeout
import java.util.concurrent.TimeUnit
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.seconds

@WireMockTest
class HttpRequestInterruptTest : JMeterTestCase() {
@Test
@Timeout(5, unit = TimeUnit.SECONDS)
fun `httpClient4 interrupts`(server: WireMockRuntimeInfo) {
server.wireMock.register(
get("/delayed")
.willReturn(
aResponse()
.withStatus(200)
.withFixedDelay(1.minutes.inWholeMilliseconds.toInt())
)
)

val events = executePlanAndCollectEvents(50.seconds) {
OpenModelThreadGroup::class {
scheduleString = "rate(50 / sec) random_arrivals(100 ms) pause(1 s)"
HTTPSamplerProxy::class {
method = "GET"
protocol = "http"
domain = "localhost"
port = server.httpPort
path = "/delayed"
}
}
}

assertEquals(
listOf<SampleEvent>(),
events,
"No samples expected as all the threads should be interrupted before the request completes"
)
}
}
1 change: 1 addition & 0 deletions xdocs/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Summary
<ul>
<li><issue>5682</issue><pr>717</pr> Open Model Thread Group: avoid skipping rows from CSV Data Set Config</li>
<li>Support custom thread group implementations in "Add think time" and "Save as test fragment" actions</li>
<li>Open Model Thread Group: interrupt pending HTTP requests and other <code>Interruptible</code> test elements on test stop</li>
</ul>

<h3>HTTP Samplers and Test Script Recorder</h3>
Expand Down

0 comments on commit 1498605

Please sign in to comment.