Repository navigation
Expand file tree
/
Copy pathvalue_test.go
More file actions
103 lines (82 loc) · 1.57 KB
/
Copy pathvalue_test.go
File metadata and controls
103 lines (82 loc) · 1.57 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package shadow
import (
"testing"
"time"
)
func TestValue(t *testing.T) {
var v Value
// Start trying to get the value
valueCh := make(chan interface{})
go func() {
valueCh <- v.Value()
}()
// We should not get the value
select {
case <-valueCh:
t.Fatal("shouldn't receive value")
case <-time.After(10 * time.Millisecond):
}
// Set the value
v.SetValue(42)
val := <-valueCh
// Verify
if val != 42 {
t.Fatalf("bad: %#v", val)
}
// We should be able to ask for the value again immediately
if val := v.Value(); val != 42 {
t.Fatalf("bad: %#v", val)
}
// We can change the value
v.SetValue(84)
if val := v.Value(); val != 84 {
t.Fatalf("bad: %#v", val)
}
}
func TestValueClose(t *testing.T) {
var v Value
// Close
v.Close()
// Verify
val := v.Value()
if val != ErrClosed {
t.Fatalf("bad: %#v", val)
}
}
func TestValueClose_blocked(t *testing.T) {
var v Value
// Start trying to get the value
valueCh := make(chan interface{})
go func() {
valueCh <- v.Value()
}()
// We should not get the value
select {
case <-valueCh:
t.Fatal("shouldn't receive value")
case <-time.After(10 * time.Millisecond):
}
// Set the value
v.Close()
val := <-valueCh
// Verify
if val != ErrClosed {
t.Fatalf("bad: %#v", val)
}
// We should be able to ask for the value again immediately
if val := v.Value(); val != ErrClosed {
t.Fatalf("bad: %#v", val)
}
}
func TestValueClose_existing(t *testing.T) {
var v Value
// Set the value
v.SetValue(42)
// Close
v.Close()
// Verify
val := v.Value()
if val != 42 {
t.Fatalf("bad: %#v", val)
}
}