Skip to content

Commit e34b82b

Browse files
AlliBalliBabadunglas
authored andcommitted
refactor: removes 'Max Threads'
1 parent af057a9 commit e34b82b

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

caddy/admin_test.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func TestAutoScaleWorkerThreads(t *testing.T) {
109109

110110
// spam an endpoint that simulates IO
111111
endpoint := "http://localhost:" + testPort + "/?sleep=2&work=1000"
112-
amountOfThreads := len(getDebugState(t, tester).ThreadDebugStates)
112+
amountOfThreads := getNumThreads(t, tester)
113113

114114
// try to spawn the additional threads by spamming the server
115115
for range maxTries {
@@ -122,7 +122,7 @@ func TestAutoScaleWorkerThreads(t *testing.T) {
122122
}
123123
wg.Wait()
124124

125-
amountOfThreads = len(getDebugState(t, tester).ThreadDebugStates)
125+
amountOfThreads = getNumThreads(t, tester)
126126
if amountOfThreads > 2 {
127127
break
128128
}
@@ -161,7 +161,7 @@ func TestAutoScaleRegularThreadsOnAutomaticThreadLimit(t *testing.T) {
161161

162162
// spam an endpoint that simulates IO
163163
endpoint := "http://localhost:" + testPort + "/sleep.php?sleep=2&work=1000"
164-
amountOfThreads := len(getDebugState(t, tester).ThreadDebugStates)
164+
amountOfThreads := getNumThreads(t, tester)
165165

166166
// try to spawn the additional threads by spamming the server
167167
for range maxTries {
@@ -174,7 +174,7 @@ func TestAutoScaleRegularThreadsOnAutomaticThreadLimit(t *testing.T) {
174174
}
175175
wg.Wait()
176176

177-
amountOfThreads = len(getDebugState(t, tester).ThreadDebugStates)
177+
amountOfThreads = getNumThreads(t, tester)
178178
if amountOfThreads > 1 {
179179
break
180180
}
@@ -208,6 +208,7 @@ func getAdminResponseBody(t *testing.T, tester *caddytest.Tester, method string,
208208
}
209209

210210
func getDebugState(t *testing.T, tester *caddytest.Tester) frankenphp.FrankenPHPDebugState {
211+
t.Helper()
211212
threadStates := getAdminResponseBody(t, tester, "GET", "threads")
212213

213214
var debugStates frankenphp.FrankenPHPDebugState
@@ -217,6 +218,11 @@ func getDebugState(t *testing.T, tester *caddytest.Tester) frankenphp.FrankenPHP
217218
return debugStates
218219
}
219220

221+
func getNumThreads(t *testing.T, tester *caddytest.Tester) int {
222+
t.Helper()
223+
return len(getDebugState(t, tester).ThreadDebugStates)
224+
}
225+
220226
func TestAddModuleWorkerViaAdminApi(t *testing.T) {
221227
// Initialize a server with admin API enabled
222228
tester := caddytest.NewTester(t)

caddy/caddy_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414

1515
"github.com/caddyserver/caddy/v2"
1616
"github.com/caddyserver/caddy/v2/caddytest"
17-
"github.com/dunglas/frankenphp"
1817
"github.com/dunglas/frankenphp/internal/fastabs"
1918
"github.com/prometheus/client_golang/prometheus/testutil"
2019
"github.com/stretchr/testify/require"
@@ -475,7 +474,7 @@ func TestMetrics(t *testing.T) {
475474
_, err = metrics.ReadFrom(resp.Body)
476475
require.NoError(t, err, "failed to read metrics")
477476

478-
cpus := fmt.Sprintf("%d", frankenphp.MaxThreads)
477+
cpus := strconv.Itoa(getNumThreads(t, tester))
479478

480479
// Check metrics
481480
expectedMetrics := `
@@ -548,7 +547,7 @@ func TestWorkerMetrics(t *testing.T) {
548547
_, err = metrics.ReadFrom(resp.Body)
549548
require.NoError(t, err, "failed to read metrics")
550549

551-
cpus := fmt.Sprintf("%d", frankenphp.MaxThreads)
550+
cpus := strconv.Itoa(getNumThreads(t, tester))
552551

553552
// Check metrics
554553
expectedMetrics := `
@@ -640,7 +639,7 @@ func TestNamedWorkerMetrics(t *testing.T) {
640639
_, err = metrics.ReadFrom(resp.Body)
641640
require.NoError(t, err, "failed to read metrics")
642641

643-
cpus := fmt.Sprintf("%d", frankenphp.MaxThreads)
642+
cpus := strconv.Itoa(getNumThreads(t, tester))
644643

645644
// Check metrics
646645
expectedMetrics := `
@@ -731,8 +730,9 @@ func TestAutoWorkerConfig(t *testing.T) {
731730
_, err = metrics.ReadFrom(resp.Body)
732731
require.NoError(t, err, "failed to read metrics")
733732

734-
cpus := fmt.Sprintf("%d", frankenphp.MaxThreads)
735-
workers := fmt.Sprintf("%d", frankenphp.MaxThreads-1)
733+
numThreads := getNumThreads(t, tester)
734+
cpus := strconv.Itoa(numThreads)
735+
workers := strconv.Itoa(numThreads - 1)
736736

737737
// Check metrics
738738
expectedMetrics := `
@@ -1093,7 +1093,7 @@ func TestMultiWorkersMetrics(t *testing.T) {
10931093
_, err = metrics.ReadFrom(resp.Body)
10941094
require.NoError(t, err, "failed to read metrics")
10951095

1096-
cpus := fmt.Sprintf("%d", frankenphp.MaxThreads)
1096+
cpus := strconv.Itoa(getNumThreads(t, tester))
10971097

10981098
// Check metrics
10991099
expectedMetrics := `

frankenphp.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,6 @@ func Config() PHPConfig {
140140
}
141141
}
142142

143-
// MaxThreads is internally used during tests. It is written to, but never read and may go away in the future.
144-
var MaxThreads int
145-
146143
func calculateMaxThreads(opt *opt) (int, int, int, error) {
147144
maxProcs := runtime.GOMAXPROCS(0) * 2
148145

@@ -253,7 +250,6 @@ func Init(options ...Option) error {
253250
}
254251

255252
metrics.TotalThreads(totalThreadCount)
256-
MaxThreads = totalThreadCount
257253

258254
config := Config()
259255

0 commit comments

Comments
 (0)