support memmory connection for unit tests

This commit is contained in:
smallnest
2021-11-02 17:21:15 +08:00
parent 36c8e986b4
commit a224da409a
6 changed files with 34 additions and 7 deletions

View File

@@ -13,8 +13,11 @@
- support websocket as the transport like tcp,kcp and quic
- add CMuxPlugin to allow developing customzied services by using the same single port
- re-tag rpcx to make sure the version is less than 2 (for go module)
- support visit grpc services by rpcx clients
- support visit grpc services by rpcx clients: https://github.com/rpcxio/rpcxplus/tree/master/grpcx
- support configing grpc servicves in rpcx server side
- improve rpcx performance
- add Inform method in XClient
- add memory connection for unit tests
## 1.6.0

View File

@@ -22,6 +22,7 @@ var ConnFactories = map[string]ConnFactoryFn{
"kcp": newDirectKCPConn,
"quic": newDirectQuicConn,
"unix": newDirectConn,
"memu": newMemuConn,
}
// Connect connects the server via specified network.
@@ -34,12 +35,6 @@ func (c *Client) Connect(network, address string) error {
conn, err = newDirectHTTPConn(c, network, address)
case "ws", "wss":
conn, err = newDirectWSConn(c, network, address)
case "kcp":
conn, err = newDirectKCPConn(c, network, address)
case "quic":
conn, err = newDirectQuicConn(c, network, address)
case "unix":
conn, err = newDirectConn(c, network, address)
default:
fn := ConnFactories[network]
if fn != nil {

11
client/connection_memu.go Normal file
View File

@@ -0,0 +1,11 @@
package client
import (
"net"
"github.com/akutz/memconn"
)
func newMemuConn(c *Client, network, address string) (net.Conn, error) {
return memconn.Dial(network, address)
}

1
go.mod
View File

@@ -4,6 +4,7 @@ go 1.16
require (
github.com/ChimeraCoder/gojson v1.1.0
github.com/akutz/memconn v0.1.0 // indirect
github.com/apache/thrift v0.14.0
github.com/cenk/backoff v2.2.1+incompatible // indirect
github.com/cenkalti/backoff v2.2.1+incompatible // indirect

2
go.sum
View File

@@ -11,6 +11,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/ChimeraCoder/gojson v1.1.0 h1:/6S8djl/jColpJGTYniA3xrqJWuKeyEozzPtpr5L4Pw=
github.com/ChimeraCoder/gojson v1.1.0/go.mod h1:nYbTQlu6hv8PETM15J927yM0zGj3njIldp72UT1MqSw=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/akutz/memconn v0.1.0 h1:NawI0TORU4hcOMsMr11g7vwlCdkYeLKXBcxWu2W/P8A=
github.com/akutz/memconn v0.1.0/go.mod h1:Jo8rI7m0NieZyLI5e2CDlRdRqRRB4S7Xp77ukDjH+Fw=
github.com/alangpierce/go-forceexport v0.0.0-20160317203124-8f1d6941cd75/go.mod h1:uAXEEpARkRhCZfEvy/y0Jcc888f9tHCc1W7/UeEtreE=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=

15
server/memconn.go Normal file
View File

@@ -0,0 +1,15 @@
package server
import (
"net"
"github.com/akutz/memconn"
)
func init() {
makeListeners["memconn"] = memconnMakeListener
}
func memconnMakeListener(s *Server, address string) (ln net.Listener, err error) {
return memconn.Listen("memu", address)
}