Skip to content

Commit

Permalink
🐛 minor fixes to test runner
Browse files Browse the repository at this point in the history
Signed-off-by: Pranav Gaikwad <[email protected]>
  • Loading branch information
pranavgaikwad committed Apr 12, 2024
1 parent 893ca13 commit 2e60b79
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func NewTestCommand(log logr.Logger) *cobra.Command {
RunLocal: Settings.RunLocal,
ContainerImage: Settings.RunnerImage,
ProgressPrinter: testing.PrintProgress,
Log: log.V(3),
})
testing.PrintSummary(os.Stdout, results)
if err != nil {
Expand Down
22 changes: 13 additions & 9 deletions pkg/testing/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,20 @@ type TestOptions struct {
RunLocal bool
ContainerImage string
ProgressPrinter ResultPrinter
Log logr.Logger
}

// TODO (pgaikwad): we need to move the default config to a common place
// to be shared between kantra analyze command and this
var defaultProviderConfig = []provider.Config{
{
Name: "java",
BinaryPath: "/jdtls/bin/jdtls",
BinaryPath: "/usr/local/bin/java-external-provider",
InitConfig: []provider.InitConfig{
{
AnalysisMode: provider.FullAnalysisMode,
ProviderSpecificConfig: map[string]interface{}{
"lspServerName": "java",
"bundles": "/jdtls/java-analyzer-bundle/java-analyzer-bundle.core/target/java-analyzer-bundle.core-1.0.0-SNAPSHOT.jar",
"depOpenSourceLabelsFile": "/usr/local/etc/maven.default.index",
provider.LspServerPathConfigKey: "/jdtls/bin/jdtls",
Expand Down Expand Up @@ -139,19 +141,16 @@ func (r defaultRunner) Run(testFiles []TestsFile, opts TestOptions) ([]Result, e

wg := &sync.WaitGroup{}

workerCount := 5
// when running in container, we don't want to mount
// same base volumes concurrently in two different places
if !opts.RunLocal {
workerCount = 1
}
workerCount := 1
// setup workers
for idx := 0; idx < workerCount; idx += 1 {
wg.Add(1)
go runWorker(wg, workerInputChan, resChan)
go runWorker(wg, workerInputChan, resChan, opts.Log)
}
// send input
wg.Add(1)
go func() {
defer wg.Done()
for idx := range testFiles {
testFile := testFiles[idx]
workerInputChan <- workerInput{
Expand Down Expand Up @@ -203,7 +202,7 @@ func (r defaultRunner) Run(testFiles []TestsFile, opts TestOptions) ([]Result, e
return results, nil
}

func runWorker(wg *sync.WaitGroup, inChan chan workerInput, outChan chan []Result) {
func runWorker(wg *sync.WaitGroup, inChan chan workerInput, outChan chan []Result, log logr.Logger) {
defer wg.Done()
for input := range inChan {
results := []Result{}
Expand All @@ -222,6 +221,7 @@ func runWorker(wg *sync.WaitGroup, inChan chan workerInput, outChan chan []Resul
Error: fmt.Errorf("failed creating temp dir - %w", err)})
continue
}
log.Info("created temporary directory", "dir", tempDir, "tests", input.testsFile.Path)
// print analysis logs to a file
logFile, err := os.OpenFile(filepath.Join(tempDir, "analysis.log"), os.O_CREATE|os.O_APPEND|os.O_RDWR, 0644)
if err != nil {
Expand Down Expand Up @@ -338,6 +338,8 @@ func runLocal(logFile io.Writer, dir string, analysisParams AnalysisParams) (str
filepath.Join(dir, "output.yaml"),
"--rules",
filepath.Join(dir, "rules.yaml"),
"--verbose",
"20",
}
if analysisParams.DepLabelSelector != "" {
args = append(args, []string{
Expand All @@ -363,6 +365,8 @@ func runInContainer(consoleLogger logr.Logger, image string, logFile io.Writer,
"/shared/output.yaml",
"--rules",
"/shared/rules.yaml",
"--verbose",
"20",
}
if analysisParams.DepLabelSelector != "" {
args = append(args, []string{
Expand Down

0 comments on commit 2e60b79

Please sign in to comment.