github.com/ronaksoft/rony@v0.16.26-0.20230807065236-1743dbfe6959/internal/testEnv/test_server.go (about) 1 package testEnv 2 3 import ( 4 "fmt" 5 "time" 6 7 "github.com/ronaksoft/rony" 8 "github.com/ronaksoft/rony/edge" 9 "github.com/ronaksoft/rony/edgetest" 10 ) 11 12 /* 13 Creation Time: 2020 - Apr - 10 14 Created by: (ehsan) 15 Maintainers: 16 1. Ehsan N. Moosa (E2) 17 Auditor: Ehsan N. Moosa (E2) 18 Copyright Ronak Software Group 2020 19 */ 20 21 var ( 22 receivedMessages int32 23 receivedUpdates int32 24 ) 25 26 func EdgeServer(serverID string, listenPort int, concurrency int, opts ...edge.Option) *edge.Server { 27 opts = append(opts, 28 edge.WithTcpGateway(edge.TcpGatewayConfig{ 29 Concurrency: concurrency, 30 ListenAddress: fmt.Sprintf(":%d", listenPort), 31 MaxIdleTime: time.Second, 32 Protocol: rony.TCP, 33 ExternalAddrs: []string{fmt.Sprintf("127.0.0.1:%d", listenPort)}, 34 }), 35 ) 36 edgeServer := edge.NewServer(serverID, opts...) 37 38 return edgeServer 39 } 40 41 func TestServer(serverID string) *edgetest.Server { 42 return edgetest.NewServer( 43 serverID, &edge.DefaultDispatcher{}, 44 ) 45 } 46 47 func TestJSONServer(serverID string) *edgetest.Server { 48 return edgetest.NewServer( 49 serverID, &edge.JSONDispatcher{}, 50 ) 51 }