Skip to content

Commit

Permalink
Attempt to fix flaky integration ApproveForMyOrg
Browse files Browse the repository at this point in the history
The lifecycle tests use the PeersWithChannel function to get a list of
peers to invoke ApproveChaincodeForMyOrg on.  That function then picks
the first peer from each org in this list.  Consequently, a random
subset of peers from orgs are picked.  Then sometimes, the peers will
have the implicit collection private data in their transient store, and
sometimes, they will not.

By making this function deterministic, we should ensure that these tests
consistently get Peer1 for their org, which is almost always the peer
which is selected for individual approvals.

This is untested (except soon to be in CI) but will hopefully reduce the
flakiness of these tests.

Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick authored and denyeart committed Dec 15, 2019
1 parent 1fe6954 commit 634e14b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions integration/nwo/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"os"
"os/exec"
"path/filepath"
"sort"
"strconv"
"strings"
"syscall"
Expand Down Expand Up @@ -1200,6 +1201,17 @@ func (n *Network) PeersWithChannel(chanName string) []*Peer {
}
}
}

// This is a bit of a hack to make the output of this function deterministic.
// When this function's output is supplied as input to functions such as ApproveChaincodeForMyOrg
// it causes a different subset of peers to be picked, which can create flakiness in tests.
sort.Slice(peers, func(i, j int) bool {
if peers[i].Organization < peers[j].Organization {
return true
}

return peers[i].Organization == peers[j].Organization && peers[i].Name < peers[j].Name
})
return peers
}

Expand Down

0 comments on commit 634e14b

Please sign in to comment.