-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathchild_parity_test.go
More file actions
58 lines (49 loc) · 1.61 KB
/
child_parity_test.go
File metadata and controls
58 lines (49 loc) · 1.61 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
package featurevisor
import "testing"
func TestChildEventIsolationAndProxying(t *testing.T) {
instance := CreateInstance(Options{
Datafile: DatafileContent{
SchemaVersion: "2",
Revision: "1",
Features: map[FeatureKey]Feature{},
Segments: map[SegmentKey]Segment{},
},
})
child := instance.Spawn()
childContextEvents := 0
parentContextEvents := 0
childDatafileEvents := 0
childUnsubscribe := child.On(EventNameContextSet, func(details EventDetails) {
childContextEvents++
})
defer childUnsubscribe()
parentUnsubscribe := instance.On(EventNameContextSet, func(details EventDetails) {
parentContextEvents++
})
defer parentUnsubscribe()
datafileUnsubscribe := child.On(EventNameDatafileSet, func(details EventDetails) {
childDatafileEvents++
})
defer datafileUnsubscribe()
child.SetContext(Context{"userId": "123"})
if childContextEvents != 1 {
t.Fatalf("expected child context_set listener to be called once, got %d", childContextEvents)
}
if parentContextEvents != 0 {
t.Fatalf("expected parent context_set listener not to be called by child.setContext, got %d", parentContextEvents)
}
instance.SetDatafile(DatafileContent{
SchemaVersion: "2",
Revision: "2",
Features: map[FeatureKey]Feature{},
Segments: map[SegmentKey]Segment{},
})
if childDatafileEvents != 1 {
t.Fatalf("expected child datafile_set listener to proxy parent event, got %d", childDatafileEvents)
}
child.Close()
child.SetContext(Context{"country": "nl"})
if childContextEvents != 1 {
t.Fatalf("expected child listeners to be cleared after close, got %d", childContextEvents)
}
}