From 4680494c783f1147677f0391ecf425ae52b2343f Mon Sep 17 00:00:00 2001 From: yacovm Date: Sun, 13 Jan 2019 21:44:48 +0200 Subject: [PATCH] [FAB-12126] Fix discovery client test flake This change set fixes the following test flake: Both p15 and p7 belonged to Org D, and had the same height. The endorsement policy of mycc3 was AND(A,B,C,D) and it was selecting one peer with the highest height from every org. Therefore, it can only select either p7 or p15. The test had a loop in it, that made sure that it selects both peers with high probability by iterating 10 times over the selection. I removed the loop, and made p7 to have a height of p15's height - 1, for the test to be deterministic. Also increased the iteration count for a test case by x3, to make it more stable. Change-Id: Id4b04197c0fe9229e68aa003e2c9ac6b0566d5d0 Signed-off-by: yacovm (cherry picked from commit c57633fe0bcf8293926258fc1960d676ade19ae2) --- discovery/client/client_test.go | 36 +++++++++++++++------------------ 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/discovery/client/client_test.go b/discovery/client/client_test.go index 8fda9b8e019..6a641e84f44 100644 --- a/discovery/client/client_test.go +++ b/discovery/client/client_test.go @@ -140,7 +140,7 @@ var ( newPeer(4, stateInfoMessageWithHeight(101, cc3), propertiesWithChaincodes).NetworkMember, newPeer(5, stateInfoMessageWithHeight(108, cc3), propertiesWithChaincodes).NetworkMember, newPeer(6, stateInfoMessageWithHeight(110, cc3), propertiesWithChaincodes).NetworkMember, - newPeer(7, stateInfoMessageWithHeight(111, cc3), propertiesWithChaincodes).NetworkMember, + newPeer(7, stateInfoMessageWithHeight(110, cc3), propertiesWithChaincodes).NetworkMember, newPeer(8, stateInfoMessageWithHeight(100, cc3), propertiesWithChaincodes).NetworkMember, newPeer(9, stateInfoMessageWithHeight(107, cc3), propertiesWithChaincodes).NetworkMember, newPeer(10, stateInfoMessageWithHeight(110, cc3), propertiesWithChaincodes).NetworkMember, @@ -506,16 +506,14 @@ func TestClient(t *testing.T) { mychannel := r.ForChannel("mychannel") // acceptablePeers are the ones at the highest ledger height for each org - acceptablePeers := []string{"p5", "p7", "p9", "p11", "p15"} + acceptablePeers := []string{"p5", "p9", "p11", "p15"} used := make(map[string]struct{}) - for i := 0; i < 10; i++ { - endorsers, err := mychannel.Endorsers(ccCall("mycc3"), NewFilter(PrioritiesByHeight, NoExclusion)) - assert.NoError(t, err) - names := getNames(endorsers) - assert.Subset(t, acceptablePeers, names) - for _, name := range names { - used[name] = struct{}{} - } + endorsers, err := mychannel.Endorsers(ccCall("mycc3"), NewFilter(PrioritiesByHeight, NoExclusion)) + assert.NoError(t, err) + names := getNames(endorsers) + assert.Subset(t, acceptablePeers, names) + for _, name := range names { + used[name] = struct{}{} } assert.Equalf(t, len(acceptablePeers), len(used), "expecting each endorser to be returned at least once") }) @@ -532,7 +530,7 @@ func TestClient(t *testing.T) { acceptablePeers := []string{"p1", "p9", "p3", "p5", "p6", "p7", "p10", "p11", "p12", "p14", "p15"} used := make(map[string]struct{}) - for i := 0; i < 30; i++ { + for i := 0; i < 90; i++ { endorsers, err := mychannel.Endorsers(ccCall("mycc3"), &ledgerHeightFilter{threshold: threshold}) assert.NoError(t, err) names := getNames(endorsers) @@ -544,16 +542,14 @@ func TestClient(t *testing.T) { assert.Equalf(t, len(acceptablePeers), len(used), "expecting each endorser to be returned at least once") threshold = 0 // only use the peers at the highest ledger height (same as using the PrioritiesByHeight selector) - acceptablePeers = []string{"p5", "p7", "p9", "p11", "p15"} + acceptablePeers = []string{"p5", "p9", "p11", "p15"} used = make(map[string]struct{}) - for i := 0; i < 10; i++ { - endorsers, err := mychannel.Endorsers(ccCall("mycc3"), &ledgerHeightFilter{threshold: threshold}) - assert.NoError(t, err) - names := getNames(endorsers) - assert.Subset(t, acceptablePeers, names) - for _, name := range names { - used[name] = struct{}{} - } + endorsers, err := mychannel.Endorsers(ccCall("mycc3"), &ledgerHeightFilter{threshold: threshold}) + assert.NoError(t, err) + names := getNames(endorsers) + assert.Subset(t, acceptablePeers, names) + for _, name := range names { + used[name] = struct{}{} } t.Logf("Used peers: %#v\n", used) assert.Equalf(t, len(acceptablePeers), len(used), "expecting each endorser to be returned at least once")