MCPcopy Index your code
hub / github.com/php/frankenphp / TestCorrectThreadCalculation

Function TestCorrectThreadCalculation

phpmainthread_test.go:264–308  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

262}
263
264func TestCorrectThreadCalculation(t *testing.T) {
265 maxProcs := runtime.GOMAXPROCS(0) * 2
266 oneWorkerThread := []workerOpt{{num: 1}}
267
268 // default values
269 testThreadCalculation(t, maxProcs, maxProcs, &opt{})
270 testThreadCalculation(t, maxProcs, maxProcs, &opt{workers: oneWorkerThread})
271
272 // num_threads is set
273 testThreadCalculation(t, 1, 1, &opt{numThreads: 1})
274 testThreadCalculation(t, 2, 2, &opt{numThreads: 2, workers: oneWorkerThread})
275
276 // max_threads is set
277 testThreadCalculation(t, 1, 10, &opt{maxThreads: 10})
278 testThreadCalculation(t, 2, 10, &opt{maxThreads: 10, workers: oneWorkerThread})
279 testThreadCalculation(t, 5, 10, &opt{numThreads: 5, maxThreads: 10, workers: oneWorkerThread})
280
281 // automatic max_threads
282 testThreadCalculation(t, 1, -1, &opt{maxThreads: -1})
283 testThreadCalculation(t, 2, -1, &opt{maxThreads: -1, workers: oneWorkerThread})
284 testThreadCalculation(t, 2, -1, &opt{numThreads: 2, maxThreads: -1})
285
286 // max_threads should be thread minimum + sum of worker max_threads
287 testThreadCalculation(t, 2, 6, &opt{workers: []workerOpt{{num: 1, maxThreads: 5}}})
288 testThreadCalculation(t, 6, 9, &opt{workers: []workerOpt{{num: 1, maxThreads: 4}, {num: 4, maxThreads: 4}}})
289 testThreadCalculation(t, 10, 14, &opt{numThreads: 10, workers: []workerOpt{{num: 1, maxThreads: 4}, {num: 3, maxThreads: 4}}})
290
291 // max_threads should remain equal to overall max_threads
292 testThreadCalculation(t, 2, 5, &opt{maxThreads: 5, workers: []workerOpt{{num: 1, maxThreads: 3}}})
293 testThreadCalculation(t, 3, 5, &opt{maxThreads: 5, workers: []workerOpt{{num: 1, maxThreads: 4}, {num: 1, maxThreads: 4}}})
294
295 // not enough num threads
296 testThreadCalculationError(t, &opt{numThreads: 1, workers: oneWorkerThread})
297 testThreadCalculationError(t, &opt{numThreads: 1, maxThreads: 1, workers: oneWorkerThread})
298
299 // not enough max_threads
300 testThreadCalculationError(t, &opt{numThreads: 2, maxThreads: 1})
301 testThreadCalculationError(t, &opt{maxThreads: 1, workers: oneWorkerThread})
302
303 // worker max_threads is bigger than overall max_threads
304 testThreadCalculationError(t, &opt{maxThreads: 5, workers: []workerOpt{{num: 1, maxThreads: 10}}})
305
306 // worker max_threads is smaller than num_threads
307 testThreadCalculationError(t, &opt{workers: []workerOpt{{num: 3, maxThreads: 2}}})
308}
309
310func testThreadCalculation(t *testing.T, expectedNumThreads int, expectedMaxThreads int, o *opt) {
311 t.Helper()

Callers

nothing calls this directly

Calls 2

testThreadCalculationFunction · 0.85

Tested by

no test coverage detected