Home >Backend Development >Golang >How Do I Correctly Set the Timeout Flag for `go test`?

How Do I Correctly Set the Timeout Flag for `go test`?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-12-07 00:59:11440browse

How Do I Correctly Set the Timeout Flag for `go test`?

Setting the Go Test Timeout Flag

Using the command go test -timeout 99999, as you've mentioned, generates an error indicating an invalid value. This is because the specified duration lacks a proper unit designation.

The -timeout flag in go test provides an aggregate time limit for all tests. To set it effectively, you must specify a valid time duration using the time.ParseDuration syntax.

For instance, if you wish to set a timeout of 300 milliseconds, use:

$ go test -timeout 300ms

Similarly, to set a timeout of 99999 seconds:

$ go test -timeout 99999s

Refer to the documentation for time.ParseDuration for further details on specifying duration strings.

The above is the detailed content of How Do I Correctly Set the Timeout Flag for `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