blob: 06db61231d94fd545b615983b7a0f886d91bf831 [file] [log] [blame]
Brad Fitzpatrick6fe76312014-11-11 09:26:28 -06001// 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.
Brad Fitzpatrick6fe76312014-11-11 09:26:28 -06004
5package http2
6
7import (
8 "fmt"
9 "strings"
10 "testing"
11)
12
13func TestGoroutineLock(t *testing.T) {
Jeff R. Allen6c894892015-12-19 16:51:57 +060014 oldDebug := DebugGoroutines
Brad Fitzpatrick6fe76312014-11-11 09:26:28 -060015 DebugGoroutines = true
Jeff R. Allen6c894892015-12-19 16:51:57 +060016 defer func() { DebugGoroutines = oldDebug }()
17
Brad Fitzpatrick6fe76312014-11-11 09:26:28 -060018 g := newGoroutineLock()
19 g.check()
20
21 sawPanic := make(chan interface{})
22 go func() {
23 defer func() { sawPanic <- recover() }()
24 g.check() // should panic
25 }()
26 e := <-sawPanic
27 if e == nil {
28 t.Fatal("did not see panic from check in other goroutine")
29 }
30 if !strings.Contains(fmt.Sprint(e), "wrong goroutine") {
31 t.Errorf("expected on see panic about running on the wrong goroutine; got %v", e)
32 }
33}