2018-06-13 02:06:59 +00:00
|
|
|
package p2p
|
|
|
|
|
2018-07-17 18:39:04 +00:00
|
|
|
import (
|
|
|
|
"reflect"
|
2018-09-09 22:15:24 +00:00
|
|
|
"sync"
|
2018-07-17 18:39:04 +00:00
|
|
|
"testing"
|
2018-09-09 22:15:24 +00:00
|
|
|
|
2018-12-23 20:34:59 +00:00
|
|
|
"github.com/gogo/protobuf/proto"
|
2018-09-09 22:15:24 +00:00
|
|
|
testpb "github.com/prysmaticlabs/prysm/proto/testing"
|
2018-07-17 18:39:04 +00:00
|
|
|
)
|
2018-06-13 02:06:59 +00:00
|
|
|
|
2019-02-22 15:11:26 +00:00
|
|
|
func TestFeed_SameFeed(t *testing.T) {
|
2018-06-13 02:06:59 +00:00
|
|
|
tests := []struct {
|
2018-09-09 22:15:24 +00:00
|
|
|
a proto.Message
|
|
|
|
b proto.Message
|
2018-06-13 02:06:59 +00:00
|
|
|
want bool
|
|
|
|
}{
|
2018-06-13 11:44:45 +00:00
|
|
|
// Equality tests
|
2018-09-09 22:15:24 +00:00
|
|
|
{a: &testpb.TestMessage{}, b: &testpb.TestMessage{}, want: true},
|
|
|
|
{a: &testpb.Puzzle{}, b: &testpb.Puzzle{}, want: true},
|
2018-06-13 02:06:59 +00:00
|
|
|
// Inequality tests
|
2018-09-09 22:15:24 +00:00
|
|
|
{a: &testpb.TestMessage{}, b: &testpb.Puzzle{}, want: false},
|
|
|
|
{a: &testpb.Puzzle{}, b: &testpb.TestMessage{}, want: false},
|
2018-06-13 02:06:59 +00:00
|
|
|
}
|
|
|
|
|
2018-11-25 16:55:02 +00:00
|
|
|
s, _ := NewServer(&ServerConfig{})
|
2018-06-13 02:06:59 +00:00
|
|
|
|
|
|
|
for _, tt := range tests {
|
2018-06-21 03:03:02 +00:00
|
|
|
feed1 := s.Feed(tt.a)
|
|
|
|
feed2 := s.Feed(tt.b)
|
2018-06-13 02:06:59 +00:00
|
|
|
|
|
|
|
if (feed1 == feed2) != tt.want {
|
|
|
|
t.Errorf("Expected %v == %v to be %t", feed1, feed2, tt.want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-08-12 20:27:21 +00:00
|
|
|
|
|
|
|
func TestFeed_ConcurrentWrite(t *testing.T) {
|
2018-09-09 22:15:24 +00:00
|
|
|
s := Server{
|
2018-09-16 18:02:53 +00:00
|
|
|
feeds: make(map[reflect.Type]Feed),
|
2018-09-09 22:15:24 +00:00
|
|
|
mutex: &sync.Mutex{},
|
2018-08-12 20:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < 5; i++ {
|
2018-09-09 22:15:24 +00:00
|
|
|
go s.Feed(&testpb.TestMessage{})
|
2018-08-12 20:27:21 +00:00
|
|
|
}
|
|
|
|
}
|