github.com/koko1123/flow-go-1@v0.29.6/consensus/integration/slow_test.go (about)

     1  //go:build timesensitivetest
     2  // +build timesensitivetest
     3  
     4  // This file includes a few time sensitive tests. They might pass on your powerful local machine
     5  // but fail on slow CI machine.
     6  // For now, these tests are only for local. Run it with the build tag on:
     7  // > go test --tags=relic,timesensitivetest ./...
     8  
     9  package integration_test
    10  
    11  import (
    12  	"testing"
    13  	"time"
    14  )
    15  
    16  // verify if a node lost some messages, it's still able to catch up.
    17  func TestMessagesLost(t *testing.T) {
    18  
    19  	nodes, stopper, hub := createNodes(t, 5, 1000)
    20  
    21  	hub.WithFilter(blockNodesForFirstNMessages(50, nodes[0]))
    22  	runNodes(nodes)
    23  
    24  	<-stopper.stopped
    25  
    26  	for i := range nodes {
    27  		printState(t, nodes, i)
    28  	}
    29  	allViews := allFinalizedViews(t, nodes)
    30  	assertSafety(t, allViews)
    31  	assertLiveness(t, allViews, 60)
    32  	cleanupNodes(nodes)
    33  }
    34  
    35  // verify if each receiver lost 10% messages, the network can still reach consensus
    36  func TestMessagesLostAcrossNetwork(t *testing.T) {
    37  
    38  	nodes, stopper, hub := createNodes(t, 5, 1500)
    39  
    40  	hub.WithFilter(blockReceiverMessagesByPercentage(10))
    41  	runNodes(nodes)
    42  
    43  	<-stopper.stopped
    44  
    45  	for i := range nodes {
    46  		printState(t, nodes, i)
    47  	}
    48  	allViews := allFinalizedViews(t, nodes)
    49  	assertSafety(t, allViews)
    50  	assertLiveness(t, allViews, 50)
    51  	cleanupNodes(nodes)
    52  }
    53  
    54  // verify if each receiver receive delayed messages, the network can still reach consensus
    55  // the delay might skip some blocks, so should expect to see some gaps in the finalized views
    56  // like this:
    57  // [1 2 3 4 10 11 12 17 20 21 22 23 28 31 33 36 39 44 47 53 58 61 62 79 80 88 89 98 101 106 108 111 115 116 119 120 122 123 124 126 127 128 129 130 133 134 135 138 141 142 143 144]
    58  func TestDelay(t *testing.T) {
    59  
    60  	nodes, stopper, hub := createNodes(t, 5, 1500)
    61  
    62  	hub.WithFilter(delayReceiverMessagesByRange(hotstuffTimeout/10, hotstuffTimeout/2))
    63  	runNodes(nodes)
    64  
    65  	<-stopper.stopped
    66  
    67  	for i := range nodes {
    68  		printState(t, nodes, i)
    69  	}
    70  	allViews := allFinalizedViews(t, nodes)
    71  	assertSafety(t, allViews)
    72  	assertLiveness(t, allViews, 60)
    73  	cleanupNodes(nodes)
    74  }
    75  
    76  // verify that if a node always
    77  func TestOneNodeBehind(t *testing.T) {
    78  	nodes, stopper, hub := createNodes(t, 5, 1500)
    79  
    80  	hub.WithFilter(func(channelID string, event interface{}, sender, receiver *Node) (bool, time.Duration) {
    81  		if receiver == nodes[0] {
    82  			return false, hotstuffTimeout + time.Millisecond
    83  		}
    84  		// no block or delay to other nodes
    85  		return false, 0
    86  	})
    87  	runNodes(nodes)
    88  
    89  	<-stopper.stopped
    90  
    91  	for i := range nodes {
    92  		printState(t, nodes, i)
    93  	}
    94  	allViews := allFinalizedViews(t, nodes)
    95  	assertSafety(t, allViews)
    96  	assertLiveness(t, allViews, 60)
    97  	cleanupNodes(nodes)
    98  }