1package tests
2
3import (
4	"testing"
5	"time"
6)
7
8func inner(ch chan struct{}, b bool) ([]byte, error) {
9	// ensure gopherjs thinks that this inner function can block
10	if b {
11		<-ch
12	}
13	return []byte{}, nil
14}
15
16// this function's call to inner never blocks, but the deferred
17// statement does.
18func outer(ch chan struct{}, b bool) ([]byte, error) {
19	defer func() {
20		<-ch
21	}()
22
23	return inner(ch, b)
24}
25
26func TestBlockingInDefer(t *testing.T) {
27	defer func() {
28		if x := recover(); x != nil {
29			t.Errorf("run time panic: %v", x)
30		}
31	}()
32
33	ch := make(chan struct{})
34	b := false
35
36	go func() {
37		time.Sleep(5 * time.Millisecond)
38		ch <- struct{}{}
39	}()
40
41	outer(ch, b)
42}
43