Home > Backend Development > Golang > How to Correctly Set Timeout Duration in Go Test?

How to Correctly Set Timeout Duration in Go Test?

Patricia Arquette
Release: 2024-12-07 04:12:11
Original
388 people have browsed it

How to Correctly Set Timeout Duration in Go Test?

Timeout Duration Setting in Go Test

In a typical Go test workflow, users may encounter an error when setting the timeout flag using a simple numeric value:

go test -timeout 99999
Copy after login

This command will result in the following error:

invalid value "99999" for flag -test.timeout: time: missing unit in duration 99999
Copy after login

Solution: Using Valid Duration Format

To rectify this issue, users should utilize a valid time format as specified by time.ParseDuration. Valid formats include:

  • "h" or "H" for hours
  • "m" or "M" for minutes
  • "s" or "S" for seconds
  • "ms" or "µs" for milliseconds

Examples:

$ go test -timeout 300ms

$ go test -timeout 99999s
Copy after login

Reference:

  • [Package flag: Duration Flags](https://golang.org/pkg/flag/#hdr-Duration_Flags)
  • [Package time: ParseDuration](https://golang.org/pkg/time/#ParseDuration)

The above is the detailed content of How to Correctly Set Timeout Duration in Go Test?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template