Skip to content

Commit

Permalink
parallel execution of checks, release 0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
abulimov committed Apr 8, 2016
1 parent 9251ebc commit c2c2da1
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## v0.4.0 [2016-04-08]

- Execute checks in parallel
- More tests

## v0.3.0 [2016-04-08]

- Added deprecated rules check
Expand Down
1 change: 1 addition & 0 deletions checks/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/abulimov/haproxy-lint/lib"
)

// CheckUnusedBackends checks if we have declared but not used backends
func CheckUnusedBackends(sections []*lib.Section) []lib.Problem {
var problems []lib.Problem
backends := make(map[lib.Entity]bool)
Expand Down
20 changes: 18 additions & 2 deletions checks/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,34 @@ func Run(sections []*lib.Section, extrasOnly bool) []lib.Problem {
// alert message for it doesn't show the line with backend usage
{CheckUnknownBackends, true},
}

var problems []lib.Problem
// channel to get problems from check
ch := make(chan []lib.Problem)
defer close(ch)
// count how many times we call goroutines
count := 0
for _, s := range sections {
for _, r := range sectionChecks {
if !extrasOnly || r.extra {
problems = append(problems, r.f(s)...)
count++
go func(s *lib.Section, r secCheck) {
ch <- r.f(s)
}(s, r)
}
}
}
for _, r := range globalChecks {
if !extrasOnly || r.extra {
problems = append(problems, r.f(sections)...)
count++
go func(r globCheck) {
ch <- r.f(sections)
}(r)
}
}
for i := 0; i < count; i++ {
p := <-ch
problems = append(problems, p...)
}
return problems
}
32 changes: 32 additions & 0 deletions checks/checks_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package checks

import (
"testing"

"github.com/abulimov/haproxy-lint/lib"
)

func TestRun(t *testing.T) {
lines, err := lib.ReadConfigFile("../testdata/haproxy.cfg")
if err != nil {
t.Fatalf("Failed to read test data: %v", err)
}
sections := lib.GetSections(lines)
problems := Run(sections, false)

if len(problems) != 9 {
t.Errorf("Expected %d problems, got %d", 9, len(problems))
}
}

func BenchmarkRun(b *testing.B) {
lines, err := lib.ReadConfigFile("../testdata/haproxy.cfg")
if err != nil {
b.Fatalf("Failed to read test data: %v", err)
}
sections := lib.GetSections(lines)
// run the Run function b.N times
for n := 0; n < b.N; n++ {
Run(sections, false)
}
}
2 changes: 1 addition & 1 deletion haproxy-lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/abulimov/haproxy-lint/lib"
)

var version = "0.3.0"
var version = "0.4.0"

func myUsage() {
fmt.Printf("Usage: %s [OPTIONS] haproxy.cfg\n", os.Args[0])
Expand Down

0 comments on commit c2c2da1

Please sign in to comment.