github.com/neatio-net/neatio@v1.7.3-0.20231114194659-f4d7a2226baa/neatptc/sync_test.go (about)

     1  package neatptc
     2  
     3  import (
     4  	"sync/atomic"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/neatio-net/neatio/neatptc/downloader"
     9  	"github.com/neatio-net/neatio/network/p2p"
    10  	"github.com/neatio-net/neatio/network/p2p/discover"
    11  )
    12  
    13  func TestFastSyncDisabling(t *testing.T) {
    14  
    15  	pmEmpty, _ := newTestProtocolManagerMust(t, downloader.FastSync, 0, nil, nil)
    16  	if atomic.LoadUint32(&pmEmpty.fastSync) == 0 {
    17  		t.Fatalf("fast sync disabled on pristine blockchain")
    18  	}
    19  
    20  	pmFull, _ := newTestProtocolManagerMust(t, downloader.FastSync, 1024, nil, nil)
    21  	if atomic.LoadUint32(&pmFull.fastSync) == 1 {
    22  		t.Fatalf("fast sync not disabled on non-empty blockchain")
    23  	}
    24  
    25  	io1, io2 := p2p.MsgPipe()
    26  
    27  	go pmFull.handle(pmFull.newPeer(63, p2p.NewPeer(discover.NodeID{}, "empty", nil), io2))
    28  	go pmEmpty.handle(pmEmpty.newPeer(63, p2p.NewPeer(discover.NodeID{}, "full", nil), io1))
    29  
    30  	time.Sleep(250 * time.Millisecond)
    31  	pmEmpty.synchronise(pmEmpty.peers.BestPeer())
    32  
    33  	if atomic.LoadUint32(&pmEmpty.fastSync) == 1 {
    34  		t.Fatalf("fast sync not disabled after successful synchronisation")
    35  	}
    36  }