mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 21:38:05 -05:00
* save progress * tidy * Update go.yml * make CI happy * gosec * revert back * Update go.yml * change go version * remove fixed test case * fix ci * fix updates * fix up * fix race tests * fix bad mock * lock it * fix it * fix e2e builds * use gotags * Revert "use gotags" This reverts commit808863f427. * Revert "fix e2e builds" This reverts commiteb351e7d31. * Revert "fix it" This reverts commit9e99dac94f. * Revert "lock it" This reverts commit1a3c60ad41. * different approach * better Co-authored-by: james-prysm <90280386+james-prysm@users.noreply.github.com>
54 lines
1.5 KiB
Go
54 lines
1.5 KiB
Go
package params_test
|
|
|
|
import (
|
|
"sync"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/config/params"
|
|
)
|
|
|
|
// Test cases can be executed in an arbitrary order. TestOverrideBeaconConfigTestTeardown checks
|
|
// that there's no state mutation leak from the previous test, therefore we need a sentinel flag,
|
|
// to make sure that previous test case has already been completed and check can be run.
|
|
var testOverrideBeaconConfigExecuted bool
|
|
|
|
func TestConfig_OverrideBeaconConfig(t *testing.T) {
|
|
// Ensure that param modifications are safe.
|
|
params.SetupTestConfigCleanup(t)
|
|
cfg := params.BeaconConfig()
|
|
cfg.SlotsPerEpoch = 5
|
|
params.OverrideBeaconConfig(cfg)
|
|
if c := params.BeaconConfig(); c.SlotsPerEpoch != 5 {
|
|
t.Errorf("Shardcount in BeaconConfig incorrect. Wanted %d, got %d", 5, c.SlotsPerEpoch)
|
|
}
|
|
testOverrideBeaconConfigExecuted = true
|
|
}
|
|
|
|
func TestConfig_OverrideBeaconConfigTestTeardown(t *testing.T) {
|
|
if !testOverrideBeaconConfigExecuted {
|
|
t.Skip("State leak can occur only if state mutating test has already completed")
|
|
}
|
|
cfg := params.BeaconConfig()
|
|
if cfg.SlotsPerEpoch == 5 {
|
|
t.Fatal("Parameter update has been leaked out of previous test")
|
|
}
|
|
}
|
|
|
|
func TestConfig_DataRace(t *testing.T) {
|
|
params.SetupTestConfigCleanup(t)
|
|
wg := new(sync.WaitGroup)
|
|
for i := 0; i < 10; i++ {
|
|
wg.Add(2)
|
|
go func() {
|
|
defer wg.Done()
|
|
cfg := params.BeaconConfig()
|
|
params.OverrideBeaconConfig(cfg)
|
|
}()
|
|
go func() uint64 {
|
|
defer wg.Done()
|
|
return params.BeaconConfig().MaxDeposits
|
|
}()
|
|
}
|
|
wg.Wait()
|
|
}
|