Skip to content

Commit

Permalink
Stopped competing thread
Browse files Browse the repository at this point in the history
  • Loading branch information
factom-clay authored and carryforward committed Oct 8, 2018
1 parent 3a9d32f commit 637f2e8
Show file tree
Hide file tree
Showing 24 changed files with 50 additions and 51 deletions.
Expand Up @@ -16,7 +16,7 @@ func TestCheckDatabaseFromDBO(t *testing.T) {
}

func TestCheckDatabaseFromState(t *testing.T) {
state := testHelper.CreateAndPopulateTestState()
state := testHelper.CreateAndPopulateTestStateAndStartValidator()
CheckDatabase(state.DB.(interfaces.DBOverlay))
}

Expand Down
4 changes: 2 additions & 2 deletions common/messages/dbstate_test.go
Expand Up @@ -165,7 +165,7 @@ func TestMarshalUnmarshalDBStateMsg(t *testing.T) {
}

func TestSimpleDBStateMsgValidate(t *testing.T) {
state := testHelper.CreateAndPopulateTestState()
state := testHelper.CreateAndPopulateTestStateAndStartValidator()

msg := new(DBStateMsg)
if msg.Validate(state) >= 0 {
Expand All @@ -190,7 +190,7 @@ func TestSimpleDBStateMsgValidate(t *testing.T) {
}

func TestDBStateDataValidate(t *testing.T) {
state := testHelper.CreateAndPopulateTestState()
state := testHelper.CreateAndPopulateTestStateAndStartValidator()
msg := newDBStateMsg()

if v := msg.ValidateData(state); v != 1 {
Expand Down
4 changes: 2 additions & 2 deletions common/messages/electionMsgs/electionAdapter_test.go
Expand Up @@ -44,7 +44,7 @@ func TestElectionAuditOrder(t *testing.T) {
}

func TestSimpleSigning(t *testing.T) {
s := CreateAndPopulateTestState()
s := CreateAndPopulateTestStateAndStartValidator()
e := NewTestElection()
v1 := NewTestVolunteerMessage(e, 2, 0)
err := v1.Sign(s)
Expand All @@ -60,7 +60,7 @@ func TestSimpleSigning(t *testing.T) {

func TestElectionAdapterSimple(t *testing.T) {
e := NewTestElection()
e.State = CreateAndPopulateTestState()
e.State = CreateAndPopulateTestStateAndStartValidator()
e.State.SetIdentityChainID(primitives.NewZeroHash())

a := NewElectionAdapter(e, primitives.NewZeroHash())
Expand Down
Expand Up @@ -55,7 +55,7 @@ func NewController(feds, auds int) *Controller {
s.Online = true

c.feds[i] = &s
e.State = testHelper.CreateAndPopulateTestState()
e.State = testHelper.CreateAndPopulateTestStateAndStartValidator()
e.State.SetIdentityChainID(s.ChainID)
c.Elections[i] = e
}
Expand Down
2 changes: 1 addition & 1 deletion common/messages/electionMsgs/fedVoteLevelMsg_test.go
Expand Up @@ -17,7 +17,7 @@ import (
func TestMarshalUnmarshalFedVoteLevel(t *testing.T) {
messages.General = new(msgsupport.GeneralFactory)
primitives.General = messages.General
s := testHelper.CreateAndPopulateTestState()
s := testHelper.CreateAndPopulateTestStateAndStartValidator()

test := func(va *FedVoteLevelMsg, num string) {
vas, err := va.JSONString()
Expand Down
2 changes: 1 addition & 1 deletion common/messages/electionMsgs/fedVotePropose_test.go
Expand Up @@ -53,7 +53,7 @@ func TestMarshalUnmarshalFedVoteProposal(t *testing.T) {
}
}

s := testHelper.CreateAndPopulateTestState()
s := testHelper.CreateAndPopulateTestStateAndStartValidator()
// Have volunteer
for i := 0; i < 20; i++ {
p := NewFedProposalMsg(primitives.RandomHash(), *randomVol(s))
Expand Down
2 changes: 1 addition & 1 deletion common/messages/electionMsgs/fedVoteVolunteerMsg_test.go
Expand Up @@ -42,7 +42,7 @@ func TestUnmarshalFedVoteVolunteerDBSig(t *testing.T) {
vol := con.Volunteers[0]

var err error
s := testHelper.CreateAndPopulateTestState()
s := testHelper.CreateAndPopulateTestStateAndStartValidator()
for s.UpdateState() {
}
for s.Process() {
Expand Down
2 changes: 1 addition & 1 deletion common/messages/entryBlockResponse_test.go
Expand Up @@ -35,7 +35,7 @@ func TestUnmarshalNilEntryBlockResponse(t *testing.T) {

func TestNewEntryBlockResponse(t *testing.T) {

state := testHelper.CreateAndPopulateTestState()
state := testHelper.CreateAndPopulateTestStateAndStartValidator()
msg := NewEntryBlockResponse(state)
response := msg.String()
timestamp := fmt.Sprintf("%d", msg.GetTimestamp().GetTimeMilli())
Expand Down
2 changes: 1 addition & 1 deletion common/messages/heartbeat_test.go
Expand Up @@ -144,7 +144,7 @@ func newSignedHeartbeat() *Heartbeat {
}

func TestValidHeatbeat(t *testing.T) {
s := testHelper.CreateAndPopulateTestState()
s := testHelper.CreateAndPopulateTestStateAndStartValidator()
a := identity.RandomAuthority()

pkey := primitives.RandomPrivateKey()
Expand Down
4 changes: 2 additions & 2 deletions common/messages/revealEntry_test.go
Expand Up @@ -95,7 +95,7 @@ func newRevealEntry() *RevealEntryMsg {
}

func TestValidRevealMsg(t *testing.T) {
s := testHelper.CreateAndPopulateTestState()
s := testHelper.CreateAndPopulateTestStateAndStartValidator()

if v := testValid(1, 0, s); v != 0 {
t.Error("Should be 0, found ", v)
Expand Down Expand Up @@ -163,7 +163,7 @@ func newMaliciousRevealEntry() *RevealEntryMsg {
}

func TestRevealMaliciousFirstEntryReveal(t *testing.T) {
testState := testHelper.CreateAndPopulateTestState()
testState := testHelper.CreateAndPopulateTestStateAndStartValidator()

m := newMaliciousRevealEntry()
goodEntry := newSignedCommitChain()
Expand Down
6 changes: 3 additions & 3 deletions controlPanel/controlPanel_test.go
Expand Up @@ -65,7 +65,7 @@ func TestControlPanel(t *testing.T) {
if LongTest {
var i uint32
connections := make(chan interface{})
emptyState := CreateAndPopulateTestState()
emptyState := CreateAndPopulateTestStateAndStartValidator()

gitBuild := "Test Is Running"
go ServeControlPanel(emptyState.ControlPanelChannel, emptyState, connections, nil, gitBuild)
Expand All @@ -84,7 +84,7 @@ func TestControlPanel(t *testing.T) {

func TestDataDump(t *testing.T) {
AllConnections = NewConnectionsMap()
s := CreateAndPopulateTestState()
s := CreateAndPopulateTestStateAndStartValidator()
ds, err := state.DeepStateDisplayCopy(s)
if err != nil {
t.Error(err)
Expand All @@ -100,7 +100,7 @@ func TestDataDump(t *testing.T) {
func TestSearching(t *testing.T) {
var err error
InitTemplates()
s := CreateAndPopulateTestState()
s := CreateAndPopulateTestStateAndStartValidator()
StatePointer = s

c := new(SearchedStruct)
Expand Down
2 changes: 1 addition & 1 deletion database/securedb/encryptedMarshaler_test.go
Expand Up @@ -18,7 +18,7 @@ func TestEncryptedMarshaler(t *testing.T) {
var err error
var ems []*EncryptedMarshaler
var hashes []interfaces.BinaryMarshallable
s := testHelper.CreateAndPopulateTestState()
s := testHelper.CreateAndPopulateTestStateAndStartValidator()

key := primitives.RandomHash().Bytes()
// Test with IHash
Expand Down
14 changes: 7 additions & 7 deletions state/ack_test.go
Expand Up @@ -21,7 +21,7 @@ var _ interfaces.IMsg
var _ = NewProcessList

func TestIsStateFullySynced(t *testing.T) {
s1_good := CreateAndPopulateTestState()
s1_good := CreateAndPopulateTestStateAndStartValidator()
t.Log("IsStateFullySynced():", s1_good.IsStateFullySynced())
if !s1_good.IsStateFullySynced() {
t.Error("Test state is shown not to be fully synced")
Expand All @@ -37,7 +37,7 @@ func TestIsStateFullySynced(t *testing.T) {
}

func TestFetchECTransactionByHash(t *testing.T) {
s1 := CreateAndPopulateTestState()
s1 := CreateAndPopulateTestStateAndStartValidator()
blocks := CreateFullTestBlockSet()

for _, block := range blocks {
Expand Down Expand Up @@ -75,7 +75,7 @@ func TestFetchECTransactionByHash(t *testing.T) {
}

func TestFetchFactoidTransactionByHash(t *testing.T) {
s1 := CreateAndPopulateTestState()
s1 := CreateAndPopulateTestStateAndStartValidator()
blocks := CreateFullTestBlockSet()

for _, block := range blocks {
Expand Down Expand Up @@ -107,7 +107,7 @@ func TestFetchFactoidTransactionByHash(t *testing.T) {
}

func TestFetchPaidFor(t *testing.T) {
s1 := CreateAndPopulateTestState()
s1 := CreateAndPopulateTestStateAndStartValidator()
blocks := CreateFullTestBlockSet()

for _, block := range blocks {
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestFetchPaidFor(t *testing.T) {
}

func TestFetchEntryByHash(t *testing.T) {
s1 := CreateAndPopulateTestState()
s1 := CreateAndPopulateTestStateAndStartValidator()
blocks := CreateFullTestBlockSet()

for _, block := range blocks {
Expand Down Expand Up @@ -190,7 +190,7 @@ func TestFetchEntryByHash(t *testing.T) {

func TestUnknownAcks(t *testing.T) {
// All random unknown hashes
s := CreateAndPopulateTestState()
s := CreateAndPopulateTestStateAndStartValidator()
status, _, _, _ := s.GetEntryCommitAckByTXID(primitives.RandomHash())
if status != constants.AckStatusUnknown {
t.Error("Should be unknown")
Expand All @@ -214,7 +214,7 @@ func TestUnknownAcks(t *testing.T) {

func TestDblockConf(t *testing.T) {
// All random unknown hashes
s := CreateAndPopulateTestState()
s := CreateAndPopulateTestStateAndStartValidator()
commit := messages.NewCommitEntryMsg()
commit.CommitEntry = entryCreditBlock.NewCommitEntry()
commit.CommitEntry.Credits = 2
Expand Down
6 changes: 3 additions & 3 deletions state/factoidstate_test.go
Expand Up @@ -194,7 +194,7 @@ func TestGetMapHash(t *testing.T) {
}

func TestUpdateECTransactionWithNegativeBalance(t *testing.T) {
s := testHelper.CreateAndPopulateTestState()
s := testHelper.CreateAndPopulateTestStateAndStartValidator()
fs := s.FactoidState

add1, err := primitives.HexToHash("0000000000000000000000000000000000000000000000000000000000000001")
Expand Down Expand Up @@ -230,7 +230,7 @@ func TestUpdateECTransactionWithNegativeBalance(t *testing.T) {
t.Errorf("No error returned when it should be")
}

s = testHelper.CreateAndPopulateTestState()
s = testHelper.CreateAndPopulateTestStateAndStartValidator()
fs = s.FactoidState
s.PutE(true, add1.Fixed(), 10)

Expand Down Expand Up @@ -261,7 +261,7 @@ func TestUpdateECTransactionWithNegativeBalance(t *testing.T) {
}

func TestUpdateTransactionWithNegativeBalance(t *testing.T) {
s := testHelper.CreateAndPopulateTestState()
s := testHelper.CreateAndPopulateTestStateAndStartValidator()
fs := s.FactoidState

add1, err := primitives.HexToHash("0000000000000000000000000000000000000000000000000000000000000001")
Expand Down
2 changes: 1 addition & 1 deletion state/journal_test.go
Expand Up @@ -16,7 +16,7 @@ import (
// TODO - very incompleate journal test. needs to be expanded with different
// message types and more messages and bad messages and so on.
func TestJournal(t *testing.T) {
s := CreateAndPopulateTestState()
s := CreateAndPopulateTestStateAndStartValidator()
filename := "journaltest.log"
s.JournalFile = filename
_, err := os.Create(s.JournalFile)
Expand Down
4 changes: 2 additions & 2 deletions state/plugins_test.go
Expand Up @@ -11,7 +11,7 @@ import (
)

func TestSetAndGetUseTorrent(t *testing.T) {
state := testHelper.CreateAndPopulateTestState()
state := testHelper.CreateAndPopulateTestStateAndStartValidator()
if state.UsingTorrent() {
t.Error("State unexpectedly using torrents without having been set to true")
}
Expand All @@ -22,7 +22,7 @@ func TestSetAndGetUseTorrent(t *testing.T) {
}
}
func TestSetAndGetTorrentUploader(t *testing.T) {
state := testHelper.CreateAndPopulateTestState()
state := testHelper.CreateAndPopulateTestStateAndStartValidator()
if state.TorrentUploader() {
t.Error("State unexpectedly using TorrentUploader without having been set to true")
}
Expand Down
1 change: 0 additions & 1 deletion state/state.go
Expand Up @@ -2424,7 +2424,6 @@ func (s *State) CalculateTransactionRate() (totalTPS float64, instantTPS float64
s.transCnt = total // transactions accounted for
InstantTransactionPerSecond.Set(s.tps) // Prometheus
}

return tps, s.tps
}

Expand Down
2 changes: 1 addition & 1 deletion state/stateConsensus_test.go
Expand Up @@ -16,7 +16,7 @@ import (
var _ = NewProcessList

func TestIsHighestCommit(t *testing.T) {
s := testHelper.CreateAndPopulateTestState()
s := testHelper.CreateAndPopulateTestStateAndStartValidator()

commit := newCom()
eh := commit.CommitEntry.EntryHash
Expand Down
16 changes: 8 additions & 8 deletions state/state_test.go
Expand Up @@ -86,7 +86,7 @@ func TestDirBlockHead(t *testing.T) {
*/

func TestGetDirectoryBlockByHeight(t *testing.T) {
state := testHelper.CreateAndPopulateTestState()
state := testHelper.CreateAndPopulateTestStateAndStartValidator()
blocks := testHelper.CreateFullTestBlockSet()
for i, block := range blocks {
dBlock := state.GetDirectoryBlockByHeight(uint32(i))
Expand All @@ -102,7 +102,7 @@ func TestGetDirectoryBlockByHeight(t *testing.T) {
}

func TestLoadHoldingMap(t *testing.T) {
state := testHelper.CreateAndPopulateTestState()
state := testHelper.CreateAndPopulateTestStateAndStartValidator()

hque := state.LoadHoldingMap()
if len(hque) != len(state.HoldingMap) {
Expand All @@ -111,7 +111,7 @@ func TestLoadHoldingMap(t *testing.T) {
}

func TestLoadAcksMap(t *testing.T) {
state := testHelper.CreateAndPopulateTestState()
state := testHelper.CreateAndPopulateTestStateAndStartValidator()

hque := state.LoadAcksMap()
if len(hque) != len(state.HoldingMap) {
Expand All @@ -127,7 +127,7 @@ func TestCalculateTransactionRate(t *testing.T) {

s.FactoidTrans = 333
to2, i := s.CalculateTransactionRate()
fmt.Println(to2, i)
fmt.Println("tps", to2, i)
if to >= to2 {
t.Errorf("Rate should be higher than %f, found %f", to, to2)
}
Expand All @@ -138,7 +138,7 @@ func TestCalculateTransactionRate(t *testing.T) {
}

func TestClone(t *testing.T) {
s := testHelper.CreateAndPopulateTestState()
s := testHelper.CreateAndPopulateTestStateAndStartValidator()
s2i := s.Clone(1)
s2, ok := s2i.(*State)
if !ok {
Expand All @@ -159,7 +159,7 @@ func TestClone(t *testing.T) {
}

func TestLog(t *testing.T) {
s := testHelper.CreateAndPopulateTestState()
s := testHelper.CreateAndPopulateTestStateAndStartValidator()
buf := new(bytes.Buffer)
//s.Logger = log.New(buf, "debug", "unit_test")
log.SetOutput(buf)
Expand All @@ -186,7 +186,7 @@ func TestLog(t *testing.T) {
}

func TestSetKeys(t *testing.T) {
s := testHelper.CreateAndPopulateTestState()
s := testHelper.CreateAndPopulateTestStateAndStartValidator()
p, _ := primitives.NewPrivateKeyFromHex("0000000000000000000000000000000000000000000000000000000000000000")
s.SimSetNewKeys(p)

Expand All @@ -196,7 +196,7 @@ func TestSetKeys(t *testing.T) {
}

func TestPrintState(t *testing.T) {
s := testHelper.CreateAndPopulateTestState()
s := testHelper.CreateAndPopulateTestStateAndStartValidator()
PrintState(s)
}

Expand Down
8 changes: 4 additions & 4 deletions testHelper/testHelper.go
Expand Up @@ -40,24 +40,24 @@ func CreateEmptyTestState() *state.State {
return s
}

func CreateAndPopulateTestState() *state.State {
s := createAndPopulateTestState()
func CreateAndPopulateTestStateAndStartValidator() *state.State {
s := CreateAndPopulateTestState()
go s.ValidatorLoop()
time.Sleep(30 * time.Millisecond)

return s
}

func CreatePopulateAndExecuteTestState() *state.State {
s := createAndPopulateTestState()
s := CreateAndPopulateTestState()
ExecuteAllBlocksFromDatabases(s)
go s.ValidatorLoop()
time.Sleep(30 * time.Millisecond)

return s
}

func createAndPopulateTestState() *state.State {
func CreateAndPopulateTestState() *state.State {
s := new(state.State)
s.EFactory = new(electionMsgs.ElectionsFactory)
s.SetLeaderTimestamp(primitives.NewTimestampFromMilliseconds(0))
Expand Down
2 changes: 1 addition & 1 deletion testHelper/testHelper_test.go
Expand Up @@ -61,7 +61,7 @@ func Test(t *testing.T) {
}

func Test_DB_With_Ten_Blks(t *testing.T) {
state := CreateAndPopulateTestState()
state := CreateAndPopulateTestStateAndStartValidator()
t.Log("Highest Recorded Block: ", state.GetHighestSavedBlk())
}

Expand Down

0 comments on commit 637f2e8

Please sign in to comment.