Skip to content

Commit

Permalink
[FAB-3949] refactor gossip UT waitgroup counter
Browse files Browse the repository at this point in the history
In the gossip tests there is a waitgroup counter that is
used for the last test (that checks that goroutines ended)
to be able to run only when all the other tests have finished.

Currently the waitgroup counter is initialized to the number of
tests but it should be initialized in a more dynamic way that
shows which tests are disabled and which tests are not.

Change-Id: I491d7d3676aeb79fbe2a30fadc63b27a37f003c9
Signed-off-by: yacovm <[email protected]>
  • Loading branch information
yacovm committed Aug 14, 2017
1 parent a73da04 commit a434b22
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
2 changes: 2 additions & 0 deletions gossip/gossip/anchor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ type msgInspection func(t *testing.T, index int, m *receivedMsg)

func TestAnchorPeer(t *testing.T) {
t.Parallel()
defer testWG.Done()
// Actors:
// OrgA: {
// p: a real gossip instance
Expand Down Expand Up @@ -281,6 +282,7 @@ func TestAnchorPeer(t *testing.T) {

func TestBootstrapPeerMisConfiguration(t *testing.T) {
t.Parallel()
defer testWG.Done()
// Scenario:
// The peer 'p' is a peer in orgA
// Peers bs1 and bs2 are bootstrap peers.
Expand Down
37 changes: 29 additions & 8 deletions gossip/gossip/gossip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ var timeout = time.Second * time.Duration(180)

var testWG = sync.WaitGroup{}

var tests = []func(t *testing.T){
TestPull,
TestConnectToAnchorPeers,
TestMembership,
TestDissemination,
TestMembershipConvergence,
TestMembershipRequestSpoofing,
TestDataLeakage,
//TestDisseminateAll2All: {},
TestIdentityExpiration,
TestMultipleOrgEndpointLeakage,
TestConfidentiality,
TestAnchorPeer,
TestBootstrapPeerMisConfiguration,
}

func init() {
util.SetupTestLogging()
rand.Seed(int64(time.Now().Second()))
Expand All @@ -44,7 +60,9 @@ func init() {
discovery.SetAliveExpirationTimeout(aliveTimeInterval * 10)
discovery.SetReconnectInterval(aliveTimeInterval)
discovery.SetMaxConnAttempts(5)
testWG.Add(6)
for range tests {
testWG.Add(1)
}
factory.InitFactories(nil)
identityExpirationCheckInterval = time.Second
}
Expand Down Expand Up @@ -251,7 +269,7 @@ func newGossipInstanceWithOnlyPull(portPrefix int, id int, maxMsgCount int, boot

func TestPull(t *testing.T) {
t.Parallel()

defer testWG.Done()
portPrefix := 5610
t1 := time.Now()
// Scenario: Turn off forwarding and use only pull-based gossip.
Expand Down Expand Up @@ -347,11 +365,11 @@ func TestPull(t *testing.T) {
t.Log("Took", time.Since(t1))
atomic.StoreInt32(&stopped, int32(1))
fmt.Println("<<<TestPull>>>")
testWG.Done()
}

func TestConnectToAnchorPeers(t *testing.T) {
t.Parallel()
defer testWG.Done()
// Scenario: spawn 10 peers, and have them join a channel
// of 3 anchor peers that don't exist yet.
// Wait 5 seconds, and then spawn a random anchor peer out of the 3.
Expand Down Expand Up @@ -415,11 +433,12 @@ func TestConnectToAnchorPeers(t *testing.T) {

fmt.Println("<<<TestConnectToAnchorPeers>>>")
atomic.StoreInt32(&stopped, int32(1))
testWG.Done()

}

func TestMembership(t *testing.T) {
t.Parallel()
defer testWG.Done()
portPrefix := 4610
t1 := time.Now()
// Scenario: spawn 20 nodes and a single bootstrap node and then:
Expand Down Expand Up @@ -496,11 +515,12 @@ func TestMembership(t *testing.T) {
t.Log("Took", time.Since(t1))
atomic.StoreInt32(&stopped, int32(1))
fmt.Println("<<<TestMembership>>>")
testWG.Done()

}

func TestDissemination(t *testing.T) {
t.Parallel()
defer testWG.Done()
portPrefix := 3610
t1 := time.Now()
// Scenario: 20 nodes and a bootstrap node.
Expand Down Expand Up @@ -611,11 +631,11 @@ func TestDissemination(t *testing.T) {
t.Log("Took", time.Since(t1))
atomic.StoreInt32(&stopped, int32(1))
fmt.Println("<<<TestDissemination>>>")
testWG.Done()
}

func TestMembershipConvergence(t *testing.T) {
t.Parallel()
defer testWG.Done()
portPrefix := 2610
// Scenario: Spawn 12 nodes and 3 bootstrap peers
// but assign each node to its bootstrap peer group modulo 3.
Expand Down Expand Up @@ -709,11 +729,11 @@ func TestMembershipConvergence(t *testing.T) {
atomic.StoreInt32(&stopped, int32(1))
t.Log("Took", time.Since(t1))
fmt.Println("<<<TestMembershipConvergence>>>")
testWG.Done()
}

func TestMembershipRequestSpoofing(t *testing.T) {
t.Parallel()
defer testWG.Done()
// Scenario: g1, g2, g3 are peers, and g2 is malicious, and wants
// to impersonate g3 when sending a membership request to g1.
// Expected output: g1 should *NOT* respond to g2,
Expand Down Expand Up @@ -784,6 +804,7 @@ func TestMembershipRequestSpoofing(t *testing.T) {

func TestDataLeakage(t *testing.T) {
t.Parallel()
defer testWG.Done()
portPrefix := 1610
// Scenario: spawn some nodes and let them all
// establish full membership.
Expand Down Expand Up @@ -907,7 +928,6 @@ func TestDataLeakage(t *testing.T) {
t.Log("Stop took", time.Since(stopTime))
atomic.StoreInt32(&stopped, int32(1))
fmt.Println("<<<TestDataLeakage>>>")
testWG.Done()
}

func TestDisseminateAll2All(t *testing.T) {
Expand Down Expand Up @@ -983,6 +1003,7 @@ func TestDisseminateAll2All(t *testing.T) {

func TestIdentityExpiration(t *testing.T) {
t.Parallel()
defer testWG.Done()
// Scenario: spawn 4 peers and make the MessageCryptoService revoke one of them.
// Eventually, the rest of the peers should not be able to communicate with
// the revoked peer at all because its identity would seem to them as expired
Expand Down
2 changes: 2 additions & 0 deletions gossip/gossip/orgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func newGossipInstanceWithExternalEndpoint(portPrefix int, id int, mcs *configur

func TestMultipleOrgEndpointLeakage(t *testing.T) {
t.Parallel()
defer testWG.Done()
// Scenario: create 2 organizations, each with 5 peers.
// The first org will have an anchor peer, but the second won't.
// The first 2 peers of each org would have an external endpoint, the rest won't.
Expand Down Expand Up @@ -253,6 +254,7 @@ func TestMultipleOrgEndpointLeakage(t *testing.T) {

func TestConfidentiality(t *testing.T) {
t.Parallel()
defer testWG.Done()
// Scenario: create 4 organizations: {A, B, C, D}, each with 3 peers.
// Make only the first 2 peers have an external endpoint.
// Also, add the peers to the following channels:
Expand Down

0 comments on commit a434b22

Please sign in to comment.