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

Ginkgo "corrupts" some global state when testing "package main" #305

Closed
nikhilm opened this issue Oct 12, 2016 · 5 comments
Closed

Ginkgo "corrupts" some global state when testing "package main" #305

nikhilm opened this issue Oct 12, 2016 · 5 comments

Comments

@nikhilm
Copy link

nikhilm commented Oct 12, 2016

I have a project that has certain functions in package main that I want to test. The tests are located in another directory. I am aware that this is bad style, and I should move the exported functions to another package and so on... but the fact is, it is something that works, until running ginkgo makes it not work.

I have a reduced test case at https://github.com/nikhilm/ginkgo-broken that intentionally does not use any gomega specifics, to demonstrate the problem is in the ginkgo executable. Reproducing the README here.

Reproduced on

go version go1.7.1 darwin/amd64
Darwin Nikhils-MBP 15.5.0 Darwin Kernel Version 15.5.0: Tue Apr 19 18:36:36 PDT 2016; root:xnu-3248.50.21~8/RELEASE_X86_64 x86_64
Ginkgo Version 1.2.0

Environment:

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/nikhil/iron/gocode"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/3t/tx0j5bws5kv7m6s2rj2dtyvm0000gn/T/go-build959139225=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"

What is the problem?

When a package main exports some fields/functions that the test package
imports to test, ginkgo works fine on the first run, but fails on subsequent
runs. No global state seems to be modified, nor are new files created, so
I cannot figure out what is the cause. After the command is run, go test
starts failing too.

Steps to Reproduce

go get github.com/nikhilm/ginkgo-broken
cd $GOPATH/src/github.com/nikhilm/ginkgo-broken
cd tests
go test -v . # everything works!
go test -v . # everything works!

These commands output:

=== RUN   TestYo
YOYOYO
--- PASS: TestYo (0.00s)
PASS
ok      github.com/nikhilm/ginkgo-broken/tests  0.006s

Let's continue:

ginkgo -v . # everything works!

This works too:

=== RUN   TestYo
YOYOYO
--- PASS: TestYo (0.00s)
PASS

Ginkgo ran 1 suite in 593.024519ms
Test Suite Passed

But it has broken something, because from this point on:

go test -v . 

leads to:

# github.com/nikhilm/ginkgo-broken/tests_test
./project_test.go:6: can't find import:
"github.com/nikhilm/ginkgo-broken/project"
FAIL    github.com/nikhilm/ginkgo-broken/tests [build failed]

Expected output: tests should always pass

Once the ginkgo command is run, this directory is broken "forever". I have not
yet been able to isolate what leads to the go runtime considering it "fixed".

Things I've found that work as a "fix":

  • Touching project/main.go.
  • Cloning repo again.

Things I've found that do not work as a "fix":

  • Starting a new shell.
  • Touching test/project_test.go
@onsi
Copy link
Owner

onsi commented Oct 15, 2016

Fastinating... I'll try to take a look soon.

@onsi
Copy link
Owner

onsi commented Oct 16, 2016

ginkgo calls into go test -i -c -o=... to produce a compiled artifact. It looks like go test -i is to blame.

If you clone your repo and run:

go test -i

then all subsequent invocations of go test fail until you touch project/main.go

Weird. I recommend opening an issue on go itself

For now, I'm removing the -i flag. It's not necessary and may have evolved over the years...

@nikhilm
Copy link
Author

nikhilm commented Oct 17, 2016

Thank you @onsi

On Sun, Oct 16, 2016 at 1:59 PM, Onsi Fakhouri [email protected]
wrote:

Closed #305 #305 via afe049e
afe049e
.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#305 (comment), or mute the
thread
https://github.com/notifications/unsubscribe-auth/AAEzWrj1zhx4sIuw0ju-nLA1XwN4x4IEks5q0pAXgaJpZM4KVNKv
.

Nikhil

onsi added a commit that referenced this issue Oct 23, 2016
@onsi
Copy link
Owner

onsi commented Oct 23, 2016

hey @nikhilm bad news. removing -i has slowed people's test suites significantly. I've reverted this bug. Please open an issue at golang/go to see if the go community can fix the behavior of -i

@nikhilm
Copy link
Author

nikhilm commented Oct 24, 2016

Thanks @onsi. Related, the Golang bug is also going to change this behavior in go 1.8 to not allow such imports. We will change our tests.

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

No branches or pull requests

2 participants