Home >Backend Development >Golang >How Do I Correctly Use the `-timeout` Flag in `go test`?

How Do I Correctly Use the `-timeout` Flag in `go test`?

DDD
DDDOriginal
2024-12-05 08:49:13188browse

How Do I Correctly Use the `-timeout` Flag in `go test`?

Timeout Flags Usage in "Go Test"

When utilizing the "go test" command with the "-timeout" flag, you may encounter an error if the provided duration string is invalid. To address this issue, ensure that the input matches the expected format specified by time.ParseDuration.

Normally, a valid duration string should consist of a combination of digits, optionally including a sign, followed by a decimal point (if necessary) and then the appropriate time unit. Examples of valid time unit suffixes are "s" (seconds), "ms" (milliseconds), and "h" (hours).

For instance, the following command will properly set a timeout of 300 milliseconds:

$ go test -timeout 300ms

Alternatively, you can specify larger durations like 99999 seconds using the "s" unit:

$ go test -timeout 99999s

Refer to the official documentation for further details on the supported duration string syntax:

  • Package flag: [Duration flags](https://pkg.go.dev/flag#hdr-Duration_Flags)
  • Package time: [ParseDuration](https://pkg.go.dev/time#ParseDuration)

The above is the detailed content of How Do I Correctly Use the `-timeout` Flag in `go test`?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn