Note this test requires at least 2x40MB available memory for the process
(t *testing.T)
| 181 | |
| 182 | // Note this test requires at least 2x40MB available memory for the process |
| 183 | func TestAutoScaleRegularThreadsOnAutomaticThreadLimit(t *testing.T) { |
| 184 | wg := sync.WaitGroup{} |
| 185 | maxTries := 10 |
| 186 | requestsPerTry := 200 |
| 187 | tester := caddytest.NewTester(t) |
| 188 | tester.InitServer(` |
| 189 | { |
| 190 | skip_install_trust |
| 191 | admin localhost:2999 |
| 192 | http_port `+testPort+` |
| 193 | |
| 194 | frankenphp { |
| 195 | max_threads auto |
| 196 | num_threads 1 |
| 197 | php_ini memory_limit 40M # a reasonable limit for the test |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | localhost:`+testPort+` { |
| 202 | route { |
| 203 | root ../testdata |
| 204 | php |
| 205 | } |
| 206 | } |
| 207 | `, "caddyfile") |
| 208 | |
| 209 | // spam an endpoint that simulates IO |
| 210 | endpoint := "http://localhost:" + testPort + "/sleep.php?sleep=2&work=1000" |
| 211 | amountOfThreads := getNumThreads(t, tester) |
| 212 | |
| 213 | // try to spawn the additional threads by spamming the server |
| 214 | for range maxTries { |
| 215 | wg.Add(requestsPerTry) |
| 216 | for range requestsPerTry { |
| 217 | go func() { |
| 218 | // deferred so a t.Fatalf from a failed request doesn't leak the WaitGroup |
| 219 | defer wg.Done() |
| 220 | tester.AssertGetResponse(endpoint, http.StatusOK, "slept for 2 ms and worked for 1000 iterations") |
| 221 | }() |
| 222 | } |
| 223 | wg.Wait() |
| 224 | |
| 225 | amountOfThreads = getNumThreads(t, tester) |
| 226 | if amountOfThreads > 1 || t.Failed() { |
| 227 | break |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | // assert that there are now more threads present |
| 232 | assert.NotEqual(t, amountOfThreads, 1) |
| 233 | } |
| 234 | |
| 235 | func assertAdminResponse(t *testing.T, tester *caddytest.Tester, method string, path string, expectedStatus int, expectedBody string) { |
| 236 | adminUrl := "http://localhost:2999/frankenphp/" |
nothing calls this directly
no test coverage detected