本文整理汇总了Golang中github.com/dedis/cothority/log.AfterTest函数的典型用法代码示例。如果您正苦于以下问题:Golang AfterTest函数的具体用法?Golang AfterTest怎么用?Golang AfterTest使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了AfterTest函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestNewNode
// Test instantiation of Node
func TestNewNode(t *testing.T) {
defer log.AfterTest(t)
h1, h2 := SetupTwoHosts(t, false)
// Add tree + entitylist
el := sda.NewRoster([]*network.ServerIdentity{h1.ServerIdentity, h2.ServerIdentity})
h1.AddRoster(el)
tree := el.GenerateBinaryTree()
h1.AddTree(tree)
// Try directly StartNewNode
proto, err := h1.StartProtocol(testProto, tree)
if err != nil {
t.Fatal("Could not start new protocol", err)
}
p := proto.(*ProtocolTest)
m := <-p.DispMsg
if m != "Dispatch" {
t.Fatal("Dispatch() not called - msg is:", m)
}
m = <-p.StartMsg
if m != "Start" {
t.Fatal("Start() not called - msg is:", m)
}
h1.Close()
h2.Close()
}
示例2: TestProtocolHandlers
func TestProtocolHandlers(t *testing.T) {
defer log.AfterTest(t)
local := sda.NewLocalTest()
_, _, tree := local.GenTree(3, false, true, true)
defer local.CloseAll()
log.Lvl2("Sending to children")
IncomingHandlers = make(chan *sda.TreeNodeInstance, 2)
p, err := local.CreateProtocol(tree, "ProtocolHandlers")
if err != nil {
t.Fatal(err)
}
go p.Start()
log.Lvl2("Waiting for responses")
child1 := <-IncomingHandlers
child2 := <-IncomingHandlers
if child1.ServerIdentity().ID == child2.ServerIdentity().ID {
t.Fatal("Both entities should be different")
}
log.Lvl2("Sending to parent")
tni := p.(*ProtocolHandlers).TreeNodeInstance
child1.SendTo(tni.TreeNode(), &NodeTestAggMsg{})
if len(IncomingHandlers) > 0 {
t.Fatal("This should not trigger yet")
}
child2.SendTo(tni.TreeNode(), &NodeTestAggMsg{})
final := <-IncomingHandlers
if final.ServerIdentity().ID != tni.ServerIdentity().ID {
t.Fatal("This should be the same ID")
}
}
示例3: TestProcessor_ProcessClientRequest
func TestProcessor_ProcessClientRequest(t *testing.T) {
defer log.AfterTest(t)
local := NewLocalTest()
// generate 5 hosts, they don't connect, they process messages, and they
// don't register the tree or entitylist
h := local.GenLocalHosts(1, false, false)[0]
defer local.CloseAll()
s := local.Services[h.ServerIdentity.ID]
ts := s[testServiceID]
cr := &ClientRequest{Data: mkClientRequest(&testMsg{12})}
ts.ProcessClientRequest(h.ServerIdentity, cr)
msg := ts.(*testService).Msg
if msg == nil {
t.Fatal("Msg should not be nil")
}
tm, ok := msg.(*testMsg)
if !ok {
t.Fatalf("Couldn't cast to *testMsg - %+v", tm)
}
if tm.I != 12 {
t.Fatal("Didn't send 12")
}
}
示例4: TestMain
func TestMain(m *testing.M) {
flag.Parse()
log.TestOutput(testing.Verbose(), 4)
code := m.Run()
log.AfterTest(nil)
os.Exit(code)
}
示例5: TestProcessor_AddMessage
func TestProcessor_AddMessage(t *testing.T) {
defer log.AfterTest(t)
p := NewServiceProcessor(nil)
log.ErrFatal(p.RegisterMessage(procMsg))
if len(p.functions) != 1 {
t.Fatal("Should have registered one function")
}
mt := network.TypeFromData(&testMsg{})
if mt == network.ErrorType {
t.Fatal("Didn't register message-type correctly")
}
var wrongFunctions = []interface{}{
procMsgWrong1,
procMsgWrong2,
procMsgWrong3,
procMsgWrong4,
procMsgWrong5,
procMsgWrong6,
}
for _, f := range wrongFunctions {
log.Lvl2("Checking function", reflect.TypeOf(f).String())
err := p.RegisterMessage(f)
if err == nil {
t.Fatalf("Shouldn't accept function %+s", reflect.TypeOf(f).String())
}
}
}
示例6: TestHostMessaging
// Test connection of multiple Hosts and sending messages back and forth
// also tests for the counterIO interface that it works well
func TestHostMessaging(t *testing.T) {
defer log.AfterTest(t)
h1, h2 := SetupTwoHosts(t, false)
bw1 := h1.Tx()
br2 := h2.Rx()
msgSimple := &SimpleMessage{3}
err := h1.SendRaw(h2.ServerIdentity, msgSimple)
if err != nil {
t.Fatal("Couldn't send from h2 -> h1:", err)
}
msg := h2.Receive()
decoded := testMessageSimple(t, msg)
if decoded.I != 3 {
t.Fatal("Received message from h2 -> h1 is wrong")
}
written := h1.Tx() - bw1
read := h2.Rx() - br2
if written == 0 || read == 0 || written != read {
t.Logf("Before => bw1 = %d vs br2 = %d", bw1, br2)
t.Logf("Tx = %d, Rx = %d", written, read)
t.Logf("h1.Tx() %d vs h2.Rx() %d", h1.Tx(), h2.Rx())
t.Fatal("Something is wrong with Host.CounterIO")
}
h1.Close()
h2.Close()
}
示例7: TestNodeChannel
func TestNodeChannel(t *testing.T) {
defer log.AfterTest(t)
local := sda.NewLocalTest()
_, _, tree := local.GenTree(2, false, true, true)
defer local.CloseAll()
p, err := local.CreateProtocol(tree, "ProtocolChannels")
if err != nil {
t.Fatal("Couldn't create new node:", err)
}
c := make(chan struct {
*sda.TreeNode
NodeTestMsg
}, 1)
tni := p.(*ProtocolChannels).TreeNodeInstance
err = tni.RegisterChannel(c)
if err != nil {
t.Fatal("Couldn't register channel:", err)
}
err = tni.DispatchChannel([]*sda.ProtocolMsg{&sda.ProtocolMsg{
Msg: NodeTestMsg{3},
MsgType: network.RegisterMessageType(NodeTestMsg{}),
From: &sda.Token{
TreeID: tree.ID,
TreeNodeID: tree.Root.ID,
}},
})
if err != nil {
t.Fatal("Couldn't dispatch to channel:", err)
}
msg := <-c
if msg.I != 3 {
t.Fatal("Message should contain '3'")
}
}
示例8: TestTokenId
func TestTokenId(t *testing.T) {
defer log.AfterTest(t)
t1 := &sda.Token{
RosterID: sda.RosterID(uuid.NewV1()),
TreeID: sda.TreeID(uuid.NewV1()),
ProtoID: sda.ProtocolID(uuid.NewV1()),
RoundID: sda.RoundID(uuid.NewV1()),
}
id1 := t1.ID()
t2 := &sda.Token{
RosterID: sda.RosterID(uuid.NewV1()),
TreeID: sda.TreeID(uuid.NewV1()),
ProtoID: sda.ProtocolID(uuid.NewV1()),
RoundID: sda.RoundID(uuid.NewV1()),
}
id2 := t2.ID()
if uuid.Equal(uuid.UUID(id1), uuid.UUID(id2)) {
t.Fatal("Both token are the same")
}
if !uuid.Equal(uuid.UUID(id1), uuid.UUID(t1.ID())) {
t.Fatal("Twice the Id of the same token should be equal")
}
t3 := t1.ChangeTreeNodeID(sda.TreeNodeID(uuid.NewV1()))
if t1.TreeNodeID.Equal(t3.TreeNodeID) {
t.Fatal("OtherToken should modify copy")
}
}
示例9: TestProcessor_GetReply
func TestProcessor_GetReply(t *testing.T) {
defer log.AfterTest(t)
p := NewServiceProcessor(nil)
log.ErrFatal(p.RegisterMessage(procMsg))
pair := config.NewKeyPair(network.Suite)
e := network.NewServerIdentity(pair.Public, "")
rep := p.GetReply(e, mkClientRequest(&testMsg{11}))
val, ok := rep.(*testMsg)
if !ok {
t.Fatalf("Couldn't cast reply to testMsg: %+v", rep)
}
if val.I != 11 {
t.Fatal("Value got lost - should be 11")
}
rep = p.GetReply(e, mkClientRequest(&testMsg{42}))
errMsg, ok := rep.(*StatusRet)
if !ok {
t.Fatal("42 should return an error")
}
if errMsg.Status == "" {
t.Fatal("The error should be non-empty")
}
}
示例10: TestTcpNetwork
// Testing a full-blown server/client
func TestTcpNetwork(t *testing.T) {
defer log.AfterTest(t)
// Create one client + one server
clientHost := NewTCPHost()
serverHost := NewTCPHost()
// Give them keys
clientPub := Suite.Point().Base()
serverPub := Suite.Point().Add(Suite.Point().Base(), Suite.Point().Base())
wg := sync.WaitGroup{}
client := NewSimpleClient(clientHost, clientPub, &wg)
server := NewSimpleServer(serverHost, serverPub, t, &wg)
// Make the server listen
done := make(chan bool)
go func() {
err := server.Listen("127.0.0.1:5000", server.ExchangeWithClient)
if err != nil {
t.Fatal("Couldn't listen:", err)
}
done <- true
}()
// Make the client engage with the server
client.ExchangeWithServer("127.0.0.1:5000", t)
wg.Wait()
if err := clientHost.Close(); err != nil {
t.Fatal("could not close client", err)
}
if err := serverHost.Close(); err != nil {
t.Fatal("could not close server", err)
}
<-done
}
示例11: TestHostClose
// Test closing and opening of Host on same address
func TestHostClose(t *testing.T) {
defer log.AfterTest(t)
time.Sleep(time.Second)
h1 := sda.NewLocalHost(2000)
h2 := sda.NewLocalHost(2001)
h1.ListenAndBind()
_, err := h2.Connect(h1.ServerIdentity)
if err != nil {
t.Fatal("Couldn't Connect()", err)
}
err = h1.Close()
if err != nil {
t.Fatal("Couldn't close:", err)
}
err = h2.Close()
if err != nil {
t.Fatal("Couldn't close:", err)
}
log.Lvl3("Finished first connection, starting 2nd")
h3 := sda.NewLocalHost(2002)
h3.ListenAndBind()
c, err := h2.Connect(h3.ServerIdentity)
if err != nil {
t.Fatal(h2, "Couldn Connect() to", h3)
}
log.Lvl3("Closing h3")
err = h3.Close()
if err != nil {
// try closing the underlying connection manually and fail
c.Close()
t.Fatal("Couldn't Close()", h3)
}
}
示例12: 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")
}
}
示例13: 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 ?")
}
}
示例14: 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")
}
}
示例15: 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()
}
}