本文整理汇总了Golang中github.com/dedis/cothority/log.TestOutput函数的典型用法代码示例。如果您正苦于以下问题:Golang TestOutput函数的具体用法?Golang TestOutput怎么用?Golang TestOutput使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TestOutput函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestCloseall
// Tests a 2-node system
func TestCloseall(t *testing.T) {
defer log.AfterTest(t)
log.TestOutput(testing.Verbose(), 4)
local := sda.NewLocalTest()
nbrNodes := 2
_, _, tree := local.GenTree(nbrNodes, false, true, true)
defer local.CloseAll()
pi, err := local.CreateProtocol(tree, "ExampleChannels")
if err != nil {
t.Fatal("Couldn't start protocol:", err)
}
go pi.Start()
protocol := pi.(*channels.ProtocolExampleChannels)
timeout := network.WaitRetry * time.Duration(network.MaxRetry*nbrNodes*2) * time.Millisecond
select {
case children := <-protocol.ChildCount:
log.Lvl2("Instance 1 is done")
if children != nbrNodes {
t.Fatal("Didn't get a child-cound of", nbrNodes)
}
case <-time.After(timeout):
t.Fatal("Didn't finish in time")
}
}
示例2: TestReadyNormal
func TestReadyNormal(t *testing.T) {
defer log.AfterTest(t)
log.TestOutput(testing.Verbose(), 3)
m := make(map[string]string)
m["servers"] = "1"
stat := NewStats(m)
fresh := stat.String()
// First set up monitor listening
mon := NewMonitor(stat)
go mon.Listen()
time.Sleep(100 * time.Millisecond)
// Then measure
err := ConnectSink("localhost:" + strconv.Itoa(DefaultSinkPort))
if err != nil {
t.Fatal(fmt.Sprintf("Error starting monitor: %s", err))
return
}
meas := NewSingleMeasure("round", 10)
meas.Record()
time.Sleep(200 * time.Millisecond)
NewSingleMeasure("round", 20)
EndAndCleanup()
time.Sleep(100 * time.Millisecond)
updated := mon.Stats().String()
if updated == fresh {
t.Fatal("Stats not updated ?")
}
}
示例3: TestBroadcast
// Tests a 2-node system
func TestBroadcast(t *testing.T) {
defer log.AfterTest(t)
log.TestOutput(testing.Verbose(), 3)
for _, nbrNodes := range []int{3, 10, 14} {
local := sda.NewLocalTest()
_, _, tree := local.GenTree(nbrNodes, false, true, true)
pi, err := local.CreateProtocol(tree, "Broadcast")
if err != nil {
t.Fatal("Couldn't start protocol:", err)
}
protocol := pi.(*manage.Broadcast)
done := make(chan bool)
protocol.RegisterOnDone(func() {
done <- true
})
protocol.Start()
timeout := network.WaitRetry * time.Duration(network.MaxRetry*nbrNodes*2) * time.Millisecond
select {
case <-done:
log.Lvl2("Done with connecting everybody")
case <-time.After(timeout):
t.Fatal("Didn't finish in time")
}
local.CloseAll()
}
}
示例4: TestKeyOrder
func TestKeyOrder(t *testing.T) {
defer log.AfterTest(t)
log.TestOutput(testing.Verbose(), 3)
m := make(map[string]string)
m["servers"] = "1"
m["hosts"] = "1"
m["bf"] = "2"
// create stats
stat := NewStats(m)
m1 := NewSingleMeasure("round", 10)
m2 := NewSingleMeasure("setup", 5)
stat.Update(m1)
stat.Update(m2)
str := new(bytes.Buffer)
stat.WriteHeader(str)
stat.WriteValues(str)
stat2 := NewStats(m)
stat2.Update(m1)
stat2.Update(m2)
str2 := new(bytes.Buffer)
stat2.WriteHeader(str2)
stat2.WriteValues(str2)
if !bytes.Equal(str.Bytes(), str2.Bytes()) {
t.Fatal("KeyOrder / output not the same for same stats")
}
}
示例5: TestStatsAverage
func TestStatsAverage(t *testing.T) {
log.TestOutput(testing.Verbose(), 3)
m := make(map[string]string)
m["servers"] = "1"
m["hosts"] = "1"
m["bf"] = "2"
// create stats
stat1 := NewStats(m)
stat2 := NewStats(m)
m1 := NewSingleMeasure("round", 10)
m2 := NewSingleMeasure("setup", 5)
stat1.Update(m1)
stat2.Update(m2)
str := new(bytes.Buffer)
avgStat := AverageStats([]*Stats{stat1, stat2})
avgStat.WriteHeader(str)
avgStat.WriteValues(str)
stat3 := NewStats(m)
stat4 := NewStats(m)
stat3.Update(m1)
stat4.Update(m2)
str2 := new(bytes.Buffer)
avgStat2 := AverageStats([]*Stats{stat3, stat4})
avgStat2.WriteHeader(str2)
avgStat2.WriteValues(str2)
if !bytes.Equal(str.Bytes(), str2.Bytes()) {
t.Fatal("Average are not the same !")
}
}
示例6: TestSimulationBF
func TestSimulationBF(t *testing.T) {
defer log.AfterTest(t)
log.TestOutput(testing.Verbose(), 4)
sc, _, err := createBFTree(7, 2)
if err != nil {
t.Fatal(err)
}
addresses := []string{
"local1:2000", "local2:2000",
"local1:2001", "local2:2001",
"local1:2002", "local2:2002",
"local1:2003",
}
for i, a := range sc.Roster.List {
if a.Addresses[0] != addresses[i] {
t.Fatal("Address", a.Addresses[0], "should be", addresses[i])
}
}
if !sc.Tree.IsBinary(sc.Tree.Root) {
t.Fatal("Created tree is not binary")
}
sc, _, err = createBFTree(13, 3)
if err != nil {
t.Fatal(err)
}
if len(sc.Tree.Root.Children) != 3 {
t.Fatal("Branching-factor 3 tree has not 3 children")
}
if !sc.Tree.IsNary(sc.Tree.Root, 3) {
t.Fatal("Created tree is not binary")
}
}
示例7: TestMain
func TestMain(m *testing.M) {
flag.Parse()
log.TestOutput(testing.Verbose(), 4)
code := m.Run()
log.AfterTest(nil)
os.Exit(code)
}
示例8: TestBftCoSi
func TestBftCoSi(t *testing.T) {
defer log.AfterTest(t)
log.TestOutput(testing.Verbose(), 4)
// Register test protocol using BFTCoSi
sda.ProtocolRegisterName(TestProtocolName, func(n *sda.TreeNodeInstance) (sda.ProtocolInstance, error) {
return NewBFTCoSiProtocol(n, verify)
})
for _, nbrHosts := range []int{3, 13} {
countMut.Lock()
veriCount = 0
countMut.Unlock()
log.Lvl2("Running BFTCoSi with", nbrHosts, "hosts")
local := sda.NewLocalTest()
_, _, tree := local.GenBigTree(nbrHosts, nbrHosts, 3, true, true)
done := make(chan bool)
// create the message we want to sign for this round
msg := []byte("Hello BFTCoSi")
// Start the protocol
node, err := local.CreateProtocol(tree, TestProtocolName)
if err != nil {
t.Fatal("Couldn't create new node:", err)
}
// Register the function generating the protocol instance
var root *ProtocolBFTCoSi
root = node.(*ProtocolBFTCoSi)
root.Msg = msg
// function that will be called when protocol is finished by the root
root.RegisterOnDone(func() {
done <- true
})
go node.Start()
// are we done yet?
wait := time.Second * 3
select {
case <-done:
countMut.Lock()
assert.Equal(t, veriCount, nbrHosts,
"Each host should have called verification.")
// if assert fails we don't care for unlocking (t.Fail)
countMut.Unlock()
sig := root.Signature()
if err := cosi.VerifyCosiSignatureWithException(root.Suite(),
root.AggregatedPublic, msg, sig.Sig,
sig.Exceptions); err != nil {
t.Fatal(fmt.Sprintf("%s Verification of the signature failed: %s", root.Name(), err.Error()))
}
case <-time.After(wait):
t.Fatal("Waited", wait, "sec for BFTCoSi to finish ...")
}
local.CloseAll()
}
}
示例9: TestBigTree
func TestBigTree(t *testing.T) {
defer log.AfterTest(t)
log.TestOutput(testing.Verbose(), 4)
for i := uint(12); i < 15; i++ {
_, _, err := createBFTree(1<<i-1, 2)
if err != nil {
t.Fatal(err)
}
}
}
示例10: TestProtocolAutomaticInstantiation
// This makes h2 the leader, so it creates a tree and entity list
// and start a protocol. H1 should receive that message and request the entitity
// list and the treelist and then instantiate the protocol.
func TestProtocolAutomaticInstantiation(t *testing.T) {
defer log.AfterTest(t)
log.TestOutput(testing.Verbose(), 4)
// setup
chanH1 := make(chan bool)
chanH2 := make(chan bool)
chans := []chan bool{chanH1, chanH2}
id := 0
// custom creation function so we know the step due to the channels
fn := func(n *sda.TreeNodeInstance) (sda.ProtocolInstance, error) {
ps := SimpleProtocol{
TreeNodeInstance: n,
Chan: chans[id],
}
ps.RegisterHandler(ps.ReceiveMessage)
id++
return &ps, nil
}
network.RegisterMessageType(SimpleMessage{})
sda.ProtocolRegisterName(simpleProto, fn)
h1, h2 := SetupTwoHosts(t, true)
defer h1.Close()
defer h2.Close()
h1.StartProcessMessages()
// create small Tree
el := sda.NewRoster([]*network.ServerIdentity{h1.ServerIdentity, h2.ServerIdentity})
h1.AddRoster(el)
tree := el.GenerateBinaryTree()
h1.AddTree(tree)
// start the protocol
go func() {
_, err := h1.StartProtocol(simpleProto, tree)
if err != nil {
t.Fatal(fmt.Sprintf("Could not start protocol %v", err))
}
}()
// we are supposed to receive something from host1 from Start()
select {
case _ = <-chanH1:
break
case <-time.After(200 * time.Millisecond):
t.Fatal("Could not receive from channel of host 1")
}
// Then we are supposed to receive from h2 after he got the tree and the
// entity list from h1
select {
case _ = <-chanH2:
break
case <-time.After(2 * time.Second):
t.Fatal("Could not receive from channel of host 1")
}
}
示例11: TestStatsAverageFiltered
func TestStatsAverageFiltered(t *testing.T) {
log.TestOutput(testing.Verbose(), 3)
m := make(map[string]string)
m["servers"] = "1"
m["hosts"] = "1"
m["bf"] = "2"
// create the filter entry
m["filter_round"] = "50"
// create stats
stat1 := NewStats(m)
stat2 := NewStats(m)
m1 := NewSingleMeasure("round", 10)
m2 := NewSingleMeasure("round", 20)
m3 := NewSingleMeasure("round", 150)
stat1.Update(m1)
stat1.Update(m2)
stat1.Update(m3)
stat2.Update(m1)
stat2.Update(m2)
stat2.Update(m3)
/* stat2.Collect()*/
//val := stat2.Value("round")
//if val.Avg() != (10+20)/2 {
//t.Fatal("Average with filter does not work?")
//}
str := new(bytes.Buffer)
avgStat := AverageStats([]*Stats{stat1, stat2})
avgStat.WriteHeader(str)
avgStat.WriteValues(str)
stat3 := NewStats(m)
stat4 := NewStats(m)
stat3.Update(m1)
stat3.Update(m2)
stat3.Update(m3)
stat4.Update(m1)
stat4.Update(m2)
stat4.Update(m3)
str2 := new(bytes.Buffer)
avgStat2 := AverageStats([]*Stats{stat3, stat4})
avgStat2.WriteHeader(str2)
avgStat2.WriteValues(str2)
if !bytes.Equal(str.Bytes(), str2.Bytes()) {
t.Fatal("Average are not the same !")
}
}
示例12: TestRandHound
func TestRandHound(t *testing.T) {
// Setup parameters
var name string = "RandHound" // Protocol name
var nodes uint32 = 10 // Number of nodes (peers + leader)
var trustees uint32 = 5 // Number of trustees
var purpose string = "RandHound test run" // Purpose
var shards uint32 = 2 // Number of shards created from the randomness
local := sda.NewLocalTest()
_, _, tree := local.GenTree(int(nodes), false, true, true)
defer local.CloseAll()
log.TestOutput(testing.Verbose(), 1)
// Setup and Start RandHound
log.Printf("RandHound - starting")
leader, err := local.CreateProtocol(tree, name)
if err != nil {
t.Fatal("Couldn't initialise RandHound protocol:", err)
}
rh := leader.(*randhound.RandHound)
err = rh.Setup(nodes, trustees, purpose)
if err != nil {
t.Fatal("Couldn't initialise RandHound protocol:", err)
}
log.Printf("RandHound - group config: %d %d %d %d %d %d\n", rh.Group.N, rh.Group.F, rh.Group.L, rh.Group.K, rh.Group.R, rh.Group.T)
log.Printf("RandHound - shards: %d\n", shards)
leader.Start()
select {
case <-rh.Leader.Done:
log.Printf("RandHound - done")
rnd, err := rh.Random()
if err != nil {
t.Fatal(err)
}
sharding, err := rh.Shard(rnd, shards)
if err != nil {
t.Fatal(err)
}
log.Printf("RandHound - random bytes: %v\n", rnd)
log.Printf("RandHound - sharding: %v\n", sharding)
case <-time.After(time.Second * 60):
t.Fatal("RandHound – time out")
}
}
示例13: TestNtree
func TestNtree(t *testing.T) {
defer log.AfterTest(t)
log.TestOutput(testing.Verbose(), 4)
for _, nbrHosts := range []int{1, 3, 13} {
log.Lvl2("Running ntree with", nbrHosts, "hosts")
local := sda.NewLocalTest()
_, _, tree := local.GenBigTree(nbrHosts, nbrHosts, 3, true, true)
done := make(chan bool)
// create the message we want to sign for this round
msg := []byte("Ntree rocks slowly")
// Register the function generating the protocol instance
var root *ntree.Protocol
// function that will be called when protocol is finished by the root
doneFunc := func() bool {
done <- true
return true
}
// Start the protocol
pi, err := local.CreateProtocol(tree, "NaiveTree")
if err != nil {
t.Fatal("Couldn't create new node:", err)
}
root = pi.(*ntree.Protocol)
root.Message = msg
root.OnDoneCallback(doneFunc)
err = pi.Start()
if nbrHosts == 1 {
if err == nil {
t.Fatal("Shouldn't be able to start NTree with 1 node")
}
} else if err != nil {
t.Fatal("Couldn't start protocol:", err)
} else {
select {
case <-done:
case <-time.After(time.Second * 2):
t.Fatal("Protocol didn't finish in time")
}
}
local.CloseAll()
}
}
示例14: TestTcpCounterIO
func TestTcpCounterIO(t *testing.T) {
defer log.AfterTest(t)
RegisterMessageType(&TestRegisterS{})
log.TestOutput(testing.Verbose(), 4)
receiverStarted := make(chan bool)
fn := func(s Conn) {
err := s.Send(context.TODO(), &TestRegisterS{10})
if err != nil {
t.Fatal("Error while sending message:", err)
}
close(receiverStarted)
}
h1 := NewTCPHost()
h2 := NewTCPHost()
done := make(chan bool)
go func() {
err := h1.Listen("localhost:3000", fn)
if err != nil {
t.Fatal("Listening failed for h1:", err)
}
done <- true
}()
c2, err := h2.Open("localhost:3000")
if err != nil {
t.Fatal("Couldn't open h2:", err)
}
<-receiverStarted
c2.Receive(context.TODO())
err = h1.Close()
if err != nil {
t.Fatal("Couldn't close:", err)
}
err = h2.Close()
if err != nil {
t.Fatal("Couldn't close:", err)
}
<-done
// verify the amount of bytes read / written
if h1.Tx() == 0 || h1.Tx() != h2.Rx() || h2.Rx() == 0 || h2.Rx() != c2.Rx() {
t.Fatal("stg is wrong with CounterIO implementation of TcpConn / TcpHost")
}
}
示例15: TestSecureTcp
// Testing exchange of entity
func TestSecureTcp(t *testing.T) {
defer log.AfterTest(t)
log.TestOutput(testing.Verbose(), 4)
opened := make(chan bool)
fn := func(s SecureConn) {
log.Lvl3("Getting connection from", s)
opened <- true
}
kp1 := config.NewKeyPair(Suite)
entity1 := NewServerIdentity(kp1.Public, "localhost:2000")
kp2 := config.NewKeyPair(Suite)
entity2 := NewServerIdentity(kp2.Public, "localhost:2001")
host1 := NewSecureTCPHost(kp1.Secret, entity1)
host2 := NewSecureTCPHost(kp1.Secret, entity2)
done := make(chan bool)
go func() {
err := host1.Listen(fn)
if err != nil {
t.Fatal("Couldn't listen:", err)
}
done <- true
}()
conn, err := host2.Open(entity1)
if err != nil {
t.Fatal("Couldn't connect to host1:", err)
}
if !conn.ServerIdentity().Public.Equal(kp1.Public) {
t.Fatal("Connection-id is not from host1")
}
if !<-opened {
t.Fatal("Lazy programmers - no select")
}
log.Lvl4("Closing connections")
if err := host1.Close(); err != nil {
t.Fatal("Couldn't close host", host1)
}
if err := host2.Close(); err != nil {
t.Fatal("Couldn't close host", host2)
}
<-done
}