-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext3_test.go
57 lines (42 loc) · 1.37 KB
/
context3_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package context_test
import (
"fmt"
"testing"
context "github.com/mcfly722/context"
)
type node4 struct {
close chan context.ChildContext
sequenceChecker sequenceChecker
}
func (node *node4) Go(current context.Context) {
node.sequenceChecker.NotifyWithText(3, "waiting for root context\n")
rootContext := <-node.close
node.sequenceChecker.NotifyWithText(4, "root context obtained\n")
newNode := &node4{}
node.sequenceChecker.NotifyWithText(5, "close context\n")
current.Close()
node.sequenceChecker.NotifyWithText(6, "creating new SubContext\n")
_, err := current.NewContextFor(newNode)
if err != nil {
_, ok := err.(*context.ClosingIsInProcessForDisposingError)
if ok {
node.sequenceChecker.NotifyWithText(7, "successfully catched error: %v\n", err)
rootContext.Close()
} else {
panic("uncatched error")
}
}
}
func Test_NewInstanceDuringClosing(t *testing.T) {
sequenceChecker := newSequenceChecker()
rootNode := &node4{
close: make(chan context.ChildContext),
sequenceChecker: sequenceChecker,
}
sequenceChecker.NotifyWithText(1, "creating new context \n")
rootContext := context.NewRootContext(rootNode)
sequenceChecker.NotifyWithText(2, "send rootContext to node close channel\n")
rootNode.close <- rootContext
rootContext.Wait()
fmt.Printf("test finished with correct sequence = %v\n", sequenceChecker.ToString())
}