You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
761 B

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