Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Nowax] Reset FNodes between unit tests #1108

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions engine/NetStart.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,3 +720,8 @@ func AddNode() {
AddSimPeer(fnodes, i, i-1) // KLUDGE peer w/ only last node
startServer(i, fnodes[i], true)
}

// ResetFNodes clears the fnode slice for unit tests
func ResetFNodes() {
fnodes = nil
}
2 changes: 1 addition & 1 deletion simTest/EntriesBeforeChain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func TestEntriesBeforeChain(t *testing.T) {

ResetSimHome(t)
encode := func(s string) []byte {
b := bytes.Buffer{}
b.WriteString(s)
Expand Down
2 changes: 1 addition & 1 deletion simTest/EntryBatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

// this applies chain & entry creation in 'proper' chronological order
func TestEntryBatch(t *testing.T) {

ResetSimHome(t)
encode := func(s string) []byte {
b := bytes.Buffer{}
b.WriteString(s)
Expand Down
1 change: 1 addition & 0 deletions simTest/HoldingRebound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
)

func TestHoldingRebound(t *testing.T) {
ResetSimHome(t)
encode := func(s string) []byte {
b := bytes.Buffer{}
b.WriteString(s)
Expand Down
2 changes: 1 addition & 1 deletion simTest/MessageFilteringInput_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func TestFilterAPIInput(t *testing.T) {

ResetSimHome(t)
state0 := SetupSim("LLLAF", map[string]string{}, 25, 1, 1, t)

RunCmd("1")
Expand Down
2 changes: 1 addition & 1 deletion simTest/MessageFilteringOutput_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func TestFilterAPIOutput(t *testing.T) {

ResetSimHome(t)
state0 := SetupSim("LLLLLAAF", map[string]string{}, 25, 1, 1, t)

RunCmd("1")
Expand Down
1 change: 1 addition & 0 deletions simTest/PermFCTBalancesAfterMin9Election_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func createDepositAddresses() {
}

func TestPermFCTBalancesAfterMin9Election(t *testing.T) {
ResetSimHome(t)
createDepositAddresses()
state0 := SetupSim("LLAL", map[string]string{"--debuglog": "", "--faulttimeout": "10"}, 10, 1, 1, t)

Expand Down
5 changes: 2 additions & 3 deletions simTest/SetupANetwork_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package simtest

import "time"

import (
"testing"
"time"

. "github.com/FactomProject/factomd/engine"
. "github.com/FactomProject/factomd/testHelper"
)

func TestSetupANetwork(t *testing.T) {

ResetSimHome(t)
state0 := SetupSim("LLLLAAAFFF", map[string]string{"--debuglog": ""}, 20, 0, 0, t)

RunCmd("9") // Puts the focus on node 9
Expand Down
2 changes: 1 addition & 1 deletion simTest/SimWallet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func TestSimWallet(t *testing.T) {

ResetSimHome(t)
a := AccountFromFctSecret("Fs31kMMKBSCDwa7tSEzjQ4EfGeXARdUS22oBEJKNSJWbLAMTsEHr")
b := AccountFromFctSecret("Fs2BNvoDgSoGJpWg4PvRUxqvLE28CQexp5FZM9X5qU6QvzFBUn6D")

Expand Down
28 changes: 28 additions & 0 deletions simTest/factomd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func TestOne(t *testing.T) {
return
}
state.MMR_enable = false // No MMR for you!
ResetSimHome(t)

RanSimTest = true

Expand All @@ -53,6 +54,7 @@ func TestDualElections(t *testing.T) {
state.MMR_enable = false // No MMR for you!

RanSimTest = true
ResetSimHome(t)

// 01234567
state0 := SetupSim("LALLLALFFLLFFFF", map[string]string{"--debuglog": ".", "--blktime": "20"}, 12, 0, 0, t)
Expand All @@ -78,6 +80,7 @@ func TestLoad(t *testing.T) {
}

RanSimTest = true
ResetSimHome(t)

// use a tree so the messages get reordered
state0 := SetupSim("LLLLFFFF", map[string]string{"--debuglog": ".", "--blktime": "30"}, 15, 0, 0, t)
Expand All @@ -101,6 +104,7 @@ func TestErr(t *testing.T) {
}

RanSimTest = true
ResetSimHome(t)
state0 := SetupSim("LF", map[string]string{"--debuglog": ".", "--db": "LDB", "--controlpanelsetting": "readwrite",
"--network": "LOCAL", "--fastsaverate": "4", "--checkheads": "false", "--net": "alot",
"--blktime": "15", "--faulttimeout": "120000", "--enablenet": "false", "--startdelay": "1"},
Expand All @@ -122,6 +126,7 @@ func TestCatchup(t *testing.T) {
}

RanSimTest = true
ResetSimHome(t)

// use a tree so the messages get reordered
state0 := SetupSim("LF", map[string]string{}, 15, 0, 0, t)
Expand Down Expand Up @@ -153,6 +158,7 @@ func TestTXTimestampsAndBlocks(t *testing.T) {
return
}
RanSimTest = true
ResetSimHome(t)

go RunCmd("Re") // Turn on tight allocation of EC as soon as the simulator is up and running
state0 := SetupSim("LLLAAAFFF", map[string]string{}, 24, 0, 0, t)
Expand All @@ -173,6 +179,7 @@ func TestLoad2(t *testing.T) {
return
}
RanSimTest = true
ResetSimHome(t)

// use tree node setup so messages get reordered
go RunCmd("Re") // Turn on tight allocation of EC as soon as the simulator is up and running
Expand Down Expand Up @@ -219,6 +226,7 @@ func TestLoadScrambled(t *testing.T) {
}()

RanSimTest = true
ResetSimHome(t)

// use a tree so the messages get reordered
state0 := SetupSim("LLFFFFFF", map[string]string{"--net": "tree"}, 32, 0, 0, t)
Expand All @@ -241,6 +249,7 @@ func TestMinute9Election(t *testing.T) {
return
}
RanSimTest = true
ResetSimHome(t)

// use a tree so the messages get reordered
state0 := SetupSim("LLAL", map[string]string{"--net": "line"}, 10, 1, 1, t)
Expand All @@ -264,6 +273,7 @@ func TestMakeALeader(t *testing.T) {
}

RanSimTest = true
ResetSimHome(t)

state0 := SetupSim("LF", map[string]string{}, 5, 0, 0, t)
RunCmd("g1")
Expand Down Expand Up @@ -371,6 +381,7 @@ func TestAnElection(t *testing.T) {
}

RanSimTest = true
ResetSimHome(t)

state0 := SetupSim("LLLAAF", map[string]string{"--blktime": "15"}, 9, 1, 1, t)

Expand All @@ -386,6 +397,7 @@ func TestAnElection(t *testing.T) {
// wait for the election
WaitMinutes(state0, 2)
//bring him back
RunCmd("2")
RunCmd("x")

// wait for him to update via dbstate and become an audit
Expand All @@ -412,6 +424,7 @@ func TestDBsigEOMElection(t *testing.T) {
}

RanSimTest = true
ResetSimHome(t)

state0 := SetupSim("LLLLLAAF", map[string]string{}, 9, 4, 4, t)

Expand Down Expand Up @@ -474,6 +487,7 @@ func TestMultiple2Election(t *testing.T) {
}

RanSimTest = true
ResetSimHome(t)

state0 := SetupSim("LLLLLAAF", map[string]string{}, 7, 2, 2, t)

Expand Down Expand Up @@ -502,6 +516,7 @@ func TestMultiple3Election(t *testing.T) {
}

RanSimTest = true
ResetSimHome(t)

state0 := SetupSim("LLLLLLLAAAAF", map[string]string{}, 9, 3, 3, t)

Expand Down Expand Up @@ -532,6 +547,7 @@ func TestSimCtrl(t *testing.T) {
return
}
RanSimTest = true
ResetSimHome(t)

type walletcallHelper struct {
Status string `json:"status"`
Expand Down Expand Up @@ -598,6 +614,7 @@ func TestMultipleFTAccountsAPI(t *testing.T) {
return
}
RanSimTest = true
ResetSimHome(t)
// only have one leader because if you are not the leader responcible for the FCT transaction then
// you will return transACK before teh balance is updated which will make thsi test fail.
state0 := SetupSim("LAF", map[string]string{}, 6, 0, 0, t)
Expand Down Expand Up @@ -789,6 +806,7 @@ func TestMultipleECAccountsAPI(t *testing.T) {
return
}
RanSimTest = true
ResetSimHome(t)

// only have one leader because if you are not the leader responcible for the FCT transaction then
// you will return transACK before teh balance is updated which will make thsi test fail.
Expand Down Expand Up @@ -995,6 +1013,7 @@ func TestDBSigElection(t *testing.T) {
return
}
RanSimTest = true
ResetSimHome(t)

state0 := SetupSim("LLLAF", map[string]string{"--faulttimeout": "10"}, 8, 1, 1, t)

Expand Down Expand Up @@ -1025,6 +1044,7 @@ func TestCoinbaseCancel(t *testing.T) {
return
}
RanSimTest = true
ResetSimHome(t)

state0 := SetupSim("LFFFFF", map[string]string{"-blktime": "5"}, 30, 0, 0, t)
// Make it quicker
Expand Down Expand Up @@ -1164,6 +1184,7 @@ func TestElection9(t *testing.T) {
return
}
RanSimTest = true
ResetSimHome(t)

state0 := SetupSim("LLAL", map[string]string{"--debuglog": "", "--faulttimeout": "10"}, 8, 1, 1, t)
StatusEveryMinute(state0)
Expand Down Expand Up @@ -1195,6 +1216,7 @@ func TestBadDBStateUnderflow(t *testing.T) {
}

RanSimTest = true
ResetSimHome(t)
state0 := SetupSim("LF", map[string]string{}, 6, 0, 0, t)
RunCmd("g1")
WaitBlocks(state0, 2)
Expand Down Expand Up @@ -1229,6 +1251,7 @@ func TestFactoidDBState(t *testing.T) {
return
}
RanSimTest = true
ResetSimHome(t)

state0 := SetupSim("LAF", map[string]string{"--faulttimeout": "10", "--blktime": "5"}, 120, 0, 0, t)
WaitBlocks(state0, 1)
Expand Down Expand Up @@ -1257,6 +1280,7 @@ func TestNoMMR(t *testing.T) {
return
}
RanSimTest = true
ResetSimHome(t)

state0 := SetupSim("LLLAAFFFFF", map[string]string{}, 10, 0, 0, t)
state.MMR_enable = false // turn off MMR processing
Expand All @@ -1273,6 +1297,7 @@ func TestDBStateCatchup(t *testing.T) {
return
}
RanSimTest = true
ResetSimHome(t)

state0 := SetupSim("LFF", map[string]string{}, 100, 0, 0, t)
state.MMR_enable = false // turn off MMR processing
Expand Down Expand Up @@ -1302,6 +1327,7 @@ func TestDBState(t *testing.T) {
return
}
RanSimTest = true
ResetSimHome(t)

state0 := SetupSim("LLLFFFF", map[string]string{"--net": "line"}, 100, 0, 0, t)
state1 := GetFnodes()[1].State
Expand Down Expand Up @@ -1333,6 +1359,7 @@ func TestCatchupEveryMinute(t *testing.T) {
}

RanSimTest = true
ResetSimHome(t)
// 01234567890
state0 := SetupSim("LFFFFFFFFFF", map[string]string{"--debuglog": ".", "--blktime": "6"}, 20, 1, 1, t)

Expand Down Expand Up @@ -1369,6 +1396,7 @@ func TestDebugLocation(t *testing.T) {
return
}
RanSimTest = true
ResetSimHome(t)

tempdir := os.TempDir() + string(os.PathSeparator) + "logs" + string(os.PathSeparator) // get os agnostic path to the temp directory

Expand Down
12 changes: 8 additions & 4 deletions testHelper/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (
"github.com/stretchr/testify/assert"
)

var par = globals.FactomParams{}

var quit = make(chan struct{})
var ExpectedHeight, Leaders, Audits, Followers int
var startTime, endTime time.Time
Expand Down Expand Up @@ -133,6 +131,7 @@ func StartPeer(CmdLineOptions map[string]string) *state.State {
// this is useful for creating scripts that will start/stop a simulation outside of the context of a unit test
// this allows for consistent tweaking of a simulation to induce load add message loss or adjust timing
func StartSim(nodeCount int, UserAddedOptions map[string]string) *state.State {
quit = make(chan struct{})
UserAddedOptions["--count"] = fmt.Sprintf("%v", nodeCount)
params := optionsToParams(UserAddedOptions)
return engine.Factomd(params, false).(*state.State)
Expand Down Expand Up @@ -618,11 +617,16 @@ func GetLongTestHome(t *testing.T) string {
// remove files from a home dir and remake .factom config dir
func ResetTestHome(homeDir string, t *testing.T) {
t.Logf("Removing old test run in %s", homeDir)
os.RemoveAll(homeDir)
os.MkdirAll(homeDir+"/.factom/m2", 0755)
if err := os.RemoveAll(homeDir); err != nil {
t.Fatal(err)
}
if err := os.MkdirAll(homeDir+"/.factom/m2", 0755); err != nil {
t.Fatal(err)
}
}

func ResetSimHome(t *testing.T) string {
engine.ResetFNodes()
h := GetSimTestHome(t)
ResetTestHome(h, t)
return h
Expand Down