Fix #240: Add test flags. Remove build tags for logging control.

License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
This commit is contained in:
Hector Sanjuan 2018-01-15 10:49:07 +01:00
parent 2a6f91cd35
commit bfdd59735c
9 changed files with 34 additions and 45 deletions

View File

@ -68,13 +68,13 @@ check:
golint -set_exit_status -min_confidence 0.3 ./...
test: deps
go test -timeout 20m -tags silent -v ./...
go test -timeout 20m -loglevel "CRITICAL" -v ./...
test_sharness: $(sharness)
@sh sharness/run-sharness-tests.sh
test_problem: deps
go test -timeout 20m -tags debug -v -run $(problematic_test)
go test -timeout 20m -loglevel "DEBUG" -v -run $(problematic_test)
$(sharness):
@echo "Downloading sharness"

2
ci/Jenkinsfile vendored
View File

@ -1 +1 @@
golang([test: "go test -tags silent -v ./..."])
golang([test: "go test -loglevel CRITICAL -v ./..."])

View File

@ -7,7 +7,15 @@ for dir in $dirs;
do
if ls "$dir"/*.go &> /dev/null;
then
go test -timeout 20m -v -coverprofile=profile.out -covermode=count -tags silent "$dir"
if [ "$dir" == "." ]; then
set -x
go test -timeout 20m -v -coverprofile=profile.out -covermode=count "$dir" -loglevel "CRITICAL"
set +x
else
set -x
go test -timeout 20m -v -coverprofile=profile.out -covermode=count "$dir"
set +x
fi
if [ $? -ne 0 ];
then
exit 1

View File

@ -1,12 +0,0 @@
// +build debug,!silent
package ipfscluster
func init() {
l := "DEBUG"
SetFacilityLogLevel("*", l)
// for f, _ := range LoggingFacilities {
// SetFacilityLogLevel(f, l)
// }
}

View File

@ -504,6 +504,10 @@ func setupLogLevel(lvl string) {
}
}
func setupDebug() {
ipfscluster.SetFacilityLogLevel("*", "DEBUG")
}
func setupAllocation(name string, diskInfCfg *disk.Config, numpinInfCfg *numpin.Config) (ipfscluster.Informer, ipfscluster.PinAllocator) {
switch name {
case "disk", "disk-freespace":
@ -525,10 +529,6 @@ func setupAllocation(name string, diskInfCfg *disk.Config, numpinInfCfg *numpin.
}
}
func setupDebug() {
ipfscluster.SetFacilityLogLevel("*", "DEBUG")
}
func saveConfig(cfg *config.Manager, force bool) {
if _, err := os.Stat(configPath); err == nil && !force {
err := fmt.Errorf("%s exists. Try running: %s -f init", configPath, programName)

View File

@ -32,10 +32,12 @@ import (
//TestClusters*
var (
// number of clusters to create
nClusters = *flag.Int("nclusters", 6, "number of clusters to use")
nClusters = 6
// number of pins to pin/unpin/check
nPins = *flag.Int("npins", 500, "number of pins to pin/unpin/check")
nPins = 500
logLevel = "CRITICAL"
// ports
clusterPort = 10000
@ -44,7 +46,20 @@ var (
)
func init() {
flag.StringVar(&logLevel, "loglevel", logLevel, "default log level for tests")
flag.IntVar(&nClusters, "nclusters", nClusters, "number of clusters to use")
flag.IntVar(&nPins, "npins", nPins, "number of pins to pin/unpin/check")
flag.Parse()
rand.Seed(time.Now().UnixNano())
for f := range LoggingFacilities {
SetFacilityLogLevel(f, logLevel)
}
for f := range LoggingFacilitiesExtra {
SetFacilityLogLevel(f, logLevel)
}
}
func checkErr(t *testing.T, err error) {

View File

@ -22,7 +22,7 @@ var LoggingFacilities = map[string]string{
// LoggingFacilitiesExtra provides logging identifiers
// used in ipfs-cluster dependencies, which may be useful
// for to display. Along with their default value.
// to display. Along with their default value.
var LoggingFacilitiesExtra = map[string]string{
"p2p-gorpc": "CRITICAL",
"swarm2": "ERROR",

View File

@ -1,14 +0,0 @@
// +build !debug,!silent
package ipfscluster
// These are our default log levels
func init() {
for f, l := range LoggingFacilities {
SetFacilityLogLevel(f, l)
}
for f, l := range LoggingFacilitiesExtra {
SetFacilityLogLevel(f, l)
}
}

View File

@ -1,8 +0,0 @@
// +build !debug,silent
package ipfscluster
func init() {
l := "CRITICAL"
SetFacilityLogLevel("*", l)
}