Created
May 9, 2019 17:06
-
-
Save rhinof/90553bc2fa43aa8c33ad9c2704f95a6b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unc TestRPC(t *testing.T) { | |
c1 := Command1{} | |
c2 := Command2{} | |
cmd1 := gbus.NewBusMessage(c1) | |
cmd2 := gbus.NewBusMessage(c2) | |
reply1 := gbus.NewBusMessage(Reply1{}) | |
reply2 := gbus.NewBusMessage(Reply2{}) | |
handler := func(invocation gbus.Invocation, message *gbus.BusMessage) error { | |
invocation.Bus().RPC(invocation.Ctx(), testSvc1, cmd2, reply2, 5*time.Second) | |
return invocation.Reply(invocation.Ctx(), reply1) | |
} | |
handler2 := func(invocation gbus.Invocation, message *gbus.BusMessage) error { | |
return invocation.Reply(invocation.Ctx(), reply2) | |
} | |
svc1 := createNamedBusForTest(testSvc1) | |
svc1.HandleMessage(c1, handler) | |
svc1.HandleMessage(c2, handler2) | |
svc1.Start() | |
defer svc1.Shutdown() | |
svc2 := createNamedBusForTest(testSvc2) | |
svc2.Start() | |
defer svc2.Shutdown() | |
t.Log("Sending RPC") | |
reply1, timeoutErr := svc2.RPC(context.Background(), testSvc1, cmd1, reply1, 5*time.Second) | |
t.Log("Tested RPC") | |
if reply1 == nil { | |
t.Fatalf("reply message was nil, error:%v", timeoutErr) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment