Skip to content

Commit

Permalink
Merge pull request #258 from FactomProject/FD-120
Browse files Browse the repository at this point in the history
Fd 120
  • Loading branch information
carryforward committed May 25, 2017
2 parents 554a409 + a0f790a commit 0087658
Show file tree
Hide file tree
Showing 26 changed files with 1,352 additions and 161 deletions.
43 changes: 12 additions & 31 deletions controlPanel/controlPanel.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,23 +583,19 @@ func getRecentTransactions(time.Time) {
if fTrans.TotalInputs == 0 {
continue
}
has := false
for _, trans := range RecentTransactions.FactoidTransactions {
if fTrans.TxID == trans.TxID {
has = true
break
txhash, err := primitives.HexToHash(fTrans.TxID)
if err == nil {
if !RecentTransactions.ContainsTrans(txhash) {
RecentTransactions.FactoidTransactions = append(RecentTransactions.FactoidTransactions, struct {
TxID string
Hash string
TotalInput string
Status string
TotalInputs int
TotalOutputs int
}{fTrans.TxID, fTrans.Hash, fTrans.TotalInput, "Processing", fTrans.TotalInputs, fTrans.TotalOutputs})
}
}
if !has {
RecentTransactions.FactoidTransactions = append(RecentTransactions.FactoidTransactions, struct {
TxID string
Hash string
TotalInput string
Status string
TotalInputs int
TotalOutputs int
}{fTrans.TxID, fTrans.Hash, fTrans.TotalInput, "Processing", fTrans.TotalInputs, fTrans.TotalOutputs})
}
}
DisplayStateMutex.RUnlock()

Expand All @@ -626,22 +622,7 @@ func getRecentTransactions(time.Time) {
totalOutputs := len(trans.GetECOutputs())
totalOutputs = totalOutputs + len(trans.GetOutputs())
inputStr := fmt.Sprintf("%f", float64(input)/1e8)
has := false
for i, fact := range RecentTransactions.FactoidTransactions {
if fact.TxID == trans.GetHash().String() {
RecentTransactions.FactoidTransactions[i] = struct {
TxID string
Hash string
TotalInput string
Status string
TotalInputs int
TotalOutputs int
}{trans.GetSigHash().String(), trans.GetHash().String(), inputStr, "Confirmed", totalInputs, totalOutputs}
has = true
break
}
}
if !has {
if !RecentTransactions.ContainsTrans(trans.GetHash()) {
RecentTransactions.FactoidTransactions = append(RecentTransactions.FactoidTransactions, struct {
TxID string
Hash string
Expand Down
39 changes: 39 additions & 0 deletions controlPanel/controlPanel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
. "github.com/FactomProject/factomd/controlPanel"
"github.com/FactomProject/factomd/p2p"
//"github.com/FactomProject/factomd/state"
"github.com/FactomProject/factomd/common/primitives"
//"github.com/FactomProject/factomd/common/primitives/random"
. "github.com/FactomProject/factomd/testHelper"
)

Expand All @@ -16,6 +18,43 @@ var _ = fmt.Sprintf("")
// Enable for long test
var LongTest bool = false

func TestFactoidHas(t *testing.T) {
rc := new(LastDirectoryBlockTransactions)
rc.FactoidTransactions = append(rc.FactoidTransactions)
for i := 0; i < 10; i++ {
addTrans(rc)
}

for i := 0; i < len(rc.FactoidTransactions); i++ {
h, _ := primitives.HexToHash(rc.FactoidTransactions[i].TxID)
if !rc.ContainsTrans(h) {
t.Error("This should be true")
}
}

for i := 0; i < len(rc.Entries); i++ {
h, _ := primitives.HexToHash(rc.Entries[i].Hash)
if !rc.ContainsEntry(h) {
t.Error("This should be true")
}
}
}

func addTrans(rc *LastDirectoryBlockTransactions) {
rc.FactoidTransactions = append(rc.FactoidTransactions, struct {
TxID string
Hash string
TotalInput string
Status string
TotalInputs int
TotalOutputs int
}{primitives.RandomHash().String(), primitives.RandomHash().String(), "1", "Confirmed", 1, 1})

e := new(EntryHolder)
e.Hash = primitives.RandomHash().String()
rc.Entries = append(rc.Entries, *e)
}

func TestControlPanel(t *testing.T) {
if LongTest {
var i uint32
Expand Down
11 changes: 11 additions & 0 deletions engine/NetStart.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ func NetStart(s *state.State) {
fastPtr := flag.Bool("fast", true, "If true, factomd will fast-boot from a file.")
fastLocationPtr := flag.String("fastlocation", "", "Directory to put the fast-boot file in.")
memProfileRate := flag.Int("mpr", 512*1024, "Set the Memory Profile Rate to update profiling per X bytes allocated. Default 512K, set to 1 to profile everything, 0 to disable.")
logLvlPtr := flag.String("loglvl", "none", "Set log level to either: debug, info, notice, warning, error, critical, alert, emergency or none")
logSTDOutPtr := flag.Bool("logstdout", false, "Use to set logging to stdout")

flag.Parse()

Expand Down Expand Up @@ -122,6 +124,8 @@ func NetStart(s *state.State) {
factomdTLS := *factomdTLSflag
factomdLocations := *factomdLocationsflag
fast := *fastPtr
logLvl := *logLvlPtr
logSTDOut := *logSTDOutPtr

messages.AckBalanceHash = ackbalanceHash
// Must add the prefix before loading the configuration.
Expand All @@ -133,6 +137,11 @@ func NetStart(s *state.State) {
s.TimeOffset = primitives.NewTimestampFromMilliseconds(uint64(timeOffset))
s.StartDelayLimit = startDelay * 1000
s.Journaling = journaling
s.LogLevel = logLvl

if logSTDOut {
s.LogPath = "stdout"
}

// Set the wait for entries flag
s.WaitForEntries = waitEntries
Expand Down Expand Up @@ -368,6 +377,8 @@ func NetStart(s *state.State) {
SeedURL: seedURL,
SpecialPeers: specialPeers,
ConnectionMetricsChannel: connectionMetricsChannel,
LogPath: s.LogPath,
LogLevel: s.LogLevel,
}
p2pNetwork = new(p2p.Controller).Init(ci)
fnodes[0].State.NetworkControler = p2pNetwork
Expand Down
174 changes: 174 additions & 0 deletions log/log_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
package log_test

import (
"bytes"
"fmt"
"testing"

. "github.com/FactomProject/factomd/log"
)

var _ = fmt.Println

func TestLog(t *testing.T) {
}

func TestBadNew(t *testing.T) {
l := New(nil, "not_allowed", "testing")
if l.Level() != WarningLvl {
t.Error("Should be set to warning")
}
}

func TestNew(t *testing.T) {
buf := new(bytes.Buffer)

floggers := make([]*FLogger, 0)
lDebug := New(buf, "debug", "testing")
linfo := New(buf, "info", "testing")
lnotice := New(buf, "notice", "testing")
lwarning := New(buf, "warning", "testing")
lerror := New(buf, "error", "testing")
lcritical := New(buf, "critical", "testing")
lalert := New(buf, "alert", "testing")
lemergency := New(buf, "emergency", "testing")
lnone := New(buf, "none", "testing")

floggers = append(floggers, lDebug)
floggers = append(floggers, linfo)
floggers = append(floggers, lnotice)
floggers = append(floggers, lwarning)
floggers = append(floggers, lerror)
floggers = append(floggers, lcritical)
floggers = append(floggers, lalert)
floggers = append(floggers, lemergency)
floggers = append(floggers, lnone)

for _, f := range floggers {
if !check(f, buf, DebugLvl) {
t.Error("Debug level not working")
}
if !check(f, buf, InfoLvl) {
t.Error("Info level not working")
}
if !check(f, buf, NoticeLvl) {
t.Error("Notice level not working")
}
if !check(f, buf, WarningLvl) {
t.Error("Warning level not working")
}
if !check(f, buf, ErrorLvl) {
t.Error("Error level not working")
}
}
}

func check(f *FLogger, out *bytes.Buffer, lvl Level) bool {
if !checkLevel(f, out, lvl) {
return false
}
if !checkLevelf(f, out, lvl) {
return false
}
return true
}

func checkLevel(f *FLogger, out *bytes.Buffer, lvl Level) bool {
pre := out.Len()

switch lvl {
case DebugLvl:
f.Debug("Test")
case InfoLvl:
f.Info("Test")
case NoticeLvl:
f.Notice("Test")
case WarningLvl:
f.Warning("Test")
case ErrorLvl:
f.Error("Test")
case CriticalLvl:
case AlertLvl:
case EmergencyLvl:
}

post := out.Len()
if f.Level() == None {
if pre != post {
return false
}
}

if f.Level() >= lvl {
if post <= pre {
return false
}
} else {
if post > pre {
return false
}
}
return true
}

func checkLevelf(f *FLogger, out *bytes.Buffer, lvl Level) bool {
pre := out.Len()

switch lvl {
case DebugLvl:
f.Debugf("Test")
case InfoLvl:
f.Infof("Test")
case NoticeLvl:
f.Noticef("Test")
case WarningLvl:
f.Warningf("Test")
case ErrorLvl:
f.Errorf("Test")
case CriticalLvl:
case AlertLvl:
case EmergencyLvl:
}

post := out.Len()
if f.Level() == None {
if pre != post {
return false
}
}

if f.Level() >= lvl {
if post <= pre {
return false
}
} else {
if post > pre {
return false
}
}
return true
}

func BenchmarkZeroFormat(b *testing.B) {
buf := new(bytes.Buffer)
l := New(buf, "debug", "testing")
doBenchmark(b, l, "zero")
}

func BenchmarkSingleFormat(b *testing.B) {
buf := new(bytes.Buffer)
l := New(buf, "debug", "testing")
doBenchmark(b, l, "%s", "single")
}

func BenchmarkDoubleFormat(b *testing.B) {
buf := new(bytes.Buffer)
l := New(buf, "debug", "testing")
doBenchmark(b, l, "%s, %s", "single", "double")
}

func doBenchmark(b *testing.B, logger *FLogger, format string, args ...interface{}) {
for i := 0; i < b.N; i++ {
logger.Debugf(format, args)
}
}

0 comments on commit 0087658

Please sign in to comment.