commit inicial do projeto
This commit is contained in:
35
internal/p2p/p2p_test.go
Normal file
35
internal/p2p/p2p_test.go
Normal file
@ -0,0 +1,35 @@
|
||||
package p2p_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"dejo_node/internal/p2p"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestP2PNode_DHT(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
||||
defer cancel()
|
||||
|
||||
nodeA, err := p2p.NewP2PNode(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("falha ao criar node A: %v", err)
|
||||
}
|
||||
nodeA.ConnectToPeers(ctx)
|
||||
if err := nodeA.InitDHT(ctx); err != nil {
|
||||
t.Fatalf("erro ao iniciar DHT no node A: %v", err)
|
||||
}
|
||||
|
||||
nodeB, err := p2p.NewP2PNode(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("falha ao criar node B: %v", err)
|
||||
}
|
||||
nodeB.ConnectToPeers(ctx)
|
||||
if err := nodeB.InitDHT(ctx); err != nil {
|
||||
t.Fatalf("erro ao iniciar DHT no node B: %v", err)
|
||||
}
|
||||
|
||||
time.Sleep(5 * time.Second)
|
||||
nodeB.Broadcast("msg: test from B to A")
|
||||
time.Sleep(5 * time.Second)
|
||||
}
|
||||
Reference in New Issue
Block a user