Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various network topology examples. #41

Merged
merged 39 commits into from
Jul 1, 2018
Merged
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5dd1f7a
Ring topology test
doug-perlin Jun 26, 2018
7048073
topology-ring: finish ring test
doug-perlin Jun 26, 2018
ba56843
Setup all the topologies
doug-perlin Jun 27, 2018
db9023a
topology-ring: clean up some code
doug-perlin Jun 27, 2018
7fae6ea
Added tests for all the nodes
doug-perlin Jun 27, 2018
f89a3ba
topology-ring: added sending messages from all the nodes
doug-perlin Jun 27, 2018
bf7137d
Merge branch 'master' into topology-ring
doug-perlin Jun 27, 2018
45f6fda
Fix up the topology tests to work with master
doug-perlin Jun 27, 2018
204bf63
Merge branch 'fix-tests' into topology-ring
doug-perlin Jun 27, 2018
fe9118e
Allow the mesh topology test to run
doug-perlin Jun 27, 2018
abb643e
Merge branch 'master' into topology-ring
doug-perlin Jun 28, 2018
0bdeb61
merged master, seems to be broken now
doug-perlin Jun 28, 2018
c44e2f0
Try to debug ring test
doug-perlin Jun 28, 2018
5a3c199
Merge branch 'master' into topology-ring
doug-perlin Jun 28, 2018
911d85f
More sleeps
doug-perlin Jun 28, 2018
91ea44a
net: Created function BlockUntilListening() to block functions until …
iwasaki-kenta Jun 28, 2018
05dff08
remove debug statements
doug-perlin Jun 28, 2018
91834e2
Merge branch 'topology-ring' of github.com:perlin-network/noise into …
doug-perlin Jun 28, 2018
0736304
Fix compile error
doug-perlin Jun 28, 2018
76cbaf5
Fixed the ring test
doug-perlin Jun 28, 2018
2e74e95
Cleaned up the tests
doug-perlin Jun 28, 2018
b299f1f
Made some of the offset more clear, removed the t.Parallel()
doug-perlin Jun 28, 2018
dc57af8
Reduce the timeouts
doug-perlin Jun 28, 2018
ef8677c
Fix some typos
doug-perlin Jun 28, 2018
eed7932
Reduce the timeout
doug-perlin Jun 28, 2018
eb7f97b
Merge branch 'master' into topology-ring
doug-perlin Jun 29, 2018
1e376ea
topology: all pass except for ring
doug-perlin Jun 29, 2018
3252b04
top: Fix the ring test
doug-perlin Jun 29, 2018
10eb1a3
top: Cleaned up comments, parallelize the tests, disabled peer discovery
doug-perlin Jun 29, 2018
9e7f71f
top: Updated some comments
doug-perlin Jun 29, 2018
b8c353a
top: fix up comment
doug-perlin Jun 29, 2018
d808f9d
top: Converted the test to an example
doug-perlin Jun 29, 2018
ee474fb
Merge branch 'master' into topology-ring
doug-perlin Jul 1, 2018
c66b263
Merge branch 'master' into topology-ring
doug-perlin Jul 1, 2018
dc72e4d
Fixed up the merge to master
doug-perlin Jul 1, 2018
2d32fa3
top: Made starting port greater to make it less likely to conflict.
iwasaki-kenta Jul 1, 2018
ae5163a
topology: Converted the example to a test, added short flags to skip
doug-perlin Jul 1, 2018
8e8ac52
Merge branch 'topology-ring' of github.com:perlin-network/noise into …
doug-perlin Jul 1, 2018
0600b5a
Merge branch 'master' into topology-ring
doug-perlin Jul 1, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
topology: Converted the example to a test, added short flags to skip
  • Loading branch information
doug-perlin committed Jul 1, 2018
commit ae5163a9133b43180c91d5c47fbba08758c1ec3f
135 changes: 59 additions & 76 deletions examples/topologies/topologies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package topologies

import (
"fmt"
"testing"
"time"

"github.com/perlin-network/noise/crypto"
Expand Down Expand Up @@ -231,7 +232,7 @@ func bootstrapNodes(nodes []*network.Network, peers map[string]map[string]struct
}

// broadcastTest will broadcast a message from the sender node, checks if the right peers receive it
func broadcastTest(nodes []*network.Network, processors []*TopologyProcessor, peers map[string]map[string]struct{}, sender int) {
func broadcastTest(t *testing.T, nodes []*network.Network, processors []*TopologyProcessor, peers map[string]map[string]struct{}, sender int) {
timeout := 250 * time.Millisecond

// Broadcast is an asynchronous call to send a message to other nodes
Expand All @@ -244,7 +245,7 @@ func broadcastTest(nodes []*network.Network, processors []*TopologyProcessor, pe
// if not a peer or not the sender, should not receive anything
select {
case received := <-processors[sender].Mailbox:
fmt.Printf("Expected nothing in sending node %d, got %v\n", sender, received)
t.Errorf("Expected nothing in sending node %d, got %v\n", sender, received)
case <-time.After(timeout):
// this is the good case, don't want to receive anything
}
Expand All @@ -254,16 +255,21 @@ func broadcastTest(nodes []*network.Network, processors []*TopologyProcessor, pe
case received := <-processors[i].Mailbox:
// this is a receiving node, it should have just the one message buffered up
if received.Message != expected {
fmt.Printf("Expected message '%s' for node %d --> %d, but got %v\n", expected, sender, i, received)
t.Errorf("Expected message '%s' for node %d --> %d, but got %v\n", expected, sender, i, received)
}
case <-time.After(timeout):
fmt.Printf("Expected a message for node %d --> %d, but it timed out\n", sender, i)
t.Errorf("Expected a message for node %d --> %d, but it timed out\n", sender, i)
}
}
}
}

func ExampleRing() {
func TestRing(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("skipping ring test in short mode")
}

var nodes []*network.Network
var processors []*TopologyProcessor
var err error
Expand All @@ -274,29 +280,26 @@ func ExampleRing() {
// setup the cluster
nodes, processors, err = setupNodes(ports)
if err != nil {
fmt.Println(err)
return
t.Fatal(err)
}

// setup node connections
if err := bootstrapNodes(nodes, peers); err != nil {
fmt.Println(err)
return
t.Fatal(err)
}
fmt.Println("Nodes setup as a ring topology.")

// have everyone send messages
for i := 0; i < len(nodes); i++ {
broadcastTest(nodes, processors, peers, i)
broadcastTest(t, nodes, processors, peers, i)
}
fmt.Printf("Messages sent from each node.")

// Output:
// Nodes setup as a ring topology.
// Messages sent from each node.
}

func ExampleMesh() {
func TestMesh(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("skipping mesh test in short mode")
}

var nodes []*network.Network
var processors []*TopologyProcessor
var err error
Expand All @@ -305,27 +308,24 @@ func ExampleMesh() {

nodes, processors, err = setupNodes(ports)
if err != nil {
fmt.Println(err)
return
t.Fatal(err)
}

if err := bootstrapNodes(nodes, peers); err != nil {
fmt.Println(err)
return
t.Fatal(err)
}
fmt.Println("Nodes setup as a mesh topology.")

for i := 0; i < len(nodes); i++ {
broadcastTest(nodes, processors, peers, i)
broadcastTest(t, nodes, processors, peers, i)
}
fmt.Printf("Messages sent from each node.")

// Output:
// Nodes setup as a mesh topology.
// Messages sent from each node.
}

func ExampleStar() {
func TestStar(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("skipping star test in short mode")
}

var nodes []*network.Network
var processors []*TopologyProcessor
var err error
Expand All @@ -334,27 +334,24 @@ func ExampleStar() {

nodes, processors, err = setupNodes(ports)
if err != nil {
fmt.Println(err)
return
t.Fatal(err)
}

if err := bootstrapNodes(nodes, peers); err != nil {
fmt.Println(err)
return
t.Fatal(err)
}
fmt.Println("Nodes setup as a star topology.")

for i := 0; i < len(nodes); i++ {
broadcastTest(nodes, processors, peers, i)
broadcastTest(t, nodes, processors, peers, i)
}
fmt.Printf("Messages sent from each node.")

// Output:
// Nodes setup as a star topology.
// Messages sent from each node.
}

func ExampleFullyConnected() {
func TestFullyConnected(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("skipping fully connected test in short mode")
}

var nodes []*network.Network
var processors []*TopologyProcessor
var err error
Expand All @@ -363,27 +360,24 @@ func ExampleFullyConnected() {

nodes, processors, err = setupNodes(ports)
if err != nil {
fmt.Println(err)
return
t.Fatal(err)
}

if err := bootstrapNodes(nodes, peers); err != nil {
fmt.Println(err)
return
t.Fatal(err)
}
fmt.Println("Nodes setup as a fully connected topology.")

for i := 0; i < len(nodes); i++ {
broadcastTest(nodes, processors, peers, i)
broadcastTest(t, nodes, processors, peers, i)
}
fmt.Printf("Messages sent from each node.")

// Output:
// Nodes setup as a fully connected topology.
// Messages sent from each node.
}

func ExampleLine() {
func TestLine(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("skipping line test in short mode")
}

var nodes []*network.Network
var processors []*TopologyProcessor
var err error
Expand All @@ -392,27 +386,24 @@ func ExampleLine() {

nodes, processors, err = setupNodes(ports)
if err != nil {
fmt.Println(err)
return
t.Fatal(err)
}

if err := bootstrapNodes(nodes, peers); err != nil {
fmt.Println(err)
return
t.Fatal(err)
}
fmt.Println("Nodes setup as a line topology.")

for i := 0; i < len(nodes); i++ {
broadcastTest(nodes, processors, peers, i)
broadcastTest(t, nodes, processors, peers, i)
}
fmt.Printf("Messages sent from each node.")

// Output:
// Nodes setup as a line topology.
// Messages sent from each node.
}

func ExampleTree() {
func TestTree(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("skipping tree test in short mode")
}

var nodes []*network.Network
var processors []*TopologyProcessor
var err error
Expand All @@ -421,22 +412,14 @@ func ExampleTree() {

nodes, processors, err = setupNodes(ports)
if err != nil {
fmt.Println(err)
return
t.Fatal(err)
}

if err := bootstrapNodes(nodes, peers); err != nil {
fmt.Println(err)
return
t.Fatal(err)
}
fmt.Println("Nodes setup as a tree topology.")

for i := 0; i < len(nodes); i++ {
broadcastTest(nodes, processors, peers, i)
broadcastTest(t, nodes, processors, peers, i)
}
fmt.Printf("Messages sent from each node.")

// Output:
// Nodes setup as a tree topology.
// Messages sent from each node.
}