|
| 1 | +package core |
| 2 | + |
| 3 | +import ( |
| 4 | + "runtime" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "gotest.tools/v3/assert" |
| 8 | +) |
| 9 | + |
| 10 | +func TestConcurrency(t *testing.T) { |
| 11 | + tests := []struct { |
| 12 | + name string |
| 13 | + opts *CompilerOptions |
| 14 | + numFiles int |
| 15 | + singleThreaded bool |
| 16 | + checkerCount int |
| 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 := range tests { |
| 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