如何在“Go测试”上设置超时超时标志 [英] How to set the go timeout flag on "Go test"

查看:1668
本文介绍了如何在“Go测试”上设置超时超时标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  go test -timeout 99999 

抛出这种无意义错误

 标志-test.timeout的无效值99999:
时间:持续时间内缺少单位99999

这是一个错误吗?
我使用
go版本go1.3



helpcli也没用。它表示 -test.timeout = 0:如果为正数,则为所有测试设置一个总计时间限制。但是,如果你去测试-test.timeout 99999你会得到同样的错误

  -test.timeout = 0:为所有测试设置一个合计时间限制


解决方案

time.ParseDuration 输入。例如,

  $ go test -timeout 300ms 

$ go test -timeout 99999s




Command go



测试标记

   - 超时t 
t
panic code>。



包裹标记 a>



持续时间标记接受任何有效的< time.ParseDuration



包裹时间



func ParseDuration

  func ParseDuration(s string)(持续时间,错误)

ParseDuration分析持续时间字符串。持续时间字符串是
可能带符号的十进制数字序列,每一个都带有可选的
分数和一个单位后缀,例如 300ms -1.5h 2h45m 。有效的
时间单位是 ns us (或 μs), ms s m h



go test -timeout 99999

throws this non sense error

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

Is it a bug ? I'm using go version go1.3

The "help" cli is useless too. It says -test.timeout=0: if positive, sets an aggregate time limit for all tests. However if you do go test -test.timeout 99999 you get the same error

 -test.timeout=0: if positive, sets an aggregate time limit for all tests

解决方案

Use a valid time.ParseDuration input. For example,

$ go test -timeout 300ms

$ go test -timeout 99999s

Command go

Testing flags

-timeout t

If a test runs longer than t, panic.

Package flag

Duration flags accept any input valid for time.ParseDuration.

Package time

func ParseDuration

func ParseDuration(s string) (Duration, error)

ParseDuration parses a duration string. A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".

这篇关于如何在“Go测试”上设置超时超时标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆