Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: how to disable (run test) Cached #24573

Closed
imkos opened this issue Mar 28, 2018 · 17 comments
Closed

cmd/go: how to disable (run test) Cached #24573

imkos opened this issue Mar 28, 2018 · 17 comments

Comments

@imkos
Copy link

imkos commented Mar 28, 2018

What version of Go are you using (go version)?

1.10 (win10_x64)

go test, The results always appear cached.
I made an HTTP request, the result of the server return was changed, but the test results were old.
However, run test (cached) does not make HTTP requests
Unless, I modified the code in func Test_** (), the result is the latest

func Test_gotest_cached(t *testing.T) {
	req := NewRequest()
	resp, b_resp, e1 := req.Get("http://10.20.60.52:8080/help")
	if e1 != nil {
		t.Error(e1)
		return
	}
	fmt.Println(string(b_resp), resp.Status)
}

server code:

http.HandleFunc("/help", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("hello!"))
	})

go test -v -timeout 30s newpay_svc -run ^Test_gotest_cached$

"hello!" => "hello world!" , but the test results were old.

@myitcv
Copy link
Member

myitcv commented Mar 28, 2018

The Go project does not use its bug tracker for general discussion or asking questions about the language. The Github bug tracker is only used for tracking bugs and proposals going through the Proposal Process.

Please see the Questions wiki page; it has a list of good places for asking questions.

But as a quick pointer, the Go 1.10 release notes discuss how to disable test caching (and indeed when caching kicks in in the first place):

https://golang.org/doc/go1.10#test

@imkos
Copy link
Author

imkos commented Mar 28, 2018

Thanks for the reply, I found the reason and the solution.

@imkos imkos closed this as completed Mar 28, 2018
@ALTree ALTree changed the title How to disable (run test) Cached. cmd/go: how to disable (run test) Cached Mar 29, 2018
@zyfdegh
Copy link

zyfdegh commented Jun 1, 2018

On go1.10

GOCACHE=off go test

@davecheney
Copy link
Contributor

davecheney commented Jun 1, 2018 via email

@franciscocpg
Copy link

Using go1.11 GOCACHE=off breaks go mod.

So I am using go test -count=1.

@zignd
Copy link

zignd commented Nov 22, 2018

The idiomatic way to bypass test caching is to use -count=1.

https://golang.org/doc/go1.10#test

Is there any documentation on the -count flag? I'd like to understand its purpose.

@myitcv
Copy link
Member

myitcv commented Nov 22, 2018

Is there any documentation on the -count flag? I'd like to understand its purpose.

https://golang.org/cmd/go/#hdr-Testing_flags

or

go help testflag

@lengocgiang
Copy link

In vscode
"go.testFlags": ["-count=1"]

Helcaraxan added a commit to Helcaraxan/go-flagz that referenced this issue Mar 22, 2019
Paths names starting with '..' are triggering errors when using Go
modules in Go >= 1.11 (1). To work around this we move the testdata
into an archive which is unzipped as part of the test.

(1) See: golang/go#24573
pohly added a commit to pohly/csi-test that referenced this issue Apr 15, 2019
GOCACHE=off is too strong (prevents reusing binaries) and is going to
break when updating to Go 1.12.x. Better use the `-count=1` trick to
force a re-run of the
tests (golang/go#24573 (comment)).
suneeth51 pushed a commit to suneeth51/csi-test that referenced this issue Sep 11, 2019
GOCACHE=off is too strong (prevents reusing binaries) and is going to
break when updating to Go 1.12.x. Better use the `-count=1` trick to
force a re-run of the
tests (golang/go#24573 (comment)).
@tj
Copy link

tj commented Nov 26, 2019

Can't say -count is very intuitive. I keep hitting scenarios where test caching is not invalidating correctly, but I haven't pinned down any specific pattern yet. go help test vs go help testflag is a bit awkward as well IMO.

@pedromss
Copy link

pedromss commented Jan 9, 2020

Just arrived at this thread. Is a -no-cache something that could be considered for future versions?
Or maybe print ... (cached, run with -count=1)?

Something that wouldn't force people to google "go test no cache"

@EnchanterIO
Copy link

+1 @pedromss Just landed here after I was intuitively trying go test -no-cache.

Helcaraxan added a commit to Helcaraxan/go-flagz that referenced this issue May 1, 2020
Paths names starting with '..' are triggering errors when using Go
modules in Go >= 1.11 (1). To work around this we move the testdata
into an archive which is unzipped as part of the test.

(1) See: golang/go#24573
Helcaraxan added a commit to Helcaraxan/go-flagz that referenced this issue May 1, 2020
Paths names starting with '..' are triggering errors when using Go
modules in Go >= 1.11 (1). To work around this we move the testdata
into an archive which is unzipped as part of the test.

(1) See: golang/go#24573
@ghostsquad
Copy link

any chance this can be reopened?

@ghostsquad
Copy link

@EnchanterIO @pedromss @tj @myitcv @lengocgiang @franciscocpg @davecheney @imkos please upvote the above issue

@cristaloleg
Copy link

@ghostsquad be patient, please. There is no need to mention everyone.

@ghostsquad
Copy link

my apologies

@arvenil
Copy link

arvenil commented Jun 12, 2020

I think the best would be if we could do something like t.NoCache() to mark specific tests. Otherwise everyone will just disable cache altogether with -count=1. I run into this problem when I simply changed sql fixture file, so I would like that specific test to run without caching but I would like to cache others.

@ORESoftware

This comment has been minimized.

@golang golang locked as resolved and limited conversation to collaborators Jun 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests