Files
gocommon/rpc/rpc_test.go

43 lines
837 B
Go
Raw Normal View History

2023-07-10 10:29:16 +09:00
package rpc
2023-07-10 10:53:49 +09:00
import (
"context"
"testing"
"go.mongodb.org/mongo-driver/bson/primitive"
"repositories.action2quare.com/ayo/gocommon"
"repositories.action2quare.com/ayo/gocommon/logger"
)
type testReceiver struct {
}
func (tr *testReceiver) TargetExists(tid primitive.ObjectID) bool {
return tid[0] >= 10
}
func (tr *testReceiver) TestFunc(a string, b string) {
logger.Println("TestFunc :", a, b)
target := primitive.NewObjectID()
target[0] = 0
if CallOrGo(tr, target, a, b) != ErrCanExecuteHere {
return
}
logger.Println(a, b)
}
2023-07-10 10:29:16 +09:00
func TestRpc(t *testing.T) {
2023-07-10 10:53:49 +09:00
var tr testReceiver
RegistReceiver(&tr)
myctx, cancel := context.WithCancel(context.Background())
redisClient, _ := gocommon.NewRedisClient("redis://192.168.8.94:6379", 0)
Start(myctx, redisClient)
2023-07-10 10:29:16 +09:00
2023-07-10 10:53:49 +09:00
tr.TestFunc("aaa", "bb")
<-myctx.Done()
cancel()
2023-07-10 10:29:16 +09:00
}