From 037ff80193b45dfb86a3e2483e2c07a78ce8b7c7 Mon Sep 17 00:00:00 2001 From: Geno Date: Tue, 14 Nov 2017 19:33:28 +0100 Subject: [PATCH] [TASK] use circle ci for build artifacts + enable data race detection (#95) --- .test-coverage | 8 +++++++- .travis.yml | 2 +- README.md | 1 + circle.yml | 41 +++++++++++++++++++++++++++++++++++++ output/all/internal_test.go | 17 +++++++++++---- output/internal_test.go | 19 ++++++++++++----- 6 files changed, 77 insertions(+), 11 deletions(-) create mode 100644 circle.yml diff --git a/.test-coverage b/.test-coverage index 6293cb2..c6bd28b 100755 --- a/.test-coverage +++ b/.test-coverage @@ -1,6 +1,12 @@ #!/bin/bash # Issue: https://github.com/mattn/goveralls/issues/20 # Source: https://github.com/uber/go-torch/blob/63da5d33a225c195fea84610e2456d5f722f3963/.test-cover.sh +CI=$1 +echo "run for $CI" + +if [ "$CI" == "circle-ci" ]; then + cd ${GOPATH}/src/github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME} +fi echo "mode: count" > profile.cov FAIL=0 @@ -20,7 +26,7 @@ done # Failures have incomplete results, so don't send if [ "$FAIL" -eq 0 ]; then - goveralls -service=travis-ci -v -coverprofile=profile.cov + goveralls -service=$CI -v -coverprofile=profile.cov bash <(curl -s https://codecov.io/bash) -t $CODECOV_TOKEN -f profile.cov fi diff --git a/.travis.yml b/.travis.yml index e601586..4b8901b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,5 +7,5 @@ install: - go get github.com/mattn/goveralls - go get golang.org/x/tools/cmd/cover script: - - ./.test-coverage + - ./.test-coverage travis-ci - go install github.com/FreifunkBremen/yanic diff --git a/README.md b/README.md index faad9e7..dd1b3a6 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ Yet another node info collector ``` [![Build Status](https://travis-ci.org/FreifunkBremen/yanic.svg?branch=master)](https://travis-ci.org/FreifunkBremen/yanic) +[![CircleCI](https://circleci.com/gh/FreifunkBremen/yanic/tree/master.svg?style=shield)](https://circleci.com/gh/FreifunkBremen/yanic/tree/master) [![Coverage Status](https://coveralls.io/repos/github/FreifunkBremen/yanic/badge.svg?branch=master)](https://coveralls.io/github/FreifunkBremen/yanic?branch=master) [![codecov](https://codecov.io/gh/FreifunkBremen/yanic/branch/master/graph/badge.svg)](https://codecov.io/gh/FreifunkBremen/yanic) [![Go Report Card](https://goreportcard.com/badge/github.com/FreifunkBremen/yanic)](https://goreportcard.com/report/github.com/FreifunkBremen/yanic) diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000..8bed18b --- /dev/null +++ b/circle.yml @@ -0,0 +1,41 @@ +version: 2 +jobs: + build: + docker: + - image: circleci/golang:latest + working_directory: /go/src/github.com/FreifunkBremen/yanic + steps: + - checkout + - run: go get -t -d -v ./... + - run: go install github.com/FreifunkBremen/yanic + - store_artifacts: + path: /go/bin/ + destination: yanic + test: + docker: + - image: circleci/golang:latest + working_directory: /go/src/github.com/FreifunkBremen/yanic + steps: + - checkout + - run: go get -t -d -v ./... + - run: go get github.com/mattn/goveralls + - run: go get golang.org/x/tools/cmd/cover + - run: ./.test-coverage circle-ci + - store_test_results: + path: ./ + destination: profile.cov + test_race: + docker: + - image: circleci/golang:latest + working_directory: /go/src/github.com/FreifunkBremen/yanic + steps: + - checkout + - run: go get -t -d -v ./... + - run: go test -race ./... +workflows: + version: 2 + build_and_tests: + jobs: + - build + - test + - test_race diff --git a/output/all/internal_test.go b/output/all/internal_test.go index ad067a3..ef87ba2 100644 --- a/output/all/internal_test.go +++ b/output/all/internal_test.go @@ -2,6 +2,7 @@ package all import ( "errors" + "sync" "testing" "github.com/FreifunkBremen/yanic/output" @@ -11,11 +12,19 @@ import ( type testOutput struct { output.Output - CountSave int + countSave int + sync.Mutex } func (c *testOutput) Save(nodes *runtime.Nodes) { - c.CountSave++ + c.Lock() + c.countSave++ + c.Unlock() +} +func (c *testOutput) Get() int { + c.Lock() + defer c.Unlock() + return c.countSave } func TestStart(t *testing.T) { @@ -69,9 +78,9 @@ func TestStart(t *testing.T) { }) assert.NoError(err) - assert.Equal(0, globalOutput.CountSave) + assert.Equal(0, globalOutput.Get()) allOutput.Save(nodes) - assert.Equal(3, globalOutput.CountSave) + assert.Equal(3, globalOutput.Get()) _, err = Register(map[string]interface{}{ "e": []map[string]interface{}{ diff --git a/output/internal_test.go b/output/internal_test.go index 9d9e9d0..72c7a11 100644 --- a/output/internal_test.go +++ b/output/internal_test.go @@ -1,6 +1,7 @@ package output import ( + "sync" "testing" "time" @@ -10,11 +11,19 @@ import ( type testConn struct { Output - CountSave int + countSave int + sync.Mutex } func (c *testConn) Save(nodes *runtime.Nodes) { - c.CountSave++ + c.Lock() + c.countSave++ + c.Unlock() +} +func (c *testConn) Get() int { + c.Lock() + defer c.Unlock() + return c.countSave } func TestStart(t *testing.T) { @@ -38,12 +47,12 @@ func TestStart(t *testing.T) { Start(conn, nil, config) assert.NotNil(quit) - assert.Equal(0, conn.CountSave) + assert.Equal(0, conn.Get()) time.Sleep(time.Millisecond * 12) - assert.Equal(1, conn.CountSave) + assert.Equal(1, conn.Get()) time.Sleep(time.Millisecond * 12) Close() - assert.Equal(2, conn.CountSave) + assert.Equal(2, conn.Get()) }