Skip to content

Commit

Permalink
Unset $GOMAXPROCS during tests (#4)
Browse files Browse the repository at this point in the history
In order to test the `maxprocs` package, we need to control the value of
`$GOMAXPROCS`. Unfortunately, Travis sets `$GOMAXPROCS` in every
container.

To work around this, use `TestMain` to unset `$GOMAXPROCS` for the
`maxprocs` package tests.
  • Loading branch information
akshayjshah authored Aug 9, 2017
1 parent c6d5fbe commit 0dd381f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies:
glide install
ifdef SHOULD_LINT
@echo "Installing golint..."
go install ./vendor/github.com/golang/lint/golint
go get -u github.com/golang/lint/golint
else
@echo "Not installing golint, since we don't expect to lint on" $(GO_VERSION)
endif
Expand Down
9 changes: 3 additions & 6 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion glide.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package: go.uber.org/automaxprocs
import: []
testImport:
- package: github.com/golang/lint/golint
- package: github.com/stretchr/testify
version: ^1.1.4
subpackages:
Expand Down
8 changes: 8 additions & 0 deletions maxprocs/maxprocs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"bytes"
"errors"
"fmt"
"log"
"os"
"strconv"
"testing"
Expand Down Expand Up @@ -141,3 +142,10 @@ func TestSet(t *testing.T) {
assert.Equal(t, 42, currentMaxProcs(), "should change GOMAXPROCS to match quota")
})
}

func TestMain(m *testing.M) {
if err := os.Unsetenv(_maxProcsKey); err != nil {
log.Fatalf("Couldn't clear %s: %v\n", _maxProcsKey, err)
}
os.Exit(m.Run())
}

0 comments on commit 0dd381f

Please sign in to comment.