|
| 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 | +} |