Rename deadline option to timeout and mark deadline as deprecated. (#793)

This commit is contained in:
Denis Titusov 2019-10-08 09:37:54 +03:00 committed by Isaev Denis
parent ee2e17f7e9
commit 0cc87df732
7 changed files with 26 additions and 12 deletions

View File

@ -7,7 +7,7 @@ run:
concurrency: 4
# timeout for analysis, e.g. 30s, 5m, default is 1m
deadline: 1m
timeout: 1m
# exit code when at least one issue was found, default is 1
issues-exit-code: 1

View File

@ -37,7 +37,7 @@ test: build
test_race:
go build -race -o golangci-lint ./cmd/golangci-lint
GL_TEST_RUN=1 ./golangci-lint run -v --deadline=5m
GL_TEST_RUN=1 ./golangci-lint run -v --timeout=5m
.PHONY: test_race
test_linters:

View File

@ -337,7 +337,7 @@ We measure peak memory usage (RSS) by tracking of processes RSS every 5 ms.
We compare golangci-lint and gometalinter in default mode, but explicitly enable all linters because of small differences in the default configuration.
```bash
$ golangci-lint run --no-config --issues-exit-code=0 --deadline=30m \
$ golangci-lint run --no-config --issues-exit-code=0 --timeout=30m \
--disable-all --enable=deadcode --enable=gocyclo --enable=golint --enable=varcheck \
--enable=structcheck --enable=maligned --enable=errcheck --enable=dupl --enable=ineffassign \
--enable=interfacer --enable=unconvert --enable=goconst --enable=gosec --enable=megacheck
@ -498,7 +498,7 @@ Flags:
--print-linter-name Print linter name in issue line (default true)
--issues-exit-code int Exit code when issues were found (default 1)
--build-tags strings Build tags
--deadline duration Deadline for total work (default 1m0s)
--timeout duration Timeout for total work (default 1m0s)
--tests Analyze tests (*_test.go) (default true)
--print-resources-usage Print avg and max memory usage of golangci-lint and total time
-c, --config PATH Read config from file path PATH
@ -600,7 +600,7 @@ run:
concurrency: 4
# timeout for analysis, e.g. 30s, 5m, default is 1m
deadline: 1m
timeout: 1m
# exit code when at least one issue was found, default is 1
issues-exit-code: 1

View File

@ -299,7 +299,7 @@ We measure peak memory usage (RSS) by tracking of processes RSS every 5 ms.
We compare golangci-lint and gometalinter in default mode, but explicitly enable all linters because of small differences in the default configuration.
```bash
$ golangci-lint run --no-config --issues-exit-code=0 --deadline=30m \
$ golangci-lint run --no-config --issues-exit-code=0 --timeout=30m \
--disable-all --enable=deadcode --enable=gocyclo --enable=golint --enable=varcheck \
--enable=structcheck --enable=maligned --enable=errcheck --enable=dupl --enable=ineffassign \
--enable=interfacer --enable=unconvert --enable=goconst --enable=gosec --enable=megacheck

View File

@ -85,7 +85,10 @@ func initFlagSet(fs *pflag.FlagSet, cfg *config.Config, m *lintersdb.Manager, is
fs.IntVar(&rc.ExitCodeIfIssuesFound, "issues-exit-code",
exitcodes.IssuesFound, wh("Exit code when issues were found"))
fs.StringSliceVar(&rc.BuildTags, "build-tags", nil, wh("Build tags"))
fs.DurationVar(&rc.Deadline, "deadline", time.Minute, wh("Deadline for total work"))
fs.DurationVar(&rc.Timeout, "deadline", time.Minute, wh("Deadline for total work"))
hideFlag("deadline")
fs.DurationVar(&rc.Timeout, "timeout", time.Minute, wh("Timeout for total work"))
fs.BoolVar(&rc.AnalyzeTests, "tests", true, wh("Analyze tests (*_test.go)"))
fs.BoolVar(&rc.PrintResourcesUsage, "print-resources-usage", false,
wh("Print avg and max memory usage of golangci-lint and total time"))
@ -387,7 +390,7 @@ func (e *Executor) executeRun(_ *cobra.Command, args []string) {
}
}()
ctx, cancel := context.WithTimeout(context.Background(), e.cfg.Run.Deadline)
ctx, cancel := context.WithTimeout(context.Background(), e.cfg.Run.Timeout)
defer cancel()
if needTrackResources {
@ -411,7 +414,7 @@ func (e *Executor) executeRun(_ *cobra.Command, args []string) {
func (e *Executor) setupExitCode(ctx context.Context) {
if ctx.Err() != nil {
e.exitCode = exitcodes.Timeout
e.log.Errorf("Deadline exceeded: try increase it by passing --deadline option")
e.log.Errorf("Timeout exceeded: try increase it by passing --timeout option")
return
}

View File

@ -116,9 +116,13 @@ type Run struct {
ExitCodeIfIssuesFound int `mapstructure:"issues-exit-code"`
AnalyzeTests bool `mapstructure:"tests"`
Deadline time.Duration
PrintVersion bool
// Deprecated: Deadline exists for historical compatibility
// and should not be used. To set run timeout use Timeout instead.
Deadline time.Duration
Timeout time.Duration
PrintVersion bool
SkipFiles []string `mapstructure:"skip-files"`
SkipDirs []string `mapstructure:"skip-dirs"`
UseDefaultSkipDirs bool `mapstructure:"skip-dirs-use-default"`

View File

@ -44,7 +44,14 @@ func TestSymlinkLoop(t *testing.T) {
func TestDeadline(t *testing.T) {
testshared.NewLintRunner(t).Run("--deadline=1ms", getProjectRoot()).
ExpectExitCode(exitcodes.Timeout).
ExpectOutputContains(`Deadline exceeded: try increase it by passing --deadline option`)
ExpectOutputContains(`Timeout exceeded: try increase it by passing --timeout option`).
ExpectOutputContains(`Flag --deadline has been deprecated, flag will be removed soon, please, use .golangci.yml config`)
}
func TestTimeout(t *testing.T) {
testshared.NewLintRunner(t).Run("--timeout=1ms", getProjectRoot()).
ExpectExitCode(exitcodes.Timeout).
ExpectOutputContains(`Timeout exceeded: try increase it by passing --timeout option`)
}
func TestTestsAreLintedByDefault(t *testing.T) {