Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit99fc50c

Browse files
committed
Testing
1 parentff61276 commit99fc50c

File tree

2 files changed

+64
-7
lines changed

2 files changed

+64
-7
lines changed

‎internal/core/concurrency.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ func ParseConcurrency(options *CompilerOptions) Concurrency {
2323
returnparseConcurrency(options.Concurrency)
2424
}
2525

26-
funcparseConcurrency(vstring)Concurrency {
26+
funcparseConcurrency(sstring)Concurrency {
2727
checkerCount:=4
2828

29-
switchstrings.ToLower(v) {
29+
switchstrings.ToLower(s) {
3030
case"default","auto","true","yes","on":
3131
break
3232
case"single","none","false","no","off":
@@ -38,8 +38,10 @@ func parseConcurrency(v string) Concurrency {
3838
case"checker-per-file":
3939
checkerCount=-1
4040
default:
41-
ifv,err:=strconv.Atoi(v);err==nil&&v>0 {
42-
checkerCount=v
41+
ifs!="" {
42+
ifv,err:=strconv.Atoi(s);err==nil&&v>0 {
43+
checkerCount=v
44+
}
4345
}
4446
}
4547

@@ -53,9 +55,11 @@ func (c Concurrency) SingleThreaded() bool {
5355
}
5456

5557
func (cConcurrency)CheckerCount(numFilesint)int {
56-
checkerCount:=min(c.checkerCount,numFiles)
57-
checkerCount=max(1,checkerCount)
58-
returncheckerCount
58+
checkerCount:=c.checkerCount
59+
ifc.checkerCount==-1 {
60+
returnmax(1,numFiles)
61+
}
62+
returnmin(max(1,checkerCount),numFiles)
5963
}
6064

6165
vartestProgramConcurrency=sync.OnceValues(func() (concurrencyConcurrency,rawstring) {

‎internal/core/concurrency_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package core
2+
3+
import (
4+
"runtime"
5+
"testing"
6+
7+
"gotest.tools/v3/assert"
8+
)
9+
10+
funcTestConcurrency(t*testing.T) {
11+
tests:= []struct {
12+
namestring
13+
opts*CompilerOptions
14+
numFilesint
15+
singleThreadedbool
16+
checkerCountint
17+
}{
18+
{"defaults",&CompilerOptions{},100,false,4},
19+
{"default",&CompilerOptions{Concurrency:"default"},100,false,4},
20+
{"auto",&CompilerOptions{Concurrency:"true"},100,false,4},
21+
{"true",&CompilerOptions{Concurrency:"true"},100,false,4},
22+
{"yes",&CompilerOptions{Concurrency:"yes"},100,false,4},
23+
{"on",&CompilerOptions{Concurrency:"on"},100,false,4},
24+
{"singleThreaded",&CompilerOptions{SingleThreaded:TSTrue},100,true,1},
25+
{"single",&CompilerOptions{Concurrency:"single"},100,true,1},
26+
{"none",&CompilerOptions{Concurrency:"none"},100,true,1},
27+
{"false",&CompilerOptions{Concurrency:"false"},100,true,1},
28+
{"no",&CompilerOptions{Concurrency:"no"},100,true,1},
29+
{"off",&CompilerOptions{Concurrency:"off"},100,true,1},
30+
{"max",&CompilerOptions{Concurrency:"max"},1000,false,runtime.GOMAXPROCS(0)},
31+
{"half",&CompilerOptions{Concurrency:"half"},1000,false,runtime.GOMAXPROCS(0)/2},
32+
{"checker-per-file",&CompilerOptions{Concurrency:"checker-per-file"},100,false,100},
33+
{"more than files",&CompilerOptions{Concurrency:"1000"},100,false,100},
34+
{"10",&CompilerOptions{Concurrency:"10"},100,false,10},
35+
{"1",&CompilerOptions{Concurrency:"1"},100,true,1},
36+
{"invalid",&CompilerOptions{Concurrency:"i dunno"},100,false,4},
37+
}
38+
39+
for_,tt:=rangetests {
40+
t.Run(tt.name,func(t*testing.T) {
41+
c:=ParseConcurrency(tt.opts)
42+
singleThreaded:=c.SingleThreaded()
43+
checkerCount:=c.CheckerCount(tt.numFiles)
44+
assert.Equal(t,singleThreaded,tt.singleThreaded)
45+
assert.Equal(t,checkerCount,tt.checkerCount)
46+
})
47+
}
48+
49+
t.Run("TestProgramConcurrency",func(t*testing.T) {
50+
c,_:=TestProgramConcurrency()
51+
assert.Assert(t,c.CheckerCount(10000)>0)
52+
})
53+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp