@@ -17,6 +17,7 @@ limitations under the License.
17
17
package service
18
18
19
19
import (
20
+ "sync"
20
21
"testing"
21
22
"time"
22
23
@@ -80,7 +81,7 @@ func (*gossipMock) Accept(acceptor common.MessageAcceptor, passThrough bool) (<-
80
81
}
81
82
82
83
func (g * gossipMock ) JoinChan (joinMsg api.JoinChannelMessage , chainID common.ChainID ) {
83
- g .Called ()
84
+ g .Called (joinMsg , chainID )
84
85
}
85
86
86
87
func (* gossipMock ) Stop () {
@@ -99,21 +100,20 @@ func (ao *appOrgMock) MSPID() string {
99
100
return ao .id
100
101
}
101
102
102
- func (* appOrgMock ) AnchorPeers () []* peer.AnchorPeer {
103
- return []* peer.AnchorPeer {{ Host : "1.2.3.4" , Port : 5611 } }
103
+ func (ao * appOrgMock ) AnchorPeers () []* peer.AnchorPeer {
104
+ return []* peer.AnchorPeer {}
104
105
}
105
106
106
107
type configMock struct {
108
+ orgs2AppOrgs map [string ]config.ApplicationOrg
107
109
}
108
110
109
111
func (* configMock ) ChainID () string {
110
112
return "A"
111
113
}
112
114
113
- func (* configMock ) Organizations () map [string ]config.ApplicationOrg {
114
- return map [string ]config.ApplicationOrg {
115
- "Org0" : & appOrgMock {"Org0" },
116
- }
115
+ func (c * configMock ) Organizations () map [string ]config.ApplicationOrg {
116
+ return c .orgs2AppOrgs
117
117
}
118
118
119
119
func (* configMock ) Sequence () uint64 {
@@ -127,11 +127,15 @@ func TestJoinChannelConfig(t *testing.T) {
127
127
128
128
failChan := make (chan struct {}, 1 )
129
129
g1SvcMock := & gossipMock {}
130
- g1SvcMock .On ("JoinChan" , mock .Anything ).Run (func (_ mock.Arguments ) {
130
+ g1SvcMock .On ("JoinChan" , mock .Anything , mock . Anything ).Run (func (_ mock.Arguments ) {
131
131
failChan <- struct {}{}
132
132
})
133
133
g1 := & gossipServiceImpl {secAdv : & secAdvMock {}, peerIdentity : api .PeerIdentityType ("OrgMSP0" ), gossipSvc : g1SvcMock }
134
- g1 .configUpdated (& configMock {})
134
+ g1 .configUpdated (& configMock {
135
+ orgs2AppOrgs : map [string ]config.ApplicationOrg {
136
+ "Org0" : & appOrgMock {id : "Org0" },
137
+ },
138
+ })
135
139
select {
136
140
case <- time .After (time .Second ):
137
141
case <- failChan :
@@ -140,15 +144,55 @@ func TestJoinChannelConfig(t *testing.T) {
140
144
141
145
succChan := make (chan struct {}, 1 )
142
146
g2SvcMock := & gossipMock {}
143
- g2SvcMock .On ("JoinChan" , mock .Anything ).Run (func (_ mock.Arguments ) {
147
+ g2SvcMock .On ("JoinChan" , mock .Anything , mock . Anything ).Run (func (_ mock.Arguments ) {
144
148
succChan <- struct {}{}
145
149
})
146
150
g2 := & gossipServiceImpl {secAdv : & secAdvMock {}, peerIdentity : api .PeerIdentityType ("Org0" ), gossipSvc : g2SvcMock }
147
- g2 .configUpdated (& configMock {})
151
+ g2 .configUpdated (& configMock {
152
+ orgs2AppOrgs : map [string ]config.ApplicationOrg {
153
+ "Org0" : & appOrgMock {id : "Org0" },
154
+ },
155
+ })
148
156
select {
149
157
case <- time .After (time .Second ):
150
158
assert .Fail (t , "Didn't join a channel (should have done so within the time period)" )
151
159
case <- succChan :
152
160
153
161
}
154
162
}
163
+
164
+ func TestJoinChannelNoAnchorPeers (t * testing.T ) {
165
+ // Scenario: The channel we're joining has 2 orgs but no anchor peers
166
+ // The test ensures that JoinChan is called with a JoinChannelMessage with Members
167
+ // that consist of the organizations of the configuration given.
168
+
169
+ var joinChanCalled sync.WaitGroup
170
+ joinChanCalled .Add (1 )
171
+ gMock := & gossipMock {}
172
+ gMock .On ("JoinChan" , mock .Anything , mock .Anything ).Run (func (args mock.Arguments ) {
173
+ defer joinChanCalled .Done ()
174
+ jcm := args .Get (0 ).(api.JoinChannelMessage )
175
+ channel := args .Get (1 ).(common.ChainID )
176
+ assert .Len (t , jcm .Members (), 2 )
177
+ assert .Contains (t , jcm .Members (), api .OrgIdentityType ("Org0" ))
178
+ assert .Contains (t , jcm .Members (), api .OrgIdentityType ("Org1" ))
179
+ assert .Equal (t , "A" , string (channel ))
180
+ })
181
+
182
+ g := & gossipServiceImpl {secAdv : & secAdvMock {}, peerIdentity : api .PeerIdentityType ("Org0" ), gossipSvc : gMock }
183
+
184
+ appOrg0 := & appOrgMock {id : "Org0" }
185
+ appOrg1 := & appOrgMock {id : "Org1" }
186
+
187
+ // Make sure the ApplicationOrgs really have no anchor peers
188
+ assert .Empty (t , appOrg0 .AnchorPeers ())
189
+ assert .Empty (t , appOrg1 .AnchorPeers ())
190
+
191
+ g .configUpdated (& configMock {
192
+ orgs2AppOrgs : map [string ]config.ApplicationOrg {
193
+ "Org0" : appOrg0 ,
194
+ "Org1" : appOrg1 ,
195
+ },
196
+ })
197
+ joinChanCalled .Wait ()
198
+ }
0 commit comments