gotrack_test.go 684 B

123456789101112131415161718192021222324252627282930
  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. package http2
  5. import (
  6. "fmt"
  7. "strings"
  8. "testing"
  9. )
  10. func TestGoroutineLock(t *testing.T) {
  11. DebugGoroutines = true
  12. g := newGoroutineLock()
  13. g.check()
  14. sawPanic := make(chan interface{})
  15. go func() {
  16. defer func() { sawPanic <- recover() }()
  17. g.check() // should panic
  18. }()
  19. e := <-sawPanic
  20. if e == nil {
  21. t.Fatal("did not see panic from check in other goroutine")
  22. }
  23. if !strings.Contains(fmt.Sprint(e), "wrong goroutine") {
  24. t.Errorf("expected on see panic about running on the wrong goroutine; got %v", e)
  25. }
  26. }