Skip to content

Commit d8ac486

Browse files
committed
set timeout sys vars, updated tests
1 parent 0d23024 commit d8ac486

File tree

3 files changed

+30
-33
lines changed

3 files changed

+30
-33
lines changed

enginetest/server_engine_test.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"math"
88
"net"
9+
"os"
910
"testing"
1011

1112
"github.com/dolthub/vitess/go/mysql"
@@ -376,7 +377,10 @@ func TestServerPreparedStatements(t *testing.T) {
376377
}
377378
}
378379

379-
func TestServerQueries(t *testing.T) {
380+
func TestServerVariables(t *testing.T) {
381+
hostname, herr := os.Hostname()
382+
require.NoError(t, herr)
383+
380384
port, perr := findEmptyPort()
381385
require.NoError(t, perr)
382386

@@ -388,22 +392,24 @@ func TestServerQueries(t *testing.T) {
388392

389393
tests := []serverScriptTest{
390394
{
391-
name: "test that config variables are properly set",
395+
name: "test that config system variables are properly set",
392396
setup: []string{},
393397
assertions: []serverScriptTestAssertion{
394398
{
395-
query: "select @@hostname, @@port",
396-
//query: "select @@hostname, @@port, @@max_connections",
399+
query: "select @@hostname, @@port, @@max_connections, @@net_read_timeout, @@net_write_timeout",
397400
isExec: false,
398401
expectedRows: []any{
399-
sql.Row{"macbook.local", port},
402+
sql.Row{hostname, port, 1, 1, 1},
400403
},
401404
checkRows: func(t *testing.T, rows *gosql.Rows, expectedRows []any) (bool, error) {
402405
var resHostname string
403406
var resPort int
407+
var resMaxConnections int
408+
var resNetReadTimeout int
409+
var resNetWriteTimeout int
404410
var rowNum int
405411
for rows.Next() {
406-
if err := rows.Scan(&resHostname, &resPort); err != nil {
412+
if err := rows.Scan(&resHostname, &resPort, &resMaxConnections, &resNetReadTimeout, &resNetWriteTimeout); err != nil {
407413
return false, err
408414
}
409415
if rowNum >= len(expectedRows) {

server/server.go

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"errors"
1919
"fmt"
2020
"net"
21-
"os"
2221
"strconv"
2322
"time"
2423

@@ -120,19 +119,7 @@ func portInUse(hostPort string) bool {
120119
return false
121120
}
122121

123-
func getHostname() (string, error) {
124-
hostname, err := os.Hostname()
125-
if err != nil {
126-
return "", err
127-
}
128-
return hostname, nil
129-
}
130-
131122
func updateSystemVariables(cfg mysql.ListenerConfig) error {
132-
hostname, err := getHostname()
133-
if err != nil {
134-
return err
135-
}
136123
_, port, err := net.SplitHostPort(cfg.Listener.Addr().String())
137124
if err != nil {
138125
return err
@@ -143,10 +130,10 @@ func updateSystemVariables(cfg mysql.ListenerConfig) error {
143130
}
144131
// TODO: add the rest of the config variables
145132
err = sql.SystemVariables.AssignValues(map[string]interface{}{
146-
"port": portInt,
147-
"hostname": hostname,
148-
// TODO: this causes an error because max_connections is 0?
149-
//"max_connections": cfg.MaxConns,
133+
"port": portInt,
134+
"max_connections": cfg.MaxConns,
135+
"net_read_timeout": cfg.ConnReadTimeout.Seconds(),
136+
"net_write_timeout": cfg.ConnWriteTimeout.Seconds(),
150137
})
151138
if err != nil {
152139
return err
@@ -155,14 +142,18 @@ func updateSystemVariables(cfg mysql.ListenerConfig) error {
155142
}
156143

157144
func newServerFromHandler(cfg Config, e *sqle.Engine, sm *SessionManager, handler mysql.Handler, sel ServerEventListener) (*Server, error) {
158-
if cfg.ConnReadTimeout < 0 {
159-
cfg.ConnReadTimeout = 0
160-
}
161-
if cfg.ConnWriteTimeout < 0 {
162-
cfg.ConnWriteTimeout = 0
163-
}
164-
if cfg.MaxConnections < 0 {
165-
cfg.MaxConnections = 0
145+
oneSecond := time.Duration(1) * time.Second
146+
if cfg.ConnReadTimeout < oneSecond {
147+
// TODO set to MySQL default value
148+
cfg.ConnReadTimeout = oneSecond
149+
}
150+
if cfg.ConnWriteTimeout < oneSecond {
151+
// TODO set to MySQL default value
152+
cfg.ConnWriteTimeout = oneSecond
153+
}
154+
if cfg.MaxConnections < 1 {
155+
// TODO set to MySQL default value
156+
cfg.MaxConnections = 1
166157
}
167158

168159
for _, opt := range cfg.Options {

server/server_config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@ func (c Config) NewConfig() (Config, error) {
109109
if !ok {
110110
return Config{}, sql.ErrUnknownSystemVariable.New("net_write_timeout")
111111
}
112-
c.ConnWriteTimeout = time.Duration(timeout) * time.Millisecond
112+
c.ConnWriteTimeout = time.Duration(timeout) * time.Second
113113
}
114114
if _, val, ok := sql.SystemVariables.GetGlobal("net_read_timeout"); ok {
115115
timeout, ok := val.(int64)
116116
if !ok {
117117
return Config{}, sql.ErrUnknownSystemVariable.New("net_read_timeout")
118118
}
119-
c.ConnReadTimeout = time.Duration(timeout) * time.Millisecond
119+
c.ConnReadTimeout = time.Duration(timeout) * time.Second
120120
}
121121
return c, nil
122122
}

0 commit comments

Comments
 (0)