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

flag provided but not defined: -test.timeout (Go 1.13) #602

Closed
dfreilich opened this issue Sep 6, 2019 · 18 comments
Closed

flag provided but not defined: -test.timeout (Go 1.13) #602

dfreilich opened this issue Sep 6, 2019 · 18 comments
Labels

Comments

@dfreilich
Copy link

When trying to run the apt-buildpack integration tests on a computer running Go 1.13, we were unable to and got the following error:


	 -------------------------------------------------------------------
	|                                                                   |
	|  Ginkgo timed out waiting for all parallel nodes to report back!  |
	|                                                                   |
	 -------------------------------------------------------------------

 integration timed out. path: .
[1] flag provided but not defined: -test.timeout
[1] Usage of /tmp/ginkgo538951234/integration.test:
...

Our integration test script:

#!/usr/bin/env bash
set -euo pipefail

cd "$( dirname "${BASH_SOURCE[0]}" )/.."
source .envrc
./scripts/install_tools.sh

GINKGO_NODES=${GINKGO_NODES:-3}
GINKGO_ATTEMPTS=${GINKGO_ATTEMPTS:-2}
export CF_STACK=${CF_STACK:-cflinuxfs3}

UNCACHED_BUILDPACK_FILE=${UNCACHED_BUILDPACK_FILE:-""}

cd src/*/integration

echo "Run Uncached Buildpack"
BUILDPACK_FILE="$UNCACHED_BUILDPACK_FILE" \
  ginkgo -r -mod vendor --flakeAttempts=$GINKGO_ATTEMPTS -nodes $GINKGO_NODES --slowSpecThreshold=60 -- --cached=false

Env:

root@b349d15677b6:/app# go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/app/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build280745408=/tmp/go-build -gno-record-gcc-switches"
@dfreilich
Copy link
Author

Suspect this is the cause https://golang.org/doc/go1.13#testing

Testing flags are now registered in the new Init function, which is invoked by the generated main function for the test. As a result, testing flags are now only registered when running a test binary, and packages that call flag.Parse during package initialization may cause tests to fail.

@lempiy
Copy link

lempiy commented Sep 11, 2019

Getting the same issue after upgrade to Go 1.13:

./bin/ginkgo -cover -r ne -- -c /builds/cns/go-app/conf/main.conf -override /builds/cns/go-app//conf/main.override.conf.tpl -override-type template -env test
flag provided but not defined: -test.timeout

@blgm blgm added the bug label Sep 12, 2019
@Winterhart
Copy link

Winterhart commented Sep 26, 2019

I am having the same bug right now with a Darwin amd64 architecture

@mszostok
Copy link

mszostok commented Nov 7, 2019

any update? are you planning to fix that?

@zhubuntu
Copy link

zhubuntu commented Nov 19, 2019

I think this is the test case problem, not the ginkgoproblem. As kubernetes/kubernetes#82742

@lempiy
Copy link

lempiy commented Nov 19, 2019

In some cases explicit call for testing.Init() before init() functions in suites may help:

var _ = func() bool {
 	testing.Init()
	return true
}()

func TestApp(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "App / Suite")
}

@ansd
Copy link
Collaborator

ansd commented Nov 21, 2019

As @dfreilich correctly pointed out, the flag provided but not defined error occurs because of https://golang.org/doc/go1.13#testing:

packages that call flag.Parse during package initialization may cause tests to fail

It occurs when flag.Parse is called within the init function.
The solution is to move flag.Parse from the init function to somewhere else (e.g. to main or BeforeSuite)
For the example above this line must be moved.

An example how to reproduce this error without using ginkgo can be found here.
(I can reproduce it with the latest go version go1.13.4 darwin/amd64.)

I agree with @zhubuntu that this is not a Ginkgo issue.
I therefore suggest to close this issue.

@blgm
Copy link
Collaborator

blgm commented Nov 27, 2019

Looks like it’s a breaking change in Go 1.13. The solution is for users not to call flag.Parse() in an init() function. Please let us know if that does not work for you.

@blgm blgm closed this as completed Nov 27, 2019
@antoineco
Copy link

antoineco commented Nov 28, 2019

I can confirm that replacing

func init() {
	flag.Parse()
}

TestXYZ(t *testing.T) {}

with

func TestMain(m *testing.M) {
	flag.Parse()
	os.Exit(m.Run())
}

TestXYZ(t *testing.T) {}

solves the issue.

@puppet-py
Copy link

I am hitting this error flag provided but not defined: -test.timeout without having to use the flag.Parse anywhere in my codebase. Nor there is any init func
My env:

$ go version
go version go1.13.3 darwin/amd64
$ ginkgo version
Ginkgo Version 1.12.3

@blgm
Copy link
Collaborator

blgm commented Jun 17, 2020

@puppet-py, could you share a little more context about what triggered this. Have you just upgraded something? Have you added some more code? How long is it since things worked without getting this error? Is there an easy way to reproduce it that you can share?

test.timeout is in the Ginkgo codebase, so we should absolutely be suspicious of Ginkgo. The challenge is to work out why you are seeing it, but most other users are not.

@puppet-py
Copy link

@blgm You can refer the last comment here #693 (comment) wrt my findings. @onsi was earlier responding to that issue which I have opened

@zemul
Copy link

zemul commented Aug 20, 2020

before flag.Parse() add testing.Init()

@blgm
Copy link
Collaborator

blgm commented Aug 20, 2020

Hi @zemul. Could you say a bit more about the issue that you're having?

@patelpayal
Copy link

patelpayal commented Sep 2, 2020

I am running into the same issue. I am using go 1.13 for the build environment.

I added test.Init() before flag.Parse() but still running into the same issue. flag provided but not defined: -timeout

I am using go test .. command to run ginkgo tests here.

Any suggestions?

@blgm
Copy link
Collaborator

blgm commented Sep 3, 2020

@patelpayal, there is a suggested approach here: #602 (comment)

@ltx0621
Copy link

ltx0621 commented May 10, 2021

I've encountered this error log while using branch v2:
flag provided but not defined: -ginkgo.timeout

steps:

  1. git clone and checkout branch v2 ,go build
  2. run the cli command , ./ginkgo , no option.

go version go version go1.16.3 darwin/amd64

ps: the case run perfectly with master branch

@onsi
Copy link
Owner

onsi commented May 10, 2021

hey thanks for giving V2 a try. can you confirm that you recompiled the ginkgo binary (eg run ginkgo version). I suspect you're using an older version of the cli.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests