github.com/volts-dev/volts@v0.0.0-20240120094013-5e9c65924106/internal/test/client/rpc_client_test.go (about) 1 package client 2 3 import ( 4 "sync" 5 "testing" 6 "time" 7 8 "github.com/volts-dev/volts" 9 "github.com/volts-dev/volts/client" 10 "github.com/volts-dev/volts/internal/test" 11 "github.com/volts-dev/volts/logger" 12 "github.com/volts-dev/volts/router" 13 "github.com/volts-dev/volts/server" 14 "github.com/volts-dev/volts/transport" 15 ) 16 17 func TestHelloworld(t *testing.T) { 18 r := router.New() 19 r.Url("CONNECT", "Arith", new(test.ArithCtrl)) 20 21 srv := server.New( 22 server.WithRouter(r), 23 ) 24 25 app := volts.New( 26 volts.Server(srv), 27 volts.Transport(transport.NewTCPTransport()), 28 volts.Debug(), 29 ) 30 31 var g sync.WaitGroup 32 g.Add(1) 33 34 go func() { 35 app.Run() 36 }() 37 38 go func() { 39 for { 40 if app.Server().Started() { 41 g.Done() 42 break 43 } 44 time.Sleep(500) 45 } 46 }() 47 48 g.Wait() 49 //<-time.After(3 * time.Second) 50 51 cli := client.NewRpcClient( 52 client.Debug(), 53 client.WithHost(app.Server().Config().Address), 54 ) 55 arith := test.NewArithCli(cli) 56 57 arg := &test.Args{Num1: 1, Num2: 2, Flt: 0.0123} 58 result, err := arith.Mul(arg) 59 if err != nil { 60 t.Fatal(err) 61 } 62 63 logger.Info(result) 64 }