-
Notifications
You must be signed in to change notification settings - Fork 424
feat: thread autoscaling #1266
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
Merged
Merged
feat: thread autoscaling #1266
Changes from all commits
Commits
Show all changes
214 commits
Select commit
Hold shift + click to select a range
fe1158f
Decouple workers.
AlliBalliBaba ad34140
Moves code to separate file.
AlliBalliBaba 89b211d
Cleans up the exponential backoff.
AlliBalliBaba 7d2ab8c
Initial working implementation.
AlliBalliBaba f7e7d41
Refactors php threads to take callbacks.
AlliBalliBaba c03c59b
Cleanup.
AlliBalliBaba a9857dc
Cleanup.
AlliBalliBaba bac9555
Cleanup.
AlliBalliBaba a2f8d59
Cleanup.
AlliBalliBaba 279924c
Merge branch 'main' into refactor/start-worker-threads-directly
AlliBalliBaba 0825453
Adjusts watcher logic.
AlliBalliBaba 17d5cbe
Adjusts the watcher logic.
AlliBalliBaba 09e0ca6
Fix opcache_reset race condition.
AlliBalliBaba a726a2c
Merge branch 'main' into refactor/start-worker-threads-directly
AlliBalliBaba 7f13ada
Fixing merge conflicts and formatting.
AlliBalliBaba 13fb4bb
Prevents overlapping of TSRM reservation and script execution.
AlliBalliBaba a8a00c8
Adjustments as suggested by @dunglas.
AlliBalliBaba b4dd138
Adds error assertions.
AlliBalliBaba 03f98fa
Adds comments.
AlliBalliBaba e52dd0f
Removes logs and explicitly compares to C.false.
AlliBalliBaba cd98e33
Resets check.
AlliBalliBaba 4e2a2c6
Adds cast for safety.
AlliBalliBaba c51eb93
Fixes waitgroup overflow.
AlliBalliBaba 89d8e26
Resolves waitgroup race condition on startup.
AlliBalliBaba 3587243
Moves worker request logic to worker.go.
AlliBalliBaba ec32f0c
Removes defer.
AlliBalliBaba 4e35698
Removes call from go to c.
AlliBalliBaba 740fac7
Merge branch 'main' into refactor/start-worker-threads-directly
AlliBalliBaba 8a272cb
Fixes merge conflict.
AlliBalliBaba ecce5d5
Adds fibers test back in.
AlliBalliBaba 06ebd67
Refactors new thread loop approach.
AlliBalliBaba c811f4a
Removes redundant check.
AlliBalliBaba 6bd047a
Adds compareAndSwap.
AlliBalliBaba 55ad8ba
Refactor: removes global waitgroups and uses a 'thread state' abstrac…
AlliBalliBaba 3ffbe06
Merge branch 'main' into refactor/start-worker-threads-directly
AlliBalliBaba 01ed92b
Removes unnecessary method.
AlliBalliBaba 790cccc
Updates comment.
AlliBalliBaba 0dd2605
Removes unnecessary booleans.
AlliBalliBaba 60a66b4
test
AlliBalliBaba 4719fa8
First state machine steps.
AlliBalliBaba f72e8cb
Splits threads.
AlliBalliBaba d20e706
Minimal working implementation with broken tests.
AlliBalliBaba 6747d15
Fixes tests.
AlliBalliBaba 54dc267
Refactoring.
AlliBalliBaba 660efcd
Merge branch 'main' into refactor/start-worker-threads-directly
AlliBalliBaba 6214754
Fixes merge conflicts.
AlliBalliBaba 00eb834
Formatting
AlliBalliBaba 02b73b1
C formatting.
AlliBalliBaba 421904e
More cleanup.
AlliBalliBaba cca2a00
Allows for clean state transitions.
AlliBalliBaba ec8aeb7
Adds state tests.
AlliBalliBaba b598bd3
Adds support for thread transitioning.
AlliBalliBaba 66cedbd
Fixes the testdata path.
AlliBalliBaba 06af5d5
Formatting.
AlliBalliBaba 71c16bc
Allows transitioning back to inactive state.
AlliBalliBaba 5095342
Fixes go linting.
AlliBalliBaba 4b18059
Formatting.
AlliBalliBaba 15429d9
Removes duplication.
AlliBalliBaba c080608
Applies suggestions by @dunglas
AlliBalliBaba a166b87
Removes redundant check.
AlliBalliBaba 9491e6b
Locks the handler on restart.
AlliBalliBaba e795c86
Removes unnecessary log.
AlliBalliBaba 68fa124
Adds frankenphp admin api.
AlliBalliBaba b6cbfae
Allows booting threads at runtime.
AlliBalliBaba f185279
Adds proper admin status codes and tests.
AlliBalliBaba ea0a4fe
Makes config smaller.
AlliBalliBaba fcb5f8c
Adds max threads option and debug status.
AlliBalliBaba a43ecbe
Adds test with debug message.
AlliBalliBaba b117bff
Formatting and comments.
AlliBalliBaba ef1bd0d
Changes Unpin() logic as suggested by @withinboredom
AlliBalliBaba 8cd9061
Allows scaling regular threads.
AlliBalliBaba 9e8d8f0
Only allows POST requests.
AlliBalliBaba a8a4545
Adds suggestions by @dunglas and resolves TODO.
AlliBalliBaba 23a6362
Makes restarts fully safe.
AlliBalliBaba 62224bf
Merge branch 'refactor/start-worker-threads-directly' into feat/worke…
AlliBalliBaba 18e3e58
Will make the initial startup fail even if the watcher is enabled (as…
AlliBalliBaba 3672c60
Also adds compareAndSwap to the test.
AlliBalliBaba 38f87b7
Adds comment.
AlliBalliBaba 96265d3
Merge branch 'refactor/start-worker-threads-directly' into feat/worke…
AlliBalliBaba d97ebfe
Prevents panic on initial watcher startup.
AlliBalliBaba 950a509
Merge branch 'refactor/start-worker-threads-directly' into feat/worke…
AlliBalliBaba 5f1ec1f
Cleans up admin endpoints.
AlliBalliBaba 7c61dfa
Fixes admin test.
AlliBalliBaba 2af993e
Boots a thread in a test.
AlliBalliBaba 547139f
Sets more explicit max_threads.
AlliBalliBaba c8bf1ec
Adjusts naming.
AlliBalliBaba 7f2b94e
Adds docs.
AlliBalliBaba df78254
Changes logic to actually terminate the thread.
AlliBalliBaba ec0bc0f
Removes the test's randomness.
AlliBalliBaba 8f10407
Adds comments.
AlliBalliBaba 91c324d
Adds comments.
AlliBalliBaba ff06bd7
Scaling v1.
AlliBalliBaba 50ba106
Scaling v2.
AlliBalliBaba bfe3de1
Allows regular thread scaling.
AlliBalliBaba e9f62b9
Refactors wait-time.
AlliBalliBaba 21949dd
Explicitly requires setting max_threads.
AlliBalliBaba 39a7fc9
Removes redundant check.
AlliBalliBaba 442a558
Removes unnecessary import.
AlliBalliBaba c213fc9
Records clock time.
AlliBalliBaba 58daaa5
Saves CPU metrics of last 100 requests.
AlliBalliBaba 14925f6
Integrates CPU tracking.
AlliBalliBaba d408bdd
Replaces clock with probing.
AlliBalliBaba 8fc3293
fmt.
AlliBalliBaba 0314247
Adds autoscale tests.
AlliBalliBaba bd4af11
Merge branch 'main' into feat/auto-scale-clock-time
AlliBalliBaba dc10546
Merges main.
AlliBalliBaba 3b9f577
Fixes alpine (probably)
AlliBalliBaba 790ce4e
Fixes alpine (definitely)
AlliBalliBaba 29de62a
go fmt
AlliBalliBaba b447412
Removes unnecessary 'isProtected'
AlliBalliBaba 6fa90d6
Adds perf tests.
AlliBalliBaba 3bd7c76
Adds request status message to thread debug status.
AlliBalliBaba 45cd915
Adjusts performance tests.
AlliBalliBaba af40470
Adds an exponential backoff on request overflow.
AlliBalliBaba d5e8f86
Merge branch 'main' into feat/auto-scale-clock-time
AlliBalliBaba c7acb25
changes dir.
AlliBalliBaba 8c22cbf
Linting and formatting.
AlliBalliBaba 745b29b
Linting and formatting.
AlliBalliBaba 68ae2e4
Adds explicit scaling tests.
AlliBalliBaba 09a5caf
Adjusts perf tests.
AlliBalliBaba 3cfcb11
Uses different worker in removal test.
AlliBalliBaba cbe45fc
More formatting fixes.
AlliBalliBaba 1d8e973
Replaces inline errors and adjusts comments.
AlliBalliBaba bf48b14
Formatting.
AlliBalliBaba 4f0cc8a
Formatting.
AlliBalliBaba d483baf
Formatting.
AlliBalliBaba d222520
Merge branch 'main' into feat/auto-scale-clock-time
AlliBalliBaba 4807947
Merge branch 'main' into feat/auto-scale-clock-time
AlliBalliBaba eef7815
Implements suggestions by @dunglas.
AlliBalliBaba 601a43a
Adds note.
AlliBalliBaba 971e1dc
Formatting.
AlliBalliBaba f4f9576
suggestion: Refactor scaling strategy (#1289)
withinboredom 6ec9ad9
Merge branch 'feat/auto-scale-clock-time' of https://github.com/dungl…
AlliBalliBaba 5282e32
Resets strategy and fixes tests.
AlliBalliBaba 83d8c11
Adds scaling strategies.
AlliBalliBaba c094680
Fixes test reloading.
AlliBalliBaba 3ba080a
Prevents threads from respawning after shutdown.
AlliBalliBaba 7934b50
Adjusts transition tests.
AlliBalliBaba eb5e76d
Simplifies scaling.
AlliBalliBaba f33aaad
Merge branch 'main' into feat/auto-scale-clock-time
AlliBalliBaba 5f70afb
Shows the original request path in debug status.
AlliBalliBaba 9dcc2cd
Adds automatic thread limit calculation.
AlliBalliBaba ed90b75
Properly forwards automatic max threads.
AlliBalliBaba d047149
Adds ini overrides.
AlliBalliBaba 5bdd50c
Adds Caddy php ini directive (for testing)
AlliBalliBaba 936556b
Adds explicit nil check
AlliBalliBaba 6758903
Adds php.ini override test.
AlliBalliBaba 548d095
Fixes linting and conversions.
AlliBalliBaba 2761d9c
Fixes fuzzing tests.
AlliBalliBaba 36d3f54
clang-format
AlliBalliBaba cd5c905
Checks for original request existence on debug status.
AlliBalliBaba 98f2279
Changes the memory calculation implementation
AlliBalliBaba a16de66
Renames var.
AlliBalliBaba 6a6d040
Reduces the stall-time.
AlliBalliBaba 83e0c08
Adjusts scaling logic and comments.
AlliBalliBaba 79447b8
Swaps to unix sys package.
AlliBalliBaba 0545e1b
Only supports CPU probing on unix and SysMemory on Linux.
AlliBalliBaba 615662e
Adjusts timers and passes the main thread directly to scaling.
AlliBalliBaba 618345b
Properly overrides ini settings on startup.
AlliBalliBaba a8b2c7c
clang-format
AlliBalliBaba 9e4a9ca
Adds php_ini error.
AlliBalliBaba ca20704
Adds ini config.
AlliBalliBaba 3e20e8f
Moves ini overrides to #else.
AlliBalliBaba 7ce4c09
Adds some max_threads docs.
AlliBalliBaba 2b1427b
Shows special debug message if in-between worker requests.
AlliBalliBaba d3df9f9
Refactors ini overrides.
AlliBalliBaba 1df0c9b
formatting.
AlliBalliBaba e51c07d
Changes TODO.
AlliBalliBaba d43f6f0
trigger
AlliBalliBaba 9c1c8a8
linting
AlliBalliBaba 825735a
Resets Caddyfile.
AlliBalliBaba 7de0972
phpIniOverrides -> phpIni
AlliBalliBaba 54b28ac
Removes admin endpoints to PUT and DELETE threads.
AlliBalliBaba 0bba5f6
Puts MaxThreads for tests back in.
AlliBalliBaba bace48c
Uses gomaxprocs instead.
AlliBalliBaba a43d2c0
Adjusts docs.
AlliBalliBaba 7614435
Uses go's monotonic clock instead.
AlliBalliBaba 32a3129
Removes unused func.
AlliBalliBaba d189010
Removes old notations.
AlliBalliBaba 32517fe
Locks the thread handler on debug status.
AlliBalliBaba 1d899db
Locks the thread handler on debug status.
AlliBalliBaba 9a83ab1
Merge branch 'main' into feat/auto-scale-clock-time
AlliBalliBaba b3fd756
Merge branch 'main' into feat/auto-scale-clock-time
AlliBalliBaba e3d38b5
go fmt
AlliBalliBaba 755551a
Makes scale chan nil if scaling is not active.
AlliBalliBaba 2135354
locks before modification.
AlliBalliBaba 69597ef
Fixes race condition on restarts in tests.
AlliBalliBaba 57a1343
Merge branch 'main' into feat/auto-scale-clock-time
AlliBalliBaba 16e8169
Resets the opcache more safely.
AlliBalliBaba c038273
trigger build
AlliBalliBaba 064a368
Starts all threads as inactive.
AlliBalliBaba 60b437f
Properly removes autoscaled threads.
AlliBalliBaba 4a5cfd1
Fix.
AlliBalliBaba 954ac9e
Marks a single thread to call opcache_reset.
AlliBalliBaba 3085a65
Marks a single thread to call opcache_reset.
AlliBalliBaba a1f89e3
Resets opcache_reset logic.
AlliBalliBaba 6544a73
Downloads specific watcher version.
AlliBalliBaba 7a4aab2
Merge branch 'main' into feat/auto-scale-clock-time
AlliBalliBaba 4668112
Fixes linting.
AlliBalliBaba 1b945f7
Fixes linting.
AlliBalliBaba deec7ee
Adds suggestions by @dunglas.
AlliBalliBaba a9b1f44
Removes linux tag.
AlliBalliBaba a8ea845
Fixes linting.
AlliBalliBaba 4e03be1
Turns the debug state into json.
AlliBalliBaba 8325a4a
Adds php.ini block notation.
AlliBalliBaba 9801f24
Adds loglevel check.
AlliBalliBaba 7adc465
Removes sleep.
AlliBalliBaba 9560e9f
Adjusts test to work without opcache.
AlliBalliBaba aaceaa8
Removes unnecessary bool.
AlliBalliBaba 96c34b4
Adds more experimental warnings.
AlliBalliBaba 319f61c
Removes request locking.
AlliBalliBaba b72df13
Merge branch 'main' into feat/auto-scale-clock-time
AlliBalliBaba 7ff6322
Merge branch 'main' into feat/auto-scale-clock-time
AlliBalliBaba 4bf5b9b
Merge branch 'main' into feat/auto-scale-clock-time
AlliBalliBaba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package caddy | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "github.com/caddyserver/caddy/v2" | ||
| "github.com/dunglas/frankenphp" | ||
| "net/http" | ||
| ) | ||
|
|
||
| type FrankenPHPAdmin struct{} | ||
|
|
||
| // if the id starts with "admin.api" the module will register AdminRoutes via module.Routes() | ||
| func (FrankenPHPAdmin) CaddyModule() caddy.ModuleInfo { | ||
| return caddy.ModuleInfo{ | ||
| ID: "admin.api.frankenphp", | ||
| New: func() caddy.Module { return new(FrankenPHPAdmin) }, | ||
| } | ||
| } | ||
|
|
||
| // EXPERIMENTAL: These routes are not yet stable and may change in the future. | ||
| func (admin FrankenPHPAdmin) Routes() []caddy.AdminRoute { | ||
| return []caddy.AdminRoute{ | ||
| { | ||
| Pattern: "/frankenphp/workers/restart", | ||
| Handler: caddy.AdminHandlerFunc(admin.restartWorkers), | ||
| }, | ||
| { | ||
| Pattern: "/frankenphp/threads", | ||
| Handler: caddy.AdminHandlerFunc(admin.threads), | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func (admin *FrankenPHPAdmin) restartWorkers(w http.ResponseWriter, r *http.Request) error { | ||
| if r.Method != http.MethodPost { | ||
| return admin.error(http.StatusMethodNotAllowed, fmt.Errorf("method not allowed")) | ||
| } | ||
|
|
||
| frankenphp.RestartWorkers() | ||
| caddy.Log().Info("workers restarted from admin api") | ||
| admin.success(w, "workers restarted successfully\n") | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (admin *FrankenPHPAdmin) threads(w http.ResponseWriter, r *http.Request) error { | ||
| debugState := frankenphp.DebugState() | ||
| prettyJson, err := json.MarshalIndent(debugState, "", " ") | ||
| if err != nil { | ||
| return admin.error(http.StatusInternalServerError, err) | ||
| } | ||
|
|
||
| return admin.success(w, string(prettyJson)) | ||
| } | ||
|
|
||
| func (admin *FrankenPHPAdmin) success(w http.ResponseWriter, message string) error { | ||
| w.WriteHeader(http.StatusOK) | ||
| _, err := w.Write([]byte(message)) | ||
| return err | ||
| } | ||
|
|
||
| func (admin *FrankenPHPAdmin) error(statusCode int, err error) error { | ||
| return caddy.APIError{HTTPStatus: statusCode, Err: err} | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,215 @@ | ||
| package caddy_test | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "io" | ||
| "net/http" | ||
| "sync" | ||
| "testing" | ||
|
|
||
| "github.com/caddyserver/caddy/v2/caddytest" | ||
| "github.com/dunglas/frankenphp" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestRestartWorkerViaAdminApi(t *testing.T) { | ||
| tester := caddytest.NewTester(t) | ||
| tester.InitServer(` | ||
| { | ||
| skip_install_trust | ||
| admin localhost:2999 | ||
| http_port `+testPort+` | ||
|
|
||
| frankenphp { | ||
| worker ../testdata/worker-with-counter.php 1 | ||
| } | ||
| } | ||
|
|
||
| localhost:`+testPort+` { | ||
| route { | ||
| root ../testdata | ||
| rewrite worker-with-counter.php | ||
| php | ||
| } | ||
| } | ||
| `, "caddyfile") | ||
|
|
||
| tester.AssertGetResponse("http://localhost:"+testPort+"/", http.StatusOK, "requests:1") | ||
| tester.AssertGetResponse("http://localhost:"+testPort+"/", http.StatusOK, "requests:2") | ||
|
|
||
| assertAdminResponse(t, tester, "POST", "workers/restart", http.StatusOK, "workers restarted successfully\n") | ||
|
|
||
| tester.AssertGetResponse("http://localhost:"+testPort+"/", http.StatusOK, "requests:1") | ||
| } | ||
|
|
||
| func TestShowTheCorrectThreadDebugStatus(t *testing.T) { | ||
| tester := caddytest.NewTester(t) | ||
| tester.InitServer(` | ||
| { | ||
| skip_install_trust | ||
| admin localhost:2999 | ||
| http_port `+testPort+` | ||
|
|
||
| frankenphp { | ||
| num_threads 3 | ||
| max_threads 6 | ||
| worker ../testdata/worker-with-counter.php 1 | ||
| worker ../testdata/index.php 1 | ||
| } | ||
| } | ||
|
|
||
| localhost:`+testPort+` { | ||
| route { | ||
| root ../testdata | ||
| rewrite worker-with-counter.php | ||
| php | ||
| } | ||
| } | ||
| `, "caddyfile") | ||
|
|
||
| debugState := getDebugState(t, tester) | ||
|
|
||
| // assert that the correct threads are present in the thread info | ||
| assert.Equal(t, debugState.ThreadDebugStates[0].State, "ready") | ||
| assert.Contains(t, debugState.ThreadDebugStates[1].Name, "worker-with-counter.php") | ||
| assert.Contains(t, debugState.ThreadDebugStates[2].Name, "index.php") | ||
| assert.Equal(t, debugState.ReservedThreadCount, 3) | ||
| assert.Len(t, debugState.ThreadDebugStates, 3) | ||
| } | ||
|
|
||
| func TestAutoScaleWorkerThreads(t *testing.T) { | ||
| wg := sync.WaitGroup{} | ||
| maxTries := 10 | ||
| requestsPerTry := 200 | ||
| tester := caddytest.NewTester(t) | ||
| tester.InitServer(` | ||
| { | ||
| skip_install_trust | ||
| admin localhost:2999 | ||
| http_port `+testPort+` | ||
|
|
||
| frankenphp { | ||
| max_threads 10 | ||
| num_threads 2 | ||
| worker ../testdata/sleep.php 1 | ||
| } | ||
| } | ||
|
|
||
| localhost:`+testPort+` { | ||
| route { | ||
| root ../testdata | ||
| rewrite sleep.php | ||
| php | ||
| } | ||
| } | ||
| `, "caddyfile") | ||
|
|
||
| // spam an endpoint that simulates IO | ||
| endpoint := "http://localhost:" + testPort + "/?sleep=2&work=1000" | ||
| amountOfThreads := len(getDebugState(t, tester).ThreadDebugStates) | ||
|
|
||
| // try to spawn the additional threads by spamming the server | ||
| for tries := 0; tries < maxTries; tries++ { | ||
| wg.Add(requestsPerTry) | ||
| for i := 0; i < requestsPerTry; i++ { | ||
| go func() { | ||
| tester.AssertGetResponse(endpoint, http.StatusOK, "slept for 2 ms and worked for 1000 iterations") | ||
| wg.Done() | ||
| }() | ||
| } | ||
| wg.Wait() | ||
|
|
||
| amountOfThreads = len(getDebugState(t, tester).ThreadDebugStates) | ||
| if amountOfThreads > 2 { | ||
| break | ||
| } | ||
| } | ||
|
|
||
| // assert that there are now more threads than before | ||
| assert.NotEqual(t, amountOfThreads, 2) | ||
| } | ||
|
|
||
| // Note this test requires at least 2x40MB available memory for the process | ||
| func TestAutoScaleRegularThreadsOnAutomaticThreadLimit(t *testing.T) { | ||
| wg := sync.WaitGroup{} | ||
| maxTries := 10 | ||
| requestsPerTry := 200 | ||
| tester := caddytest.NewTester(t) | ||
| tester.InitServer(` | ||
| { | ||
| skip_install_trust | ||
| admin localhost:2999 | ||
| http_port `+testPort+` | ||
|
|
||
| frankenphp { | ||
| max_threads auto | ||
| num_threads 1 | ||
| php_ini memory_limit 40M # a reasonable limit for the test | ||
| } | ||
| } | ||
|
|
||
| localhost:`+testPort+` { | ||
| route { | ||
| root ../testdata | ||
| php | ||
| } | ||
| } | ||
| `, "caddyfile") | ||
|
|
||
| // spam an endpoint that simulates IO | ||
| endpoint := "http://localhost:" + testPort + "/sleep.php?sleep=2&work=1000" | ||
| amountOfThreads := len(getDebugState(t, tester).ThreadDebugStates) | ||
|
|
||
| // try to spawn the additional threads by spamming the server | ||
| for tries := 0; tries < maxTries; tries++ { | ||
| wg.Add(requestsPerTry) | ||
| for i := 0; i < requestsPerTry; i++ { | ||
| go func() { | ||
| tester.AssertGetResponse(endpoint, http.StatusOK, "slept for 2 ms and worked for 1000 iterations") | ||
| wg.Done() | ||
| }() | ||
| } | ||
| wg.Wait() | ||
|
|
||
| amountOfThreads = len(getDebugState(t, tester).ThreadDebugStates) | ||
| if amountOfThreads > 1 { | ||
| break | ||
| } | ||
| } | ||
|
|
||
| // assert that there are now more threads present | ||
| assert.NotEqual(t, amountOfThreads, 1) | ||
| } | ||
|
|
||
| func assertAdminResponse(t *testing.T, tester *caddytest.Tester, method string, path string, expectedStatus int, expectedBody string) { | ||
| adminUrl := "http://localhost:2999/frankenphp/" | ||
| r, err := http.NewRequest(method, adminUrl+path, nil) | ||
| assert.NoError(t, err) | ||
| if expectedBody == "" { | ||
| _ = tester.AssertResponseCode(r, expectedStatus) | ||
| return | ||
| } | ||
| _, _ = tester.AssertResponse(r, expectedStatus, expectedBody) | ||
| } | ||
|
|
||
| func getAdminResponseBody(t *testing.T, tester *caddytest.Tester, method string, path string) string { | ||
| adminUrl := "http://localhost:2999/frankenphp/" | ||
| r, err := http.NewRequest(method, adminUrl+path, nil) | ||
| assert.NoError(t, err) | ||
| resp := tester.AssertResponseCode(r, http.StatusOK) | ||
| defer resp.Body.Close() | ||
| bytes, err := io.ReadAll(resp.Body) | ||
| assert.NoError(t, err) | ||
|
|
||
| return string(bytes) | ||
| } | ||
|
|
||
| func getDebugState(t *testing.T, tester *caddytest.Tester) frankenphp.FrankenPHPDebugState { | ||
| threadStates := getAdminResponseBody(t, tester, "GET", "threads") | ||
|
|
||
| var debugStates frankenphp.FrankenPHPDebugState | ||
| err := json.Unmarshal([]byte(threadStates), &debugStates) | ||
| assert.NoError(t, err) | ||
|
|
||
| return debugStates | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.