github.com/prysmaticlabs/prysm@v1.4.4/beacon-chain/blockchain/chain_info_norace_test.go (about) 1 package blockchain 2 3 import ( 4 "context" 5 "testing" 6 7 testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" 8 "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" 9 ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1" 10 "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1/wrapper" 11 "github.com/prysmaticlabs/prysm/shared/testutil/require" 12 ) 13 14 func TestHeadSlot_DataRace(t *testing.T) { 15 beaconDB := testDB.SetupDB(t) 16 s := &Service{ 17 cfg: &Config{BeaconDB: beaconDB}, 18 } 19 go func() { 20 require.NoError(t, s.saveHead(context.Background(), [32]byte{})) 21 }() 22 s.HeadSlot() 23 } 24 25 func TestHeadRoot_DataRace(t *testing.T) { 26 beaconDB := testDB.SetupDB(t) 27 s := &Service{ 28 cfg: &Config{BeaconDB: beaconDB, StateGen: stategen.New(beaconDB)}, 29 head: &head{root: [32]byte{'A'}}, 30 } 31 go func() { 32 require.NoError(t, s.saveHead(context.Background(), [32]byte{})) 33 }() 34 _, err := s.HeadRoot(context.Background()) 35 require.NoError(t, err) 36 } 37 38 func TestHeadBlock_DataRace(t *testing.T) { 39 beaconDB := testDB.SetupDB(t) 40 s := &Service{ 41 cfg: &Config{BeaconDB: beaconDB, StateGen: stategen.New(beaconDB)}, 42 head: &head{block: wrapper.WrappedPhase0SignedBeaconBlock(ðpb.SignedBeaconBlock{})}, 43 } 44 go func() { 45 require.NoError(t, s.saveHead(context.Background(), [32]byte{})) 46 }() 47 _, err := s.HeadBlock(context.Background()) 48 require.NoError(t, err) 49 } 50 51 func TestHeadState_DataRace(t *testing.T) { 52 beaconDB := testDB.SetupDB(t) 53 s := &Service{ 54 cfg: &Config{BeaconDB: beaconDB, StateGen: stategen.New(beaconDB)}, 55 } 56 go func() { 57 require.NoError(t, s.saveHead(context.Background(), [32]byte{})) 58 }() 59 _, err := s.HeadState(context.Background()) 60 require.NoError(t, err) 61 }