Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafa committed Oct 7, 2023
1 parent ad69ae8 commit f89cfde
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 39 deletions.
13 changes: 0 additions & 13 deletions config/getters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"testing"
"time"

"github.com/panjf2000/gnet/v2"
"github.com/rs/zerolog"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -75,18 +74,6 @@ func TestGetTickInterval(t *testing.T) {
assert.Equal(t, DefaultTickInterval, server.GetTickInterval())
}

// TestGetLoadBalancer tests the GetLoadBalancer function.
func TestGetLoadBalancer(t *testing.T) {
server := Server{}
assert.Equal(t, gnet.RoundRobin, server.GetLoadBalancer())
}

// TestGetTCPNoDelay tests the GetTCPNoDelay function.
func TestGetTCPNoDelay(t *testing.T) {
server := Server{}
assert.Equal(t, gnet.TCPDelay, server.GetTCPNoDelay())
}

// TestGetSize tests the GetSize function.
func TestGetSize(t *testing.T) {
pool := Pool{}
Expand Down
27 changes: 14 additions & 13 deletions network/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,12 @@ func BenchmarkProxyConnectDisconnect(b *testing.B) {
config.DefaultPluginTimeout)
defer proxy.Shutdown()

gconn := testGNetConnection{}
conn := testConnection{}

// Connect to the proxy
for i := 0; i < b.N; i++ {
proxy.Connect(gconn.Conn) //nolint:errcheck
proxy.Disconnect(&gconn) //nolint:errcheck
proxy.Connect(conn.Conn) //nolint:errcheck
proxy.Disconnect(&conn) //nolint:errcheck
}
}

Expand Down Expand Up @@ -306,13 +306,14 @@ func BenchmarkProxyPassThrough(b *testing.B) {
config.DefaultPluginTimeout)
defer proxy.Shutdown()

gconn := testGNetConnection{}
proxy.Connect(gconn.Conn) //nolint:errcheck
defer proxy.Disconnect(&gconn) //nolint:errcheck
conn := testConnection{}
proxy.Connect(conn.Conn) //nolint:errcheck
defer proxy.Disconnect(&conn) //nolint:errcheck

// Connect to the proxy
for i := 0; i < b.N; i++ {
proxy.PassThrough(&gconn) //nolint:errcheck
proxy.PassThroughToClient(&conn) //nolint:errcheck
proxy.PassThroughToServer(&conn) //nolint:errcheck
}
}

Expand Down Expand Up @@ -362,9 +363,9 @@ func BenchmarkProxyIsHealthyAndIsExhausted(b *testing.B) {
config.DefaultPluginTimeout)
defer proxy.Shutdown()

gconn := testGNetConnection{}
proxy.Connect(gconn.Conn) //nolint:errcheck
defer proxy.Disconnect(&gconn) //nolint:errcheck
conn := testConnection{}
proxy.Connect(conn.Conn) //nolint:errcheck
defer proxy.Disconnect(&conn) //nolint:errcheck

// Connect to the proxy
for i := 0; i < b.N; i++ {
Expand Down Expand Up @@ -419,9 +420,9 @@ func BenchmarkProxyAvailableAndBusyConnections(b *testing.B) {
config.DefaultPluginTimeout)
defer proxy.Shutdown()

gconn := testGNetConnection{}
proxy.Connect(gconn.Conn) //nolint:errcheck
defer proxy.Disconnect(&gconn) //nolint:errcheck
conn := testConnection{}
proxy.Connect(conn.Conn) //nolint:errcheck
defer proxy.Disconnect(&conn) //nolint:errcheck

// Connect to the proxy
for i := 0; i < b.N; i++ {
Expand Down
8 changes: 2 additions & 6 deletions network/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/gatewayd-io/gatewayd/logging"
"github.com/gatewayd-io/gatewayd/plugin"
"github.com/gatewayd-io/gatewayd/pool"
"github.com/panjf2000/gnet/v2"
"github.com/rs/zerolog"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc"
Expand Down Expand Up @@ -173,11 +172,8 @@ func TestRunServer(t *testing.T) {
"tcp",
"127.0.0.1:15432",
config.DefaultTickInterval,
[]gnet.Option{
gnet.WithMulticore(false),
gnet.WithReuseAddr(true),
gnet.WithReusePort(true),
gnet.WithTicker(true), // Enable ticker.
Option{
EnableTicker: false,
},
proxy,
logger,
Expand Down
13 changes: 6 additions & 7 deletions network/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/gatewayd-io/gatewayd/config"
"github.com/gatewayd-io/gatewayd/logging"
"github.com/panjf2000/gnet/v2"
"github.com/rs/zerolog"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -112,18 +111,18 @@ func BenchmarkResolveUnix(b *testing.B) {
}
}

type testGNetConnection struct {
gnet.Conn
type testConnection struct {
net.Conn
}

func (c *testGNetConnection) LocalAddr() net.Addr {
func (c *testConnection) LocalAddr() net.Addr {
return &net.TCPAddr{
IP: net.ParseIP("127.0.0.1"),
Port: 0,
}
}

func (c *testGNetConnection) RemoteAddr() net.Addr {
func (c *testConnection) RemoteAddr() net.Addr {
return &net.TCPAddr{
IP: net.ParseIP("127.0.0.1"),
Port: 0,
Expand All @@ -139,7 +138,7 @@ func BenchmarkTrafficData(b *testing.B) {
NoColor: true,
})

gconn := &testGNetConnection{}
conn := &testConnection{}
client := NewClient(context.Background(), &config.Client{
Network: "tcp",
Address: "localhost:5432",
Expand All @@ -159,7 +158,7 @@ func BenchmarkTrafficData(b *testing.B) {
}
err := "test error"
for i := 0; i < b.N; i++ {
trafficData(gconn, client, fields, err)
trafficData(conn, client, fields, err)
}
}

Expand Down

0 comments on commit f89cfde

Please sign in to comment.