Skip to content

Commit

Permalink
Merge pull request #20 from infrawatch/ci/golangci-lint
Browse files Browse the repository at this point in the history
Add golangci-lint action to CI
  • Loading branch information
leifmadsen authored Dec 3, 2020
2 parents c6ef123 + 6ee6dd5 commit ec31fcb
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 19 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ env:
on: push

jobs:
golangci:
name: Linting
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.33

test-framework:
name: Base testing
runs-on: ubuntu-20.04
Expand Down
4 changes: 1 addition & 3 deletions build/test-framework/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ go get -u honnef.co/go/tools/cmd/staticcheck

# run code validation tools
echo " *** Running pre-commit code validation"
echo " --- [TODO] Tests expected to fail currently. Changes required to pass all testing. Disable for now."
./build/test-framework/pre-commit

# run unit tests
echo " *** Running test suite"
echo " --- [TODO] Re-enable the test suite once supporting changes result in tests to pass."
#go test -v ./...
go test -v ./...

set +e
echo " *** Running code coverage tooling"
Expand Down
24 changes: 10 additions & 14 deletions pkg/cacheutil/cacheserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cacheutil

import (
"context"
"fmt"
"strconv"
"testing"
"time"
Expand Down Expand Up @@ -46,12 +45,12 @@ func (ms *MetricStash) addMetric(metricName string, interval float64, numLabels
labelName := "test-label-" + strconv.Itoa(i)

ls.deleteFn = func() {
fmt.Printf("Label %s in metric %s deleted\n", labelName, metricName)
//fmt.Printf("Label %s in metric %s deleted\n", labelName, metricName)
delete(ms.metrics[metricName], labelName)

if len(ms.metrics[metricName]) == 0 {
delete(ms.metrics, metricName)
fmt.Printf("Metrics %s deleted\n", metricName)
//fmt.Printf("Metrics %s deleted\n", metricName)
}
}

Expand All @@ -68,17 +67,18 @@ func TestCacheExpiry(t *testing.T) {
ms := NewMetricStash()

cs := NewCacheServer()
cs.Interval = 1
ctx := context.Background()

go cs.Run(ctx)
go func() {
err := cs.Run(ctx)
assert.Ok(t, err)
}()

t.Run("single entry", func(t *testing.T) {
ms.addMetric("test-metric", 1, 1, cs)
assert.Equals(t, 1, len(ms.metrics))
for i := 0; i < 2; i++ {
time.Sleep(time.Second * 1)
}

time.Sleep(time.Millisecond * 1200)
assert.Equals(t, 0, len(ms.metrics))
})

Expand All @@ -87,19 +87,15 @@ func TestCacheExpiry(t *testing.T) {
ms.addMetric("test-metric-2", 2, 1, cs)

assert.Equals(t, 2, len(ms.metrics))
for i := 0; i < 4; i++ {
time.Sleep(time.Second * 1)
}
time.Sleep(time.Millisecond * 3000)
assert.Equals(t, 0, len(ms.metrics))
})

t.Run("multilabel metric", func(t *testing.T) {
ms.addMetric("test-metric-1", 1, 10, cs)

assert.Equals(t, 10, len(ms.metrics["test-metric-1"]))
for i := 0; i < 2; i++ {
time.Sleep(time.Second * 1)
}
time.Sleep(time.Millisecond * 2000)
assert.Equals(t, 0, len(ms.metrics))
})
}
6 changes: 5 additions & 1 deletion pkg/unixserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,11 @@ func Listen(ctx context.Context, address string, w *bufio.Writer, registry *prom

// cache server
cache := cacheutil.NewCacheServer()
go cache.Run(ctx)

// TODO: check for error returns properly
go func() {
_ = cache.Run(ctx)
}()

go func() {
cd := new(collectd.Collectd)
Expand Down
5 changes: 4 additions & 1 deletion pkg/unixserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ func TestCDMetrics(t *testing.T) {
cs.Interval = 1
ctx := context.Background()

go cs.Run(ctx)
go func() {
err := cs.Run(ctx)
assert.Ok(t, err)
}()

cdmetrics.updateOrAddMetrics(cd, cs, 1.0)
assert.Equals(t, 1, len(cdmetrics.metrics))
Expand Down

0 comments on commit ec31fcb

Please sign in to comment.