prysm-pulse/beacon-chain/state/references_test.go

41 lines
1.2 KiB
Go
Raw Normal View History

Beacon State: Track field references (#4751) * track field references * gofmt, RLock * Merge refs/heads/master into randao-ref-tracking * Merge refs/heads/master into randao-ref-tracking * Merge refs/heads/master into randao-ref-tracking * Merge refs/heads/master into randao-ref-tracking * Merge refs/heads/master into randao-ref-tracking * Merge refs/heads/master into randao-ref-tracking * Merge refs/heads/master into randao-ref-tracking * cleanup comments * Merge branch 'randao-ref-tracking' of github.com:prysmaticlabs/prysm into randao-ref-tracking * Add a test for finalizer * Merge refs/heads/master into randao-ref-tracking * Merge refs/heads/master into randao-ref-tracking * maybe fix data race * maybe fix data race * temp comment out test file to find which one fails race test * its definitely something with the checkpoint state cache * its definitely something with the checkpoint state cache * its definitely something with the checkpoint state cache * Merge refs/heads/master into randao-ref-tracking * This should fix it * Merge branch 'randao-ref-tracking' of github.com:prysmaticlabs/prysm into randao-ref-tracking * gaz * Merge refs/heads/master into randao-ref-tracking * Merge refs/heads/master into randao-ref-tracking * turn off race detection, i dont understand why is broken * Merge branch 'randao-ref-tracking' of github.com:prysmaticlabs/prysm into randao-ref-tracking * feedback * @nisdas feedback * Revert "@nisdas feedback" This reverts commit 6129cf84e6b5ceb085ff8ed3d47b1c432cd05ca9. * Merge refs/heads/master into randao-ref-tracking
2020-02-06 04:07:23 +00:00
package state
import (
"runtime"
"testing"
p2ppb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
)
func TestStateReferenceSharing_Finalizer(t *testing.T) {
// This test showcases the logic on a the RandaoMixes field with the GC finalizer.
a, _ := InitializeFromProtoUnsafe(&p2ppb.BeaconState{RandaoMixes: [][]byte{[]byte("foo")}})
if a.sharedFieldReferences[randaoMixes].refs != 1 {
t.Error("Expected a single reference for Randao mixes")
}
func() {
Beacon State: Track field references (#4751) * track field references * gofmt, RLock * Merge refs/heads/master into randao-ref-tracking * Merge refs/heads/master into randao-ref-tracking * Merge refs/heads/master into randao-ref-tracking * Merge refs/heads/master into randao-ref-tracking * Merge refs/heads/master into randao-ref-tracking * Merge refs/heads/master into randao-ref-tracking * Merge refs/heads/master into randao-ref-tracking * cleanup comments * Merge branch 'randao-ref-tracking' of github.com:prysmaticlabs/prysm into randao-ref-tracking * Add a test for finalizer * Merge refs/heads/master into randao-ref-tracking * Merge refs/heads/master into randao-ref-tracking * maybe fix data race * maybe fix data race * temp comment out test file to find which one fails race test * its definitely something with the checkpoint state cache * its definitely something with the checkpoint state cache * its definitely something with the checkpoint state cache * Merge refs/heads/master into randao-ref-tracking * This should fix it * Merge branch 'randao-ref-tracking' of github.com:prysmaticlabs/prysm into randao-ref-tracking * gaz * Merge refs/heads/master into randao-ref-tracking * Merge refs/heads/master into randao-ref-tracking * turn off race detection, i dont understand why is broken * Merge branch 'randao-ref-tracking' of github.com:prysmaticlabs/prysm into randao-ref-tracking * feedback * @nisdas feedback * Revert "@nisdas feedback" This reverts commit 6129cf84e6b5ceb085ff8ed3d47b1c432cd05ca9. * Merge refs/heads/master into randao-ref-tracking
2020-02-06 04:07:23 +00:00
// Create object in a different scope for GC
b := a.Copy()
if a.sharedFieldReferences[randaoMixes].refs != 2 {
t.Error("Expected 2 references to randao mixes")
}
_ = b
}()
runtime.GC() // Should run finalizer on object b
if a.sharedFieldReferences[randaoMixes].refs != 1 {
t.Errorf("Expected 1 shared reference to randao mixes!")
}
b := a.Copy()
if b.sharedFieldReferences[randaoMixes].refs != 2 {
t.Error("Expected 2 shared references to randao mixes")
}
b.UpdateRandaoMixesAtIndex([]byte("bar"), 0)
if b.sharedFieldReferences[randaoMixes].refs != 1 || a.sharedFieldReferences[randaoMixes].refs != 1 {
t.Error("Expected 1 shared reference to randao mix for both a and b")
}
}