-
Notifications
You must be signed in to change notification settings - Fork 12
/
remote_object_registry_test.go
97 lines (75 loc) · 2.22 KB
/
remote_object_registry_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
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
package enigma
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestRpcObjectRegistry(t *testing.T) {
// Setup call registry"
ror := newRemoteObjectRegistry()
// Register object
object := &RemoteObject{ObjectInterface: &ObjectInterface{Handle: 25}}
ror.registerRemoteObject(object)
// get object
retrievedObject := ror.getRemoteObject(25)
assert.Equal(t, retrievedObject, object)
// UnRegister object
unregisteredObject := ror.unregisterRemoteObject(25)
assert.Equal(t, unregisteredObject, object)
// UnRegistered object should be gone
missingObject := ror.unregisterRemoteObject(25)
assert.Nil(t, missingObject)
}
func TestRemoteObjectRegistryHandleUpdatesClosed(t *testing.T) {
// Setup call registry"
ror := newRemoteObjectRegistry()
// Register object
object := newRemoteObject(nil, &ObjectInterface{Handle: 25})
ror.registerRemoteObject(object)
var objectClosed bool
// Check that the object is NOT closed
select {
case <-object.Closed():
objectClosed = true
default:
objectClosed = false
}
assert.False(t, objectClosed, "The object should not be closed before the close update")
// Send change event to handle 25
ror.handleUpdates([]int{}, []int{25})
// Check that the object IS closed
select {
case <-object.Closed():
objectClosed = true
default:
objectClosed = false
}
assert.True(t, objectClosed, "The object should now be closed")
}
func TestRemoteObjectRegistryHandleUpdatesChanged(t *testing.T) {
// Setup call registry"
ror := newRemoteObjectRegistry()
// Register object
object := newRemoteObject(nil, &ObjectInterface{Handle: 25})
ror.registerRemoteObject(object)
var objectChanged bool
changeChannel := object.ChangedChannel()
// Check that the object is NOT closed
select {
case <-changeChannel:
objectChanged = true
default:
objectChanged = false
}
assert.False(t, objectChanged, "The object should not be change before the change update")
// Send change event to handle 25
ror.handleUpdates([]int{}, []int{25})
// Check that the object IS changed
select {
case <-changeChannel:
objectChanged = true
default:
objectChanged = false
}
assert.True(t, objectChanged, "The object should now be changed")
object.RemoveChangeChannel(changeChannel)
}