go test -timeout 30m can this be set inside Go code? disable timeouts programmatically?

3,263 views
Skip to first unread message

Jason E. Aten

unread,
Jan 20, 2020, 8:03:36 PM1/20/20
to golang-nuts
I have a long running test where I would like to set the testing package timeout to 30 minutes from with the my_test.go code.

This would prevent me from forgetting to add the timeout flag, and then discovering 10 minutes later that it was needed.

Is this possible? Or just a way to disable the timeouts all together from Go _test.go code.

Mike P

unread,
Aug 21, 2020, 12:27:21 PM8/21/20
to golang-nuts
I was able to accomplish this via the flag library in my testing function:
flag.Set("test.timeout", "30m0s")

I found that being read from here:

So then I just changed the Lookup() function to the Set() function. Here's my working example when using go test to execute some terragrunt / terraform tests:
func TestBasicRun(t *testing.T) {
        flag.Set("test.timeout", "30m0s")
        fmt.Println("timeout: " + flag.Lookup("test.timeout").Value.String())

        terraformOptions := &terraform.Options{
                TerraformBinary: "terragrunt",
                TerraformDir:    "./basic-run",
                Lock:            true,
        }

        defer terraform.Destroy(t, terraformOptions)

        terraform.InitAndApplyAndIdempotent(t, terraformOptions)
}

I think you can disable it by setting it to something like: 

"0m0s"

Mike P

unread,
Aug 21, 2020, 1:16:04 PM8/21/20
to golang-nuts
Actually, that doesn't work. My apologies. If I figure it out, I will reply.

--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/so01nDZLnIQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/5a36865f-436b-4fab-8d44-64795e77a5bcn%40googlegroups.com.


--
____________________
Mike Pescetto
Senior Site Reliability Engineer
Reply all
Reply to author
Forward
0 new messages