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

plugin: same type but not equal in unit tests #22505

Closed
xupeilin opened this issue Oct 31, 2017 · 8 comments
Closed

plugin: same type but not equal in unit tests #22505

xupeilin opened this issue Oct 31, 2017 · 8 comments

Comments

@xupeilin
Copy link

Please answer these questions before submitting your issue. Thanks!

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

1.9.2

Does this issue reproduce with the latest release?

Yes

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/peilinx/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="/usr/bin/gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build149591310=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

Maybe similar with #19233, but still reproducing in my env.
Here(https://github.com/opera/terago/tree/plugin_test) is an simplest reproducing env.
Program(plugin_test) and unit test (plugin_test.go) have same code.

  • exec go build -buildmode plugin plugin/terago.go to gen terago.so
  • exec go build -o plugin_example examples/plugin.go to compile plugin_example and this program can run correctly.
  • exec go test -v plugin_test.go interface.go to run unit test. Here will get a failure as follow:
=== RUN   Test
--- FAIL: Test (0.00s)
panic: interface conversion: plugin.Symbol is func(string, string) (terago.ClientI, error), not func(string, string) (terago.ClientI, error) [recovered]
	panic: interface conversion: plugin.Symbol is func(string, string) (terago.ClientI, error), not func(string, string) (terago.ClientI, error)

goroutine 5 [running]:
testing.tRunner.func1(0xc42009e0f0)
	/usr/local/go/src/testing/testing.go:711 +0x2d2
panic(0x5ef860, 0xc4200606c0)
	/usr/local/go/src/runtime/panic.go:491 +0x283
command-line-arguments.Test(0xc42009e0f0)
	/home/peilinx/go/src/github.com/opera/terago/plugin_test.go:23 +0x494
testing.tRunner(0xc42009e0f0, 0x61f000)
	/usr/local/go/src/testing/testing.go:746 +0xd0
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:789 +0x2de
exit status 2
FAIL	command-line-arguments	0.016s

What did you expect to see?

run unit test correctly

What did you see instead?

running error, type assert error
interface conversion: plugin.Symbol is func(string, string) (terago.ClientI, error), not func(string, string) (terago.ClientI, error)

@ianlancetaylor
Copy link
Contributor

I tried to follow your reproduction instructions. In order to build the plugin I had to add -tags mock. To avoid version errors I had to use that option with the other builds. Running go test succeeds for me. You suggest running go test plugin_test.go interface.go but there is no file plugin_test.go and that command doesn't make much sense anyhow.

Please show us the exact commands that you type and the exact output that you get. Thanks.

@ianlancetaylor ianlancetaylor changed the title plugin same type but not equal in unit tests plugin: same type but not equal in unit tests Oct 31, 2017
@ianlancetaylor
Copy link
Contributor

CC @crawshaw

@xupeilin
Copy link
Author

xupeilin commented Nov 1, 2017

@ianlancetaylor Thanks for your attention. I think you had compiled master branch of the project. I've simplified the code and put them on a branch named plugin_test.

@ianlancetaylor
Copy link
Contributor

Please show us the exact commands that you type and the exact output that you get. Thanks.

@xupeilin
Copy link
Author

xupeilin commented Nov 1, 2017

Sorry, I don't describe the problem clearly. Now I record all command and output step by step.

  1. Checkout code from https://github.com/opera/terago/tree/plugin_test (plugin_test is a branch, not master)
  2. Run go build -buildmode plugin plugin/terago.go
  3. Run go build -o plugin_example examples/plugin.go
  4. Run go test -v plugin_test.go interface.go

Here is all output:

peilinx@:~/go/src/github.com/opera/terago$ ls
client_mock.go  examples  interface.go  LICENSE  Makefile  plugin  plugin_test.go  README.md
peilinx@:~/go/src/github.com/opera/terago$ go build -buildmode plugin plugin/terago.go
peilinx@:~/go/src/github.com/opera/terago$ go build -o plugin_example examples/plugin.go
peilinx@:~/go/src/github.com/opera/terago$ ls
client_mock.go  examples  interface.go  LICENSE  Makefile  plugin  plugin_example  plugin_test.go  README.md  terago.so
peilinx@:~/go/src/github.com/opera/terago$ ./plugin_example 
new mock client
close mock client
peilinx@:~/go/src/github.com/opera/terago$ go test -v plugin_test.go interface.go
=== RUN   Test
--- FAIL: Test (0.01s)
panic: interface conversion: plugin.Symbol is func(string, string) (terago.ClientI, error), not func(string, string) (terago.ClientI, error) [recovered]
	panic: interface conversion: plugin.Symbol is func(string, string) (terago.ClientI, error), not func(string, string) (terago.ClientI, error)

goroutine 5 [running]:
testing.tRunner.func1(0xc42009c0f0)
	/usr/local/go/src/testing/testing.go:711 +0x2d2
panic(0x5ef860, 0xc4200606c0)
	/usr/local/go/src/runtime/panic.go:491 +0x283
command-line-arguments.Test(0xc42009c0f0)
	/home/peilinx/go/src/github.com/opera/terago/plugin_test.go:23 +0x494
testing.tRunner(0xc42009c0f0, 0x61f000)
	/usr/local/go/src/testing/testing.go:746 +0xd0
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:789 +0x2de
exit status 2
FAIL	command-line-arguments	0.013s
peilinx@:~/go/src/github.com/opera/terago$ 

examples/plugin.go and plugin_test.go are almost same code. But unit test cannot pass.

@AlexRouSg
Copy link
Contributor

Change your test file to be like this https://pastebin.com/3TuSkHVQ

terago/plugin imports terago and the test file is in package terago. Building the plugin will not include the test file therefore the packages are different on compile time.

Changing the test file to be in package terago_test makes it a different package and therefore makes terago the same package when compiling the plugin and test.

@xupeilin
Copy link
Author

xupeilin commented Nov 2, 2017

@AlexRouSg Thank you. You are right. Now the unit test is passed.
Verify mechanism of plugins is so strict.

@ianlancetaylor
Copy link
Contributor

Sounds like this is fixed, more or less.

@golang golang locked and limited conversation to collaborators Mar 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants