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

Test corruption with global variables #42073

Closed
abergmeier opened this issue Oct 19, 2020 · 3 comments
Closed

Test corruption with global variables #42073

abergmeier opened this issue Oct 19, 2020 · 3 comments

Comments

@abergmeier
Copy link

@abergmeier abergmeier commented Oct 19, 2020

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

$ go version
go version go1.15.2 linux/amd64

Does this issue reproduce with the latest release?

Don't know

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/user/.cache/go-build"
GOENV="/user/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/user/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/user/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go-1.15"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.15/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/user/Projects/go-exasol-client/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-build284804196=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I run a test using a TestMain:

var (
	exaClient *exaprovider.Client
	exaConf   exasol.ConnConf
)

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

func testRun(m *testing.M) int {
	exaConf = internal.MustCreateTestConf() // Sets Port to 8563
	exaClient = exaprovider.NewClient(exaConf)
	defer exaClient.Close()

	return m.Run()
}

What did you expect to see?

Would expect to never panic and never check true no matter what.

What did you see instead?

exasol.ConnConf has a field Port. If I add a check Port == 65040 into NewClient most of the times the check will be true.

If I however also change testRun to:

func testRun(m *testing.M) int {
	exaConf = internal.MustCreateTestConf()
	if exaConf.Port == 65040 {
		panic("TESTRUN")
	}
	exaClient = exaprovider.NewClient(exaConf)
	defer exaClient.Close()

	return m.Run()
}

it will never panic and the check inside NewClient will never be true.

Am I missing something obvious?

@seankhliao
Copy link
Contributor

@seankhliao seankhliao commented Oct 19, 2020

try running with the race detector?

sounds like a bug in your code, see https://github.com/golang/go/wiki/Questions for appropriate channels to ask questions

@abergmeier
Copy link
Author

@abergmeier abergmeier commented Oct 19, 2020

try running with the race detector?

Race detector is not complaining.

@abergmeier
Copy link
Author

@abergmeier abergmeier commented Oct 19, 2020

So I moved exaConf = internal.MustCreateTestConf() into a func init and it seems to work now. This really scares me.

@abergmeier abergmeier closed this Oct 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.