You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@grails.apache.org by "jdaugherty (via GitHub)" <gi...@apache.org> on 2026/07/08 04:14:18 UTC

[PR] Add testing support option to introduce latency [grails-core]

jdaugherty opened a new pull request, #15937:
URL: https://github.com/apache/grails-core/pull/15937

   ## Description
   
   Adds a new testing support library, `grails-testing-support-latency`, that injects artificial
   latency into a running Grails application so that requests randomly take longer.
   
   **Why:** Functional tests are prone to timing bugs — assertions that race a click-triggered
   navigation, missing waits, response-ordering assumptions. These pass reliably on fast local
   machines and fail intermittently on slower CI infrastructure (see the recent
   `User1FunctionalSpec.'edit report 20'` flake in the spring-security ACL functional test app,
   which only reproduced when the server response was slow). Slowing responses down widens the
   window in which these bugs occur, turning rare flakes into deterministic failures that can be
   found and fixed locally.
   
   **What:**
   - New module `grails-testing-support-latency` (`org.apache.grails:grails-testing-support-latency`):
     - `LatencyFilter` — a `OncePerRequestFilter` that delays each matched request by a random
       amount between a configurable minimum and maximum, for a configurable fraction of requests,
       with an optional fixed seed for reproducible delay sequences. Invalid configuration
       (negative delays, `max-delay` < `min-delay`, probability outside 0..1) fails fast at startup.
     - `LatencyProperties` — bound from the `grails.testing.latency` prefix (`enabled`, `min-delay`,
       `max-delay`, `probability`, `url-patterns`, `seed`) with Spring `Duration` binding.
     - `LatencyAutoConfiguration` — conditional on `grails.testing.latency.enabled=true`, so the
       library is completely inert unless explicitly switched on; registers the filter at highest
       precedence so the delay covers the entire request pipeline.
   - New example app `grails-test-examples/latency` that enables latency for `/slow/*` only and
     confirms end-to-end behavior against the running application: matched requests take at least
     the configured minimum, unmatched requests do not.
   - Documentation: a new "Simulating Latency" section in the Functional Testing guide (dependency,
     activation, full property table, YAML example, CI usage pattern, production warning) and a
     "Latency Testing Support" entry in the What's New section.
   - Module registered in `settings.gradle` and `gradle/publish-root-config.gradle`; the BOM picks
     it up automatically via the subprojects constraint loop.
   
   **Verification performed:**
   - `./gradlew :grails-testing-support-latency:build` — 10 unit tests passing (delay bounds,
     zero-probability passthrough, configuration validation, conditional auto-configuration)
   - `./gradlew :grails-test-examples-latency:integrationTest` — 2 end-to-end tests passing
   - `./gradlew :grails-testing-support-latency:codeStyle` — clean
   - `./gradlew :grails-doc:publishGuide -x aggregateGroovydoc` — docs build clean, new sections render
   
   ## Contributor Checklist
   
   ### Issue and Scope
   
   - [ ] This PR is linked to an existing issue — **no issue exists yet**; background is provided in
         the Description above. Happy to open a ticket for the release changelog if preferred.
   - [x] This PR addresses the **complete scope** of the change: library, tests, example app, and
         documentation are all included.
   - [x] This PR contains a **single, focused change**.
   - [x] This PR targets the **correct branch**: it is a new feature (new module, no changes to any
         existing API) targeting `8.0.x`.
   
   ### Code Quality
   
   - [x] I have **added or updated tests**: unit tests for the filter and auto-configuration, plus a
         dedicated example app with integration tests confirming runtime behavior.
   - [ ] I have verified that all existing tests pass by running `./gradlew build --rerun-tasks`.
         *(Targeted builds above are green; full rerun not yet executed.)*
   - [x] My code follows the project's **code style** guidelines (`codeStyle` passes on the new module).
   - [x] This PR does **not** include mass reformatting, style-only changes, or refactoring.
   - [x] Generative AI tooling was used (Claude Code with Claude Fable 5); all output was reviewed,
         and verified against the project's quality standards via the test and style checks above.
   
   ### Licensing and Attribution
   
   - [x] All contributed code is provided under the Apache License 2.0, and every new source file
         (Groovy, Gradle, YAML, XML, AsciiDoc) includes the Apache license header.
   - [x] I have the necessary rights to submit this contribution.
   - [x] Generative AI use is disclosed per the ASF generative tooling policy: this contribution was
         prepared with assistance from Claude Code (Anthropic), with human review of all changes.
   
   ### Documentation
   
   - [x] User-facing documentation added: "Simulating Latency" section in the Functional Testing guide.
   - [x] **What's New** section updated with a "Latency Testing Support" entry.
   - [x] No breaking changes or upgrade actions — the module is new, opt-in, and inert by default, so
         no Upgrade Notes changes are needed.
   - [x] The PR description explains **what** was changed and **why**.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add testing support option to introduce latency [grails-core]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #15937:
URL: https://github.com/apache/grails-core/pull/15937#issuecomment-4911461216

   ## [Codecov](https://app.codecov.io/gh/apache/grails-core/pull/15937?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `93.33333%` with `2 lines` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 49.3450%. Comparing base ([`23045cd`](https://app.codecov.io/gh/apache/grails-core/commit/23045cd5ee629772551bf22ec931eb6b3d485215?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`8f75d23`](https://app.codecov.io/gh/apache/grails-core/commit/8f75d23ad6531d26682087893c8ecc2683999002?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/grails-core/pull/15937?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...apache/grails/testing/latency/LatencyFilter.groovy](https://app.codecov.io/gh/apache/grails-core/pull/15937?src=pr&el=tree&filepath=grails-testing-support-latency%2Fsrc%2Fmain%2Fgroovy%2Forg%2Fapache%2Fgrails%2Ftesting%2Flatency%2FLatencyFilter.groovy&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Z3JhaWxzLXRlc3Rpbmctc3VwcG9ydC1sYXRlbmN5L3NyYy9tYWluL2dyb292eS9vcmcvYXBhY2hlL2dyYWlscy90ZXN0aW5nL2xhdGVuY3kvTGF0ZW5jeUZpbHRlci5ncm9vdnk=) | 92.0000% | [0 Missing and 2 partials :warning: ](https://app.codecov.io/gh/apache/grails-core/pull/15937?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   [![Impacted file tree graph](https://app.codecov.io/gh/apache/grails-core/pull/15937/graphs/tree.svg?width=650&height=150&src=pr&token=qJrryhpk7u&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)](https://app.codecov.io/gh/apache/grails-core/pull/15937?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   ```diff
   @@                Coverage Diff                 @@
   ##                8.0.x     #15937        +/-   ##
   ==================================================
   + Coverage     49.3287%   49.3450%   +0.0163%     
   - Complexity      16768      16791        +23     
   ==================================================
     Files            1985       1987         +2     
     Lines           93327      93357        +30     
     Branches        16336      16343         +7     
   ==================================================
   + Hits            46037      46067        +30     
   + Misses          40165      40164         -1     
   - Partials         7125       7126         +1     
   ```
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/grails-core/pull/15937?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [...ls/testing/latency/LatencyAutoConfiguration.groovy](https://app.codecov.io/gh/apache/grails-core/pull/15937?src=pr&el=tree&filepath=grails-testing-support-latency%2Fsrc%2Fmain%2Fgroovy%2Forg%2Fapache%2Fgrails%2Ftesting%2Flatency%2FLatencyAutoConfiguration.groovy&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Z3JhaWxzLXRlc3Rpbmctc3VwcG9ydC1sYXRlbmN5L3NyYy9tYWluL2dyb292eS9vcmcvYXBhY2hlL2dyYWlscy90ZXN0aW5nL2xhdGVuY3kvTGF0ZW5jeUF1dG9Db25maWd1cmF0aW9uLmdyb292eQ==) | `100.0000% <100.0000%> (ø)` | |
   | [...apache/grails/testing/latency/LatencyFilter.groovy](https://app.codecov.io/gh/apache/grails-core/pull/15937?src=pr&el=tree&filepath=grails-testing-support-latency%2Fsrc%2Fmain%2Fgroovy%2Forg%2Fapache%2Fgrails%2Ftesting%2Flatency%2FLatencyFilter.groovy&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Z3JhaWxzLXRlc3Rpbmctc3VwcG9ydC1sYXRlbmN5L3NyYy9tYWluL2dyb292eS9vcmcvYXBhY2hlL2dyYWlscy90ZXN0aW5nL2xhdGVuY3kvTGF0ZW5jeUZpbHRlci5ncm9vdnk=) | `92.0000% <92.0000%> (ø)` | |
   
   ... and [2 files with indirect coverage changes](https://app.codecov.io/gh/apache/grails-core/pull/15937/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   </details>
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add testing support option to introduce latency [grails-core]

Posted by "jdaugherty (via GitHub)" <gi...@apache.org>.
jdaugherty merged PR #15937:
URL: https://github.com/apache/grails-core/pull/15937


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add testing support option to introduce latency [grails-core]

Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #15937:
URL: https://github.com/apache/grails-core/pull/15937#issuecomment-4936395247

   ## ✅ All tests passed ✅
   
   🏷️ Commit: 75605d7db197ef626c9fc8195ae8015e943f56e6
   ▶️ Tests:  44823 executed
   ⚪️ Checks: 61/61 completed
   
   ---
   _Learn more about TestLens at [testlens.app](https://testlens.app)._
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add testing support option to introduce latency [grails-core]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #15937:
URL: https://github.com/apache/grails-core/pull/15937#discussion_r3558770599


##########
grails-testing-support-latency/src/test/groovy/org/apache/grails/testing/latency/LatencyFilterSpec.groovy:
##########
@@ -0,0 +1,102 @@
+/*
+ *  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
+ *
+ *    https://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.grails.testing.latency
+
+import java.time.Duration
+
+import spock.lang.Specification
+
+import org.springframework.mock.web.MockFilterChain
+import org.springframework.mock.web.MockHttpServletRequest
+import org.springframework.mock.web.MockHttpServletResponse
+
+class LatencyFilterSpec extends Specification {
+
+    void 'delays the request by at least the configured minimum before continuing the chain'() {
+        given:
+        def filter = new LatencyFilter(new LatencyProperties(
+                minDelay: Duration.ofMillis(100),
+                maxDelay: Duration.ofMillis(100)
+        ))
+        def chain = new MockFilterChain()
+
+        when:
+        long start = System.nanoTime()
+        filter.doFilter(new MockHttpServletRequest('GET', '/report/show'), new MockHttpServletResponse(), chain)
+        long elapsedMillis = Duration.ofNanos(System.nanoTime() - start).toMillis()
+
+        then:
+        elapsedMillis >= 100

Review Comment:
   The test converts elapsed time to milliseconds via `Duration.toMillis()`, which truncates; on a 100ms sleep it can report 99ms and make this assertion flaky. Compare in nanoseconds (or add a small tolerance) to avoid rounding-related failures.



##########
grails-test-examples/latency/src/integration-test/groovy/latencyapp/LatencyFunctionalSpec.groovy:
##########
@@ -0,0 +1,62 @@
+/*
+ *  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
+ *
+ *    https://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 latencyapp
+
+import java.time.Duration
+
+import spock.lang.Specification
+
+import grails.testing.mixin.integration.Integration
+import org.apache.grails.testing.http.client.HttpClientSupport
+
+/**
+ * Confirms the behavior of the {@code grails-testing-support-latency} module against a running
+ * application. The test environment enables latency for {@code /slow/*} with a minimum delay of
+ * 1500ms (see {@code application.yml}), so matched requests must take at least that long while
+ * unmatched requests stay well under it.
+ */
+@Integration
+class LatencyFunctionalSpec extends Specification implements HttpClientSupport {
+
+    private static final long MIN_DELAY_MILLIS = 1500
+
+    void 'requests matching the latency url patterns are delayed by at least the configured minimum'() {
+        when:
+        long start = System.nanoTime()
+        def response = http('/slow/ping')
+        long elapsedMillis = Duration.ofNanos(System.nanoTime() - start).toMillis()
+
+        then:
+        response.assertStatus(200)
+        response.assertContains('pong')
+        elapsedMillis >= MIN_DELAY_MILLIS

Review Comment:
   Converting nanos to millis via `Duration.toMillis()` truncates, so elapsed time can under-report by 1ms and make the boundary assertion flaky. Compare in nanoseconds (or add a tolerance) to avoid rounding-related failures across platforms/CI.



##########
grails-test-examples/latency/src/integration-test/groovy/latencyapp/LatencyFunctionalSpec.groovy:
##########
@@ -0,0 +1,62 @@
+/*
+ *  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
+ *
+ *    https://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 latencyapp
+
+import java.time.Duration
+
+import spock.lang.Specification
+
+import grails.testing.mixin.integration.Integration
+import org.apache.grails.testing.http.client.HttpClientSupport
+
+/**
+ * Confirms the behavior of the {@code grails-testing-support-latency} module against a running
+ * application. The test environment enables latency for {@code /slow/*} with a minimum delay of
+ * 1500ms (see {@code application.yml}), so matched requests must take at least that long while
+ * unmatched requests stay well under it.
+ */
+@Integration
+class LatencyFunctionalSpec extends Specification implements HttpClientSupport {
+
+    private static final long MIN_DELAY_MILLIS = 1500
+
+    void 'requests matching the latency url patterns are delayed by at least the configured minimum'() {
+        when:
+        long start = System.nanoTime()
+        def response = http('/slow/ping')
+        long elapsedMillis = Duration.ofNanos(System.nanoTime() - start).toMillis()
+
+        then:
+        response.assertStatus(200)
+        response.assertContains('pong')
+        elapsedMillis >= MIN_DELAY_MILLIS
+    }
+
+    void 'requests outside the latency url patterns are not delayed'() {
+        when:
+        long start = System.nanoTime()
+        def response = http('/fast/ping')
+        long elapsedMillis = Duration.ofNanos(System.nanoTime() - start).toMillis()
+
+        then:
+        response.assertStatus(200)
+        response.assertContains('pong')
+        elapsedMillis < MIN_DELAY_MILLIS

Review Comment:
   This assertion has the same truncation risk as the delayed-path test: `toMillis()` can under-report elapsed time by 1ms. Switching to nanosecond comparisons removes rounding artifacts.



##########
grails-testing-support-latency/src/main/groovy/org/apache/grails/testing/latency/LatencyFilter.groovy:
##########
@@ -0,0 +1,93 @@
+/*
+ *  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
+ *
+ *    https://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.grails.testing.latency
+
+import groovy.transform.CompileStatic
+import groovy.util.logging.Slf4j
+import jakarta.servlet.FilterChain
+import jakarta.servlet.ServletException
+import jakarta.servlet.http.HttpServletRequest
+import jakarta.servlet.http.HttpServletResponse
+
+import org.springframework.web.filter.OncePerRequestFilter
+
+/**
+ * Servlet filter that delays each matched request by a random amount of time before
+ * passing it down the filter chain.
+ * <p>
+ * Slowing responses down widens the window in which timing bugs occur, turning
+ * intermittent functional test flakiness (assertions that race a navigation, missing
+ * waits, ordering assumptions) into deterministic failures. It is intended purely as a
+ * testing aid and should never be enabled in production.
+ *
+ * @see LatencyAutoConfiguration
+ * @see LatencyProperties
+ */
+@Slf4j
+@CompileStatic
+class LatencyFilter extends OncePerRequestFilter {
+
+    private final long minDelayMillis
+    private final long maxDelayMillis
+    private final double probability
+    private final Random random
+
+    LatencyFilter(LatencyProperties properties) {
+        minDelayMillis = properties.minDelay.toMillis()
+        maxDelayMillis = properties.maxDelay.toMillis()
+        probability = properties.probability
+        if (minDelayMillis < 0) {
+            throw new IllegalArgumentException("grails.testing.latency.min-delay must not be negative, was ${properties.minDelay}")
+        }
+        if (maxDelayMillis < minDelayMillis) {
+            throw new IllegalArgumentException("grails.testing.latency.max-delay (${properties.maxDelay}) " +
+                    "must not be less than min-delay (${properties.minDelay})")
+        }
+        if (probability < 0.0d || probability > 1.0d) {
+            throw new IllegalArgumentException("grails.testing.latency.probability must be between 0.0 and 1.0, was $probability")
+        }

Review Comment:
   `probability` validation doesn’t reject NaN/Infinity (both bypass the current `< 0` / `> 1` checks). Treat non-finite values as invalid so misconfiguration fails fast as intended.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add testing support option to introduce latency [grails-core]

Posted by "jdaugherty (via GitHub)" <gi...@apache.org>.
jdaugherty commented on PR #15937:
URL: https://github.com/apache/grails-core/pull/15937#issuecomment-4935373706

   Review feedback addressed in 75605d7:
   
   1. **Interrupt handling** — the filter now re-interrupts and returns instead of continuing the chain on an interrupted thread; covered by a new unit test asserting the chain is never invoked.
   2. **Zero-probability test** — configured delay reduced from 30s to 5s so a failure trips quickly instead of hanging.
   3. **Functional spec timing gap** — example now uses `min-delay: 3s` / `max-delay: 4s` with the fast-path bound at 3s.
   4. **Seed reproducibility** — caveat added to the `seed` javadoc and the guide (shared generator means delay-to-request assignment is order-dependent under concurrency); delay generation now uses `random.nextLong(min, max + 1)`.
   5. **Thread-pool note** — added next to the CI-usage paragraph in the docs.
   
   Also from the Copilot comments: elapsed-time assertions compare nanoseconds instead of truncated millis, and probability validation now rejects NaN/Infinity (with new test rows).
   
   Verified locally: `:grails-testing-support-latency:build` green (11 unit tests) and `:grails-test-examples-latency:integrationTest` green (2 tests).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add testing support option to introduce latency [grails-core]

Posted by "jdaugherty (via GitHub)" <gi...@apache.org>.
jdaugherty commented on code in PR #15937:
URL: https://github.com/apache/grails-core/pull/15937#discussion_r3558956857


##########
grails-test-examples/latency/src/integration-test/groovy/latencyapp/LatencyFunctionalSpec.groovy:
##########
@@ -0,0 +1,62 @@
+/*
+ *  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
+ *
+ *    https://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 latencyapp
+
+import java.time.Duration
+
+import spock.lang.Specification
+
+import grails.testing.mixin.integration.Integration
+import org.apache.grails.testing.http.client.HttpClientSupport
+
+/**
+ * Confirms the behavior of the {@code grails-testing-support-latency} module against a running
+ * application. The test environment enables latency for {@code /slow/*} with a minimum delay of
+ * 1500ms (see {@code application.yml}), so matched requests must take at least that long while
+ * unmatched requests stay well under it.
+ */
+@Integration
+class LatencyFunctionalSpec extends Specification implements HttpClientSupport {
+
+    private static final long MIN_DELAY_MILLIS = 1500
+
+    void 'requests matching the latency url patterns are delayed by at least the configured minimum'() {
+        when:
+        long start = System.nanoTime()
+        def response = http('/slow/ping')
+        long elapsedMillis = Duration.ofNanos(System.nanoTime() - start).toMillis()
+
+        then:
+        response.assertStatus(200)
+        response.assertContains('pong')
+        elapsedMillis >= MIN_DELAY_MILLIS

Review Comment:
   Fixed in 75605d7 — the spec now compares raw nanoseconds instead of truncating to millis.



##########
grails-test-examples/latency/src/integration-test/groovy/latencyapp/LatencyFunctionalSpec.groovy:
##########
@@ -0,0 +1,62 @@
+/*
+ *  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
+ *
+ *    https://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 latencyapp
+
+import java.time.Duration
+
+import spock.lang.Specification
+
+import grails.testing.mixin.integration.Integration
+import org.apache.grails.testing.http.client.HttpClientSupport
+
+/**
+ * Confirms the behavior of the {@code grails-testing-support-latency} module against a running
+ * application. The test environment enables latency for {@code /slow/*} with a minimum delay of
+ * 1500ms (see {@code application.yml}), so matched requests must take at least that long while
+ * unmatched requests stay well under it.
+ */
+@Integration
+class LatencyFunctionalSpec extends Specification implements HttpClientSupport {
+
+    private static final long MIN_DELAY_MILLIS = 1500
+
+    void 'requests matching the latency url patterns are delayed by at least the configured minimum'() {
+        when:
+        long start = System.nanoTime()
+        def response = http('/slow/ping')
+        long elapsedMillis = Duration.ofNanos(System.nanoTime() - start).toMillis()
+
+        then:
+        response.assertStatus(200)
+        response.assertContains('pong')
+        elapsedMillis >= MIN_DELAY_MILLIS
+    }
+
+    void 'requests outside the latency url patterns are not delayed'() {
+        when:
+        long start = System.nanoTime()
+        def response = http('/fast/ping')
+        long elapsedMillis = Duration.ofNanos(System.nanoTime() - start).toMillis()
+
+        then:
+        response.assertStatus(200)
+        response.assertContains('pong')
+        elapsedMillis < MIN_DELAY_MILLIS

Review Comment:
   Fixed in 75605d7 — same change, nanosecond comparison throughout.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add testing support option to introduce latency [grails-core]

Posted by "jdaugherty (via GitHub)" <gi...@apache.org>.
jdaugherty commented on PR #15937:
URL: https://github.com/apache/grails-core/pull/15937#issuecomment-4911316553

   @jamesfredley this gives us a way to reproduce the test run failures locally.  The idea is we can add these to our test apps to introduce latency, then have AI iterate to fix the flakiness so this isn't a problem going forward.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add testing support option to introduce latency [grails-core]

Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #15937:
URL: https://github.com/apache/grails-core/pull/15937#issuecomment-4911676326

   ## ✅ All tests passed ✅
   
   🏷️ Commit: 8f75d23ad6531d26682087893c8ecc2683999002
   ▶️ Tests:  8333 executed
   ⚪️ Checks: 61/61 completed
   
   ---
   _Learn more about TestLens at [testlens.app](https://testlens.app)._
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org