gotrack_test.go 848 B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright 2014 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // See https://code.google.com/p/go/source/browse/CONTRIBUTORS
  5. // Licensed under the same terms as Go itself:
  6. // https://code.google.com/p/go/source/browse/LICENSE
  7. package http2
  8. import (
  9. "fmt"
  10. "strings"
  11. "testing"
  12. )
  13. func TestGoroutineLock(t *testing.T) {
  14. DebugGoroutines = true
  15. g := newGoroutineLock()
  16. g.check()
  17. sawPanic := make(chan interface{})
  18. go func() {
  19. defer func() { sawPanic <- recover() }()
  20. g.check() // should panic
  21. }()
  22. e := <-sawPanic
  23. if e == nil {
  24. t.Fatal("did not see panic from check in other goroutine")
  25. }
  26. if !strings.Contains(fmt.Sprint(e), "wrong goroutine") {
  27. t.Errorf("expected on see panic about running on the wrong goroutine; got %v", e)
  28. }
  29. }