Skip to content

Commit 2448b5e

Browse files
Jason Yellickmastersingh24
Jason Yellick
authored andcommitted
FAB-16544 Properly detect node-readdition
As pointed our in the review of the CR above, there was a logic bug in handling removed organizations. This CR adds a tests case and a fix. Signed-off-by: Jason Yellick <[email protected]> Change-Id: I6b4d7d0bb3d602867144860508b6683d7b23eb5e
1 parent ffa3335 commit 2448b5e

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

internal/pkg/peer/orderers/connection.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ func (cs *ConnectionSource) Update(globalAddrs []string, orgs map[string]Orderer
6060
defer cs.mutex.Unlock()
6161
cs.logger.Debug("Processing updates for orderer endpoints")
6262

63+
newOrgToEndpointsHash := map[string][]byte{}
64+
6365
anyChange := false
6466
hasOrgEndpoints := false
6567
for orgName, org := range orgs {
@@ -73,8 +75,9 @@ func (cs *ConnectionSource) Update(globalAddrs []string, orgs map[string]Orderer
7375
}
7476
hash := hasher.Sum(nil)
7577

78+
newOrgToEndpointsHash[orgName] = hash
79+
7680
lastHash, ok := cs.orgToEndpointsHash[orgName]
77-
cs.orgToEndpointsHash[orgName] = hash
7881
if ok && bytes.Equal(hash, lastHash) {
7982
continue
8083
}
@@ -91,6 +94,8 @@ func (cs *ConnectionSource) Update(globalAddrs []string, orgs map[string]Orderer
9194
}
9295
}
9396

97+
cs.orgToEndpointsHash = newOrgToEndpointsHash
98+
9499
if hasOrgEndpoints && len(globalAddrs) > 0 {
95100
cs.logger.Warning("Config defines both orderer org specific endpoints and global endpoints, global endpoints will be ignored")
96101
}

internal/pkg/peer/orderers/connection_test.go

+33
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,39 @@ var _ = Describe("Connection", func() {
297297
Expect(endpoint.Refreshed).To(BeClosed())
298298
}
299299
})
300+
301+
When("the org is added back", func() {
302+
BeforeEach(func() {
303+
cs.Update(nil, map[string]orderers.OrdererOrg{
304+
"org1": org1,
305+
"org2": org2,
306+
})
307+
})
308+
309+
It("returns to the set of orderer endpoints", func() {
310+
newEndpoints := cs.Endpoints()
311+
Expect(stripEndpoints(newEndpoints)).To(ConsistOf(
312+
stripEndpoints([]*orderers.Endpoint{
313+
{
314+
Address: "org1-address1",
315+
CertPool: org1CertPool,
316+
},
317+
{
318+
Address: "org1-address2",
319+
CertPool: org1CertPool,
320+
},
321+
{
322+
Address: "org2-address1",
323+
CertPool: org2CertPool,
324+
},
325+
{
326+
Address: "org2-address2",
327+
CertPool: org2CertPool,
328+
},
329+
}),
330+
))
331+
})
332+
})
300333
})
301334

302335
When("an update modifies the global endpoints but does does not affect the org endpoints", func() {

0 commit comments

Comments
 (0)