|
|
@ -8,7 +8,9 @@ import ( |
|
|
|
msg_pb "github.com/harmony-one/harmony/api/proto/message" |
|
|
|
msg_pb "github.com/harmony-one/harmony/api/proto/message" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
type SupportSyncingTest struct{} |
|
|
|
type SupportSyncingTest struct { |
|
|
|
|
|
|
|
msgChan chan *msg_pb.Message |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *SupportSyncingTest) StartService() { |
|
|
|
func (s *SupportSyncingTest) StartService() { |
|
|
|
fmt.Println("SupportSyncingTest starting") |
|
|
|
fmt.Println("SupportSyncingTest starting") |
|
|
@ -19,9 +21,14 @@ func (s *SupportSyncingTest) StopService() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *SupportSyncingTest) NotifyService(data map[string]interface{}) { |
|
|
|
func (s *SupportSyncingTest) NotifyService(data map[string]interface{}) { |
|
|
|
fmt.Println("SupportSyncingTest being notified") |
|
|
|
t := data["test"].(*testing.T) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if s.msgChan != data["chan"].(chan *msg_pb.Message) { |
|
|
|
|
|
|
|
t.Error("message chan is not equal to the one from the passing params") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
func (s *SupportSyncingTest) SetMessageChan(msgChan chan *msg_pb.Message) { |
|
|
|
func (s *SupportSyncingTest) SetMessageChan(msgChan chan *msg_pb.Message) { |
|
|
|
|
|
|
|
s.msgChan = msgChan |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Test TakeAction.
|
|
|
|
// Test TakeAction.
|
|
|
@ -39,3 +46,22 @@ func TestTakeAction(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
m.SendAction(&Action{ServiceType: Done}) |
|
|
|
m.SendAction(&Action{ServiceType: Done}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestMessageChan(t *testing.T) { |
|
|
|
|
|
|
|
m := &Manager{} |
|
|
|
|
|
|
|
m.SetupServiceManager() |
|
|
|
|
|
|
|
m.RegisterService(SupportSyncing, &SupportSyncingTest{}) |
|
|
|
|
|
|
|
msgChans := make(map[Type]chan *msg_pb.Message) |
|
|
|
|
|
|
|
m.SetupServiceMessageChan(msgChans) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m.SendAction(&Action{ |
|
|
|
|
|
|
|
Action: Notify, |
|
|
|
|
|
|
|
ServiceType: SupportSyncing, |
|
|
|
|
|
|
|
Params: map[string]interface{}{ |
|
|
|
|
|
|
|
"chan": msgChans[SupportSyncing], |
|
|
|
|
|
|
|
"test": t, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m.SendAction(&Action{ServiceType: Done}) |
|
|
|
|
|
|
|
} |
|
|
|