-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TT-14070: [Testing/Concurrency] Test gateway lifecycle, enable start/stop parallelism #6677
Conversation
aa5bb05
to
200bd10
Compare
200bd10
to
bdcb415
Compare
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
API Changes --- prev.txt 2025-02-13 21:09:40.338079939 +0000
+++ current.txt 2025-02-13 21:09:36.241055024 +0000
@@ -4938,7 +4938,8 @@
FUNCTIONS
func Init(confPaths []string)
- Init sets all flags and subcommands.
+ Init sets all flags and subcommands. It's only run once to avoid races over
+ the globals. The arguments are ignored for subsequent runs.
func Parse()
Parse parses the command-line arguments.
@@ -5099,7 +5100,7 @@
valid config file.
func WriteConf(path string, conf *Config) error
-func WriteDefault(path string, conf *Config) error
+func WriteDefault(in string, conf *Config) error
writeDefault will set conf to the default config and write it to disk in
path, if the path is non-empty.
@@ -10818,7 +10819,11 @@
RemoveApis clean all the apis from a living gw
func (s *Test) ResetTestConfig()
- ResetTestConfig resets the config for the global gateway
+ Deprecated: ResetTestConfig resets the config for the global gateway.
+
+ The function does nothing, the correct way is to reuse StartTest(), filling
+ the config from the provided callback. Usage impacts a few tests (small).
+ See TestCustomDomain for an updated test.
func (s *Test) Run(t testing.TB, testCases ...test.TestCase) (*http.Response, error)
@@ -12617,6 +12622,10 @@
package templates // import "github.com/TykTechnologies/tyk/templates"
+
+VARIABLES
+
+var Assets embed.FS
# Package: ./test
package test // import "github.com/TykTechnologies/tyk/test"
@@ -12859,6 +12868,8 @@
package coprocess // import "github.com/TykTechnologies/tyk/tests/coprocess"
+# Package: ./tests/lifecycle
+
# Package: ./tests/policy
package policy // import "github.com/TykTechnologies/tyk/tests/policy" |
9dd4508
to
f1996d3
Compare
ae82a17
to
f202274
Compare
|
…stop parallelism (#6677) ### **User description** JIRA: https://tyktech.atlassian.net/browse/TT-14070 This adds an aggresive test against the gateway test lifecycle. It concurrently starts and stops an unbounded amount of gateway test servers and attempts to exit the test after 5 seconds with a timeout. As long as garbage collection occurs often enough, the test seems stable but still fails sporadically (races, leaks). The test is also significantly bottlenecked by runtime.GC. If to run it once every 256 gateway cycles, the throughput is 6657 start/stops in 5 seconds, if to run it on every start stop then only 500 start/stops get done in 5 seconds. To opt into the test: ``` cd tests/lifecycle task test ``` The test is not run in CI, would need `TEST_LIFECYCLE=1` enabled, which the taskfile does. PR fixes a set of minor issues: - config.WriteDefault would not work correctly for built gateway, now uses os.Getwd (working dir), - tests require a test-environment driven TemplatePath setting (gateway/testutil) - cleared ResetDefaultConfig in favor of StartTest practices established - moves gateway globalMu usage into initSystem, preventing most concurrency issues over globals - cli.Init is invoked in each test, as it holds global app state, overwrites needlessly The ideal outcome is us being able to all tests that rely on StartTest/Gateway lifecycle in parallel. ___ ### **PR Type** Tests, Enhancement, Bug fix ___ ### **Description** - Introduced a new lifecycle test for gateway concurrency. - Enhanced configuration handling and reduced global state races. - Improved test utilities and removed deprecated methods. - Added a Taskfile for lifecycle test execution and dependencies. ___ ### **Changes walkthrough** 📝 <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><details><summary>5 files</summary><table> <tr> <td><strong>cli.go</strong><dd><code>Added synchronization to `Init` to prevent race conditions.</code></dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6677/files#diff-ef44b92f1ba3916c39c98fc4a25b67da847cb2a07a5d1253e1978365338888a6">+11/-0</a> </td> </tr> <tr> <td><strong>api_definition.go</strong><dd><code>Refactored template loading for better modularity.</code> </dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6677/files#diff-0cf80174bbafb36f6d4f4308ebbd971b2833b76a936bad568220aa1a4ba0ee8b">+8/-6</a> </td> </tr> <tr> <td><strong>server.go</strong><dd><code>Moved <code>globalMu</code> locking to <code>initSystem</code> for better concurrency handling.</code></dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6677/files#diff-4652d1bf175a0be8f5e61ef7177c9666f23e077d8626b73ac9d13358fa8b525b">+3/-3</a> </td> </tr> <tr> <td><strong>testutil.go</strong><dd><code>Deprecated <code>ResetTestConfig</code> and improved test gateway initialization.</code></dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6677/files#diff-7aaf6ae49fb8f58a8c99d337fedd15b3e430dd928ed547e425ef429b10d28ce8">+6/-5</a> </td> </tr> <tr> <td><strong>doc.go</strong><dd><code>Embedded assets into the `templates` package.</code> </dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6677/files#diff-3c9b7851d3f50425fde5c52285b28898286ec096260f534ba8e1237f4e50845d">+6/-1</a> </td> </tr> </table></details></td></tr><tr><td><strong>Bug fix</strong></td><td><details><summary>1 files</summary><table> <tr> <td><strong>config.go</strong><dd><code>Improved `WriteDefault` to use working directory for templates.</code></dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6677/files#diff-fe44f09c4d5977b5f5eaea29170b6a0748819c9d02271746a20d81a5f3efca17">+8/-8</a> </td> </tr> </table></details></td></tr><tr><td><strong>Tests</strong></td><td><details><summary>3 files</summary><table> <tr> <td><strong>api_loader_test.go</strong><dd><code>Added cleanup for test lifecycle in </code><br><code><code>TestDifferentDomainsIdenticalListenPaths</code>.</code></dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6677/files#diff-f696545a659f4d96421b253edef4bcc8da0e7f52120b8f8866d32cbbb7cc1afc">+1/-0</a> </td> </tr> <tr> <td><strong>gateway_test.go</strong><dd><code>Updated `TestCustomDomain` to use `StartTest` for better isolation.</code></dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6677/files#diff-d34c7069ce5e81d45082b19eb3e869ee1a086e185dcd6630e75e3ed0d368b546">+6/-7</a> </td> </tr> <tr> <td><strong>lifecycle_test.go</strong><dd><code>Added a new lifecycle test to stress gateway start/stop.</code> </dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6677/files#diff-660cd4405468eea4e010f335102cbe84208c499e8109879d8c7d555837318d58">+84/-0</a> </td> </tr> </table></details></td></tr><tr><td><strong>Dependencies</strong></td><td><details><summary>2 files</summary><table> <tr> <td><strong>go.mod</strong><dd><code>Added `gopsutil` dependency for memory stats in lifecycle tests.</code></dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6677/files#diff-33ef32bf6c23acb95f5902d7097b7a1d5128ca061167ec0716715b0b9eeaa5f6">+2/-0</a> </td> </tr> <tr> <td><strong>go.sum</strong><dd><code>Updated dependencies to include `gopsutil` and related modules.</code></dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6677/files#diff-3295df7234525439d778f1b282d146a4f1ff6b415248aaac074e8042d9f42d63">+4/-0</a> </td> </tr> </table></details></td></tr><tr><td><strong>Configuration changes</strong></td><td><details><summary>1 files</summary><table> <tr> <td><strong>Taskfile.yml</strong><dd><code>Added Taskfile for lifecycle test execution and formatting.</code></dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6677/files#diff-26fa267644899f01d01db0404f6c0d1269c42fe76e340b8fb2017e966c56a132">+56/-0</a> </td> </tr> </table></details></td></tr></tr></tbody></table> ___ > <details> <summary> Need help?</summary><li>Type <code>/help how to ...</code> in the comments thread for any questions about PR-Agent usage.</li><li>Check out the <a href="https://qodo-merge-docs.qodo.ai/usage-guide/">documentation</a> for more information.</li></details> --------- Co-authored-by: Tit Petric <[email protected]>
…stop parallelism (#6677) ### **User description** JIRA: https://tyktech.atlassian.net/browse/TT-14070 This adds an aggresive test against the gateway test lifecycle. It concurrently starts and stops an unbounded amount of gateway test servers and attempts to exit the test after 5 seconds with a timeout. As long as garbage collection occurs often enough, the test seems stable but still fails sporadically (races, leaks). The test is also significantly bottlenecked by runtime.GC. If to run it once every 256 gateway cycles, the throughput is 6657 start/stops in 5 seconds, if to run it on every start stop then only 500 start/stops get done in 5 seconds. To opt into the test: ``` cd tests/lifecycle task test ``` The test is not run in CI, would need `TEST_LIFECYCLE=1` enabled, which the taskfile does. PR fixes a set of minor issues: - config.WriteDefault would not work correctly for built gateway, now uses os.Getwd (working dir), - tests require a test-environment driven TemplatePath setting (gateway/testutil) - cleared ResetDefaultConfig in favor of StartTest practices established - moves gateway globalMu usage into initSystem, preventing most concurrency issues over globals - cli.Init is invoked in each test, as it holds global app state, overwrites needlessly The ideal outcome is us being able to all tests that rely on StartTest/Gateway lifecycle in parallel. ___ ### **PR Type** Tests, Enhancement, Bug fix ___ ### **Description** - Introduced a new lifecycle test for gateway concurrency. - Enhanced configuration handling and reduced global state races. - Improved test utilities and removed deprecated methods. - Added a Taskfile for lifecycle test execution and dependencies. ___ ### **Changes walkthrough** 📝 <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><details><summary>5 files</summary><table> <tr> <td><strong>cli.go</strong><dd><code>Added synchronization to `Init` to prevent race conditions.</code></dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6677/files#diff-ef44b92f1ba3916c39c98fc4a25b67da847cb2a07a5d1253e1978365338888a6">+11/-0</a> </td> </tr> <tr> <td><strong>api_definition.go</strong><dd><code>Refactored template loading for better modularity.</code> </dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6677/files#diff-0cf80174bbafb36f6d4f4308ebbd971b2833b76a936bad568220aa1a4ba0ee8b">+8/-6</a> </td> </tr> <tr> <td><strong>server.go</strong><dd><code>Moved <code>globalMu</code> locking to <code>initSystem</code> for better concurrency handling.</code></dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6677/files#diff-4652d1bf175a0be8f5e61ef7177c9666f23e077d8626b73ac9d13358fa8b525b">+3/-3</a> </td> </tr> <tr> <td><strong>testutil.go</strong><dd><code>Deprecated <code>ResetTestConfig</code> and improved test gateway initialization.</code></dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6677/files#diff-7aaf6ae49fb8f58a8c99d337fedd15b3e430dd928ed547e425ef429b10d28ce8">+6/-5</a> </td> </tr> <tr> <td><strong>doc.go</strong><dd><code>Embedded assets into the `templates` package.</code> </dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6677/files#diff-3c9b7851d3f50425fde5c52285b28898286ec096260f534ba8e1237f4e50845d">+6/-1</a> </td> </tr> </table></details></td></tr><tr><td><strong>Bug fix</strong></td><td><details><summary>1 files</summary><table> <tr> <td><strong>config.go</strong><dd><code>Improved `WriteDefault` to use working directory for templates.</code></dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6677/files#diff-fe44f09c4d5977b5f5eaea29170b6a0748819c9d02271746a20d81a5f3efca17">+8/-8</a> </td> </tr> </table></details></td></tr><tr><td><strong>Tests</strong></td><td><details><summary>3 files</summary><table> <tr> <td><strong>api_loader_test.go</strong><dd><code>Added cleanup for test lifecycle in </code><br><code><code>TestDifferentDomainsIdenticalListenPaths</code>.</code></dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6677/files#diff-f696545a659f4d96421b253edef4bcc8da0e7f52120b8f8866d32cbbb7cc1afc">+1/-0</a> </td> </tr> <tr> <td><strong>gateway_test.go</strong><dd><code>Updated `TestCustomDomain` to use `StartTest` for better isolation.</code></dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6677/files#diff-d34c7069ce5e81d45082b19eb3e869ee1a086e185dcd6630e75e3ed0d368b546">+6/-7</a> </td> </tr> <tr> <td><strong>lifecycle_test.go</strong><dd><code>Added a new lifecycle test to stress gateway start/stop.</code> </dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6677/files#diff-660cd4405468eea4e010f335102cbe84208c499e8109879d8c7d555837318d58">+84/-0</a> </td> </tr> </table></details></td></tr><tr><td><strong>Dependencies</strong></td><td><details><summary>2 files</summary><table> <tr> <td><strong>go.mod</strong><dd><code>Added `gopsutil` dependency for memory stats in lifecycle tests.</code></dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6677/files#diff-33ef32bf6c23acb95f5902d7097b7a1d5128ca061167ec0716715b0b9eeaa5f6">+2/-0</a> </td> </tr> <tr> <td><strong>go.sum</strong><dd><code>Updated dependencies to include `gopsutil` and related modules.</code></dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6677/files#diff-3295df7234525439d778f1b282d146a4f1ff6b415248aaac074e8042d9f42d63">+4/-0</a> </td> </tr> </table></details></td></tr><tr><td><strong>Configuration changes</strong></td><td><details><summary>1 files</summary><table> <tr> <td><strong>Taskfile.yml</strong><dd><code>Added Taskfile for lifecycle test execution and formatting.</code></dd></td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6677/files#diff-26fa267644899f01d01db0404f6c0d1269c42fe76e340b8fb2017e966c56a132">+56/-0</a> </td> </tr> </table></details></td></tr></tr></tbody></table> ___ > <details> <summary> Need help?</summary><li>Type <code>/help how to ...</code> in the comments thread for any questions about PR-Agent usage.</li><li>Check out the <a href="https://qodo-merge-docs.qodo.ai/usage-guide/">documentation</a> for more information.</li></details> --------- Co-authored-by: Tit Petric <[email protected]>
User description
JIRA: https://tyktech.atlassian.net/browse/TT-14070
This adds an aggresive test against the gateway test lifecycle. It concurrently starts and stops an unbounded amount of gateway test servers and attempts to exit the test after 5 seconds with a timeout. As long as garbage collection occurs often enough, the test seems stable but still fails sporadically (races, leaks).
The test is also significantly bottlenecked by runtime.GC. If to run it once every 256 gateway cycles, the throughput is 6657 start/stops in 5 seconds, if to run it on every start stop then only 500 start/stops get done in 5 seconds.
To opt into the test:
The test is not run in CI, would need
TEST_LIFECYCLE=1
enabled, which the taskfile does.PR fixes a set of minor issues:
The ideal outcome is us being able to run all tests that rely on StartTest/Gateway lifecycle in parallel.
PR Type
Tests, Enhancement, Bug fix
Description
Introduced a new lifecycle test for gateway concurrency.
Enhanced configuration handling and reduced global state races.
Improved test utilities and removed deprecated methods.
Added a Taskfile for lifecycle test execution and dependencies.
Changes walkthrough 📝
5 files
Added synchronization to `Init` to prevent race conditions.
Refactored template loading for better modularity.
Moved
globalMu
locking toinitSystem
for better concurrency handling.Deprecated
ResetTestConfig
and improved test gateway initialization.Embedded assets into the `templates` package.
1 files
Improved `WriteDefault` to use working directory for templates.
3 files
Added cleanup for test lifecycle in
TestDifferentDomainsIdenticalListenPaths
.Updated `TestCustomDomain` to use `StartTest` for better isolation.
Added a new lifecycle test to stress gateway start/stop.
2 files
Added `gopsutil` dependency for memory stats in lifecycle tests.
Updated dependencies to include `gopsutil` and related modules.
1 files
Added Taskfile for lifecycle test execution and formatting.