This is an automated email from the ASF dual-hosted git repository. vladimirsitnikov pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/jmeter.git
commit c46e37a4f0ef8a0aa87c2ea4fe2cab9e0423c49d Author: Vladimir Sitnikov <[email protected]> AuthorDate: Fri Jun 16 08:38:03 2023 +0300 test: CollectSamplesListener should be NoThreadClone, so it collects all the events Previously, HttpRequestInterruptTest received no events because the listener was cloned, however, the test assumed there were no events because the sampling was interrupted. --- .../openmodel/ThreadsInterruptAtFinishTest.kt | 4 +-- .../jmeter/test/samplers/CollectSamplesListener.kt | 3 ++- .../protocol/http/HttpRequestInterruptTest.kt | 30 +++++++++++++--------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/core/src/test/kotlin/org/apache/jmeter/threads/openmodel/ThreadsInterruptAtFinishTest.kt b/src/core/src/test/kotlin/org/apache/jmeter/threads/openmodel/ThreadsInterruptAtFinishTest.kt index 6e79eb8140..34d5586a65 100644 --- a/src/core/src/test/kotlin/org/apache/jmeter/threads/openmodel/ThreadsInterruptAtFinishTest.kt +++ b/src/core/src/test/kotlin/org/apache/jmeter/threads/openmodel/ThreadsInterruptAtFinishTest.kt @@ -32,9 +32,9 @@ import kotlin.time.Duration.Companion.seconds class ThreadsInterruptAtFinishTest : JMeterTestCase() { @Test - @Timeout(5, unit = TimeUnit.SECONDS) + @Timeout(10, unit = TimeUnit.SECONDS) fun `openmodel interrupts sleep`() { - executePlanAndCollectEvents(10.seconds) { + assertInterruptionsPresent { OpenModelThreadGroup::class { scheduleString = "rate(50 / sec) random_arrivals(100 ms) pause(1 s)" ThreadSleep::class { diff --git a/src/core/src/testFixtures/kotlin/org/apache/jmeter/test/samplers/CollectSamplesListener.kt b/src/core/src/testFixtures/kotlin/org/apache/jmeter/test/samplers/CollectSamplesListener.kt index 05c7aca0d3..10869b82c7 100644 --- a/src/core/src/testFixtures/kotlin/org/apache/jmeter/test/samplers/CollectSamplesListener.kt +++ b/src/core/src/testFixtures/kotlin/org/apache/jmeter/test/samplers/CollectSamplesListener.kt @@ -17,6 +17,7 @@ package org.apache.jmeter.test.samplers +import org.apache.jmeter.engine.util.NoThreadClone import org.apache.jmeter.reporters.AbstractListenerElement import org.apache.jmeter.samplers.SampleEvent import org.apache.jmeter.samplers.SampleListener @@ -25,7 +26,7 @@ import java.util.Collections /** * Collects [SampleEvent] to a list. */ -class CollectSamplesListener : AbstractListenerElement(), SampleListener { +class CollectSamplesListener : AbstractListenerElement(), SampleListener, NoThreadClone { private val mutableEvents: MutableList<SampleEvent> = Collections.synchronizedList(mutableListOf<SampleEvent>()) // Copy the events to prevent late arrivals after the test has finished diff --git a/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/HttpRequestInterruptTest.kt b/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/HttpRequestInterruptTest.kt index ac3f54e975..90e25213d2 100644 --- a/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/HttpRequestInterruptTest.kt +++ b/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/HttpRequestInterruptTest.kt @@ -22,35 +22,39 @@ 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.HTTPSamplerFactory 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 org.junit.jupiter.api.fail +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.ValueSource 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) { + @ParameterizedTest + @Timeout(10, unit = TimeUnit.SECONDS) + @ValueSource(strings = [HTTPSamplerFactory.IMPL_HTTP_CLIENT4, HTTPSamplerFactory.HTTP_SAMPLER_JAVA]) + fun `http request interrupts`(httpImplementation: String, server: WireMockRuntimeInfo) { server.wireMock.register( get("/delayed") .willReturn( aResponse() - .withStatus(200) .withFixedDelay(1.minutes.inWholeMilliseconds.toInt()) + .withStatus(200) ) ) - val events = executePlanAndCollectEvents(50.seconds) { + val events = executePlanAndCollectEvents(5.seconds) { OpenModelThreadGroup::class { scheduleString = "rate(50 / sec) random_arrivals(100 ms) pause(1 s)" HTTPSamplerProxy::class { + implementation = httpImplementation method = "GET" protocol = "http" domain = "localhost" @@ -60,10 +64,12 @@ class HttpRequestInterruptTest : JMeterTestCase() { } } - assertEquals( - listOf<SampleEvent>(), - events, - "No samples expected as all the threads should be interrupted before the request completes" - ) + assertEquals(5, events.size) { "5 events expected, got $events" } + if (events.any { it.result.isSuccessful || it.result.isResponseCodeOK || it.result.time < 500 }) { + fail( + "All events should be failing, and they should take more than 500ms since the requests " + + "should have been cancelled after 1sec. Results are: $events" + ) + } } }
