package rpc import ( "context" "math/rand" "testing" "time" "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 { logger.Println(tid.Hex()) return tid[0] >= 10 } func (tr *testReceiver) TestFunc(a string, b string, c int) { target := primitive.NewObjectID() target[0] = byte(rand.Intn(2) * 20) if Make(tr).To(target).Call(a, b, c) != ErrCanExecuteHere { return } logger.Println(" ", a, b, target[0]) } func TestRpc(t *testing.T) { var tr testReceiver RegistReceiver(&tr) myctx, cancel := context.WithCancel(context.Background()) redisClient, _ := gocommon.NewRedisClient("redis://192.168.8.94:6379", 0) go func() { for { tr.TestFunc("aaaa", "bbbb", 333) time.Sleep(time.Second) } }() Start(myctx, redisClient) <-myctx.Done() cancel() }