@@ -284,23 +284,42 @@ func TestCorrectThreadCalculation(t *testing.T) {
284284 testThreadCalculation (t , 2 , - 1 , & opt {maxThreads : - 1 , workers : oneWorkerThread })
285285 testThreadCalculation (t , 2 , - 1 , & opt {numThreads : 2 , maxThreads : - 1 })
286286
287+ // max_threads should be thread minimum + sum of worker max_threads
288+ testThreadCalculation (t , 2 , 6 , & opt {workers : []workerOpt {{num : 1 , maxThreads : 5 }}})
289+ testThreadCalculation (t , 6 , 9 , & opt {workers : []workerOpt {{num : 1 , maxThreads : 4 }, {num : 4 , maxThreads : 4 }}})
290+ testThreadCalculation (t , 10 , 14 , & opt {numThreads : 10 , workers : []workerOpt {{num : 1 , maxThreads : 4 }, {num : 3 , maxThreads : 4 }}})
291+
292+ // max_threads should remain equal to overall max_threads
293+ testThreadCalculation (t , 2 , 5 , & opt {maxThreads : 5 , workers : []workerOpt {{num : 1 , maxThreads : 3 }}})
294+ testThreadCalculation (t , 3 , 5 , & opt {maxThreads : 5 , workers : []workerOpt {{num : 1 , maxThreads : 4 }, {num : 1 , maxThreads : 4 }}})
295+
287296 // not enough num threads
288297 testThreadCalculationError (t , & opt {numThreads : 1 , workers : oneWorkerThread })
289298 testThreadCalculationError (t , & opt {numThreads : 1 , maxThreads : 1 , workers : oneWorkerThread })
290299
291300 // not enough max_threads
292301 testThreadCalculationError (t , & opt {numThreads : 2 , maxThreads : 1 })
293302 testThreadCalculationError (t , & opt {maxThreads : 1 , workers : oneWorkerThread })
303+
304+ // worker max_threads is bigger than overall max_threads
305+ testThreadCalculationError (t , & opt {maxThreads : 5 , workers : []workerOpt {{num : 1 , maxThreads : 10 }}})
306+
307+ // worker max_threads is smaller than num_threads
308+ testThreadCalculationError (t , & opt {workers : []workerOpt {{num : 3 , maxThreads : 2 }}})
294309}
295310
296311func testThreadCalculation (t * testing.T , expectedNumThreads int , expectedMaxThreads int , o * opt ) {
312+ t .Helper ()
313+
297314 _ , err := calculateMaxThreads (o )
298315 assert .NoError (t , err , "no error should be returned" )
299316 assert .Equal (t , expectedNumThreads , o .numThreads , "num_threads must be correct" )
300317 assert .Equal (t , expectedMaxThreads , o .maxThreads , "max_threads must be correct" )
301318}
302319
303320func testThreadCalculationError (t * testing.T , o * opt ) {
321+ t .Helper ()
322+
304323 _ , err := calculateMaxThreads (o )
305324 assert .Error (t , err , "configuration must error" )
306325}
0 commit comments