Skip to content

Commit

Permalink
support memmory connection for unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
smallnest committed Nov 2, 2021
1 parent 36c8e98 commit a224da4
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 1 addition & 6 deletions client/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var ConnFactories = map[string]ConnFactoryFn{
"kcp": newDirectKCPConn,
"quic": newDirectQuicConn,
"unix": newDirectConn,
"memu": newMemuConn,
}

// Connect connects the server via specified network.
Expand All @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions client/connection_memu.go
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
15 changes: 15 additions & 0 deletions server/memconn.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit a224da4

Please sign in to comment.