smartystreets / goconvey

Go testing in the browser. Integrates with `go test`. Write behavioral tests in Go.
http://smartystreets.github.io/goconvey/
Other
8.25k stars 555 forks source link

Panic on master with t.Parallel, go 1.9, and Reset #506

Open cep21 opened 6 years ago

cep21 commented 6 years ago

Reproducible test case:

> cat convey_test.go 
package convey

import (
    . "github.com/smartystreets/goconvey/convey"
    "testing"
)

func TestFoo(t *testing.T) {
    t.Parallel()
    Convey("Foo", t, func() {
        Reset(func() {})
    })
}

func TestBar(t *testing.T) {
    t.Parallel()
    Convey("Foo", t, func() {
        Reset(func() {})
    })
}

Output:

16:53:51 jlindamo@f45c89cadf27.ant.amazon.com:/tmp
< go test -v .
=== RUN   TestFoo
=== RUN   TestBar

  Foo 

  Foo 

0 total assertions

--- PASS: TestFoo (0.00s)

0 total assertions

--- FAIL: TestBar (0.00s)
panic: Convey operation made without context on goroutine stack.
Hint: Perhaps you meant to use `Convey(..., func(c C){...})` ? [recovered]
    panic: Convey operation made without context on goroutine stack.
Hint: Perhaps you meant to use `Convey(..., func(c C){...})` ? [recovered]
    panic: Convey operation made without context on goroutine stack.
Hint: Perhaps you meant to use `Convey(..., func(c C){...})` ?

goroutine 6 [running]:
testing.tRunner.func1(0xc4200a41e0)
    /usr/local/Cellar/go/1.9.2/libexec/src/testing/testing.go:711 +0x2d2
panic(0x11468c0, 0xc4200b8180)
    /usr/local/Cellar/go/1.9.2/libexec/src/runtime/panic.go:491 +0x283
github.com/smartystreets/goconvey/convey.(*context).conveyInner.func2(0xc4200ba000)
    /Users/jlindamo/go/src/github.com/smartystreets/goconvey/convey/context.go:232 +0x1c8
panic(0x11468c0, 0xc4200b8180)
    /usr/local/Cellar/go/1.9.2/libexec/src/runtime/panic.go:491 +0x283
github.com/smartystreets/goconvey/convey.conveyPanic(0x117cb47, 0x78, 0x0, 0x0, 0x0)
    /Users/jlindamo/go/src/github.com/smartystreets/goconvey/convey/context.go:20 +0xca
github.com/smartystreets/goconvey/convey.mustGetCurrentContext(0xc420048ab8)
    /Users/jlindamo/go/src/github.com/smartystreets/goconvey/convey/context.go:52 +0x73
github.com/smartystreets/goconvey/convey.(*context).Reset(...)
    /Users/jlindamo/go/src/github.com/smartystreets/goconvey/convey/doc.go:102
github.com/smartystreets/goconvey/convey.Reset(0x117cf10)
    /Users/jlindamo/go/src/github.com/smartystreets/goconvey/convey/doc.go:102 +0x26
_/tmp.TestBar.func1()
    /tmp/convey_test.go:18 +0x2d
github.com/smartystreets/goconvey/convey.parseAction.func1(0x122b7c0, 0xc4200ba000)
    /Users/jlindamo/go/src/github.com/smartystreets/goconvey/convey/discovery.go:80 +0x24
github.com/smartystreets/goconvey/convey.(*context).conveyInner(0xc4200ba000, 0x117365f, 0x3, 0xc4200b0000)
    /Users/jlindamo/go/src/github.com/smartystreets/goconvey/convey/context.go:261 +0x162
github.com/smartystreets/goconvey/convey.rootConvey.func1()
    /Users/jlindamo/go/src/github.com/smartystreets/goconvey/convey/context.go:110 +0xec
github.com/jtolds/gls.(*ContextManager).SetValues.func1(0x1)
    /Users/jlindamo/go/src/github.com/jtolds/gls/context.go:97 +0x463
github.com/jtolds/gls.EnsureGoroutineId.func1()
    /Users/jlindamo/go/src/github.com/jtolds/gls/gid.go:24 +0x31
github.com/jtolds/gls._m(0x0, 0xc4200b6080)
    /Users/jlindamo/go/src/github.com/jtolds/gls/stack_tags.go:74 +0x31
github.com/jtolds/gls.github_com_jtolds_gls_mark1(0x0, 0xc4200b6080)
    /Users/jlindamo/go/src/github.com/jtolds/gls/stack_tags.go:56 +0x35
github.com/jtolds/gls._m(0x1, 0xc4200b6080)
    /Users/jlindamo/go/src/github.com/jtolds/gls/stack_tags.go:76 +0x64
github.com/jtolds/gls.github_com_jtolds_gls_markS(0x1, 0xc4200b6080)
    /Users/jlindamo/go/src/github.com/jtolds/gls/stack_tags.go:54 +0x35
github.com/jtolds/gls.addStackTag(0x1, 0xc4200b6080)
    /Users/jlindamo/go/src/github.com/jtolds/gls/stack_tags.go:49 +0x3a
github.com/jtolds/gls.EnsureGoroutineId(0xc4200b80f0)
    /Users/jlindamo/go/src/github.com/jtolds/gls/gid.go:24 +0xc9
github.com/jtolds/gls.(*ContextManager).SetValues(0xc420050510, 0xc4200b8090, 0xc4200b6040)
    /Users/jlindamo/go/src/github.com/jtolds/gls/context.go:63 +0x177
github.com/smartystreets/goconvey/convey.rootConvey(0xc420034768, 0x3, 0x3)
    /Users/jlindamo/go/src/github.com/smartystreets/goconvey/convey/context.go:105 +0x2d6
github.com/smartystreets/goconvey/convey.Convey(0xc420034768, 0x3, 0x3)
    /Users/jlindamo/go/src/github.com/smartystreets/goconvey/convey/doc.go:75 +0x7a
_/tmp.TestBar(0xc4200a41e0)
    /tmp/convey_test.go:17 +0xb4
testing.tRunner(0xc4200a41e0, 0x117cf20)
    /usr/local/Cellar/go/1.9.2/libexec/src/testing/testing.go:746 +0xd0
created by testing.(*T).Run
    /usr/local/Cellar/go/1.9.2/libexec/src/testing/testing.go:789 +0x2de
exit status 2
FAIL    _/tmp   0.872s

Using version 1.9.2:

> go version
go version go1.9.2 darwin/amd64

Using version 1.8.3, the test passes without issues

I have done a go get to get the latest master code, as well as cleared my pkg directory: still no fixes.

MelleKoning commented 6 years ago

Seems that sub-GoConvey calls are attributed to the Root. Debugging into go convey reveals that getting the current context always returns nil, hence all sub-GoConvey calls are attributed to Root.

image

The issue is visible after upgrading from go version 1.8.4 to go version 1.9.1