Skip to content

Commit

Permalink
update sqllogictest/go and add GetTimeout() method for harnesses
Browse files Browse the repository at this point in the history
  • Loading branch information
jennifersp committed Jan 18, 2024
1 parent eda861b commit ea4ada3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/dolthub/dolt/go v0.40.5-0.20240110011351-84b9180295cc
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20231213233028-64c353bf920f
github.com/dolthub/go-mysql-server v0.17.1-0.20240110234302-66c569a3137e
github.com/dolthub/sqllogictest/go v0.0.0-20240117232851-47bf95e955a2
github.com/dolthub/sqllogictest/go v0.0.0-20240118192953-30b6c7e33dfd
github.com/dolthub/vitess v0.0.0-20240110233415-e46007d964c0
github.com/fatih/color v1.13.0
github.com/gogo/protobuf v1.3.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ github.com/dolthub/jsonpath v0.0.2-0.20230525180605-8dc13778fd72 h1:NfWmngMi1CYU
github.com/dolthub/jsonpath v0.0.2-0.20230525180605-8dc13778fd72/go.mod h1:ZWUdY4iszqRQ8OcoXClkxiAVAoWoK3cq0Hvv4ddGRuM=
github.com/dolthub/maphash v0.0.0-20221220182448-74e1e1ea1577 h1:SegEguMxToBn045KRHLIUlF2/jR7Y2qD6fF+3tdOfvI=
github.com/dolthub/maphash v0.0.0-20221220182448-74e1e1ea1577/go.mod h1:gkg4Ch4CdCDu5h6PMriVLawB7koZ+5ijb9puGMV50a4=
github.com/dolthub/sqllogictest/go v0.0.0-20240117232851-47bf95e955a2 h1:NEzws/QjwLsn9sA0wmWA/Pc7RrnPbjE1WfYupfnhtK8=
github.com/dolthub/sqllogictest/go v0.0.0-20240117232851-47bf95e955a2/go.mod h1:e/FIZVvT2IR53HBCAo41NjqgtEnjMJGKca3Y/dAmZaA=
github.com/dolthub/sqllogictest/go v0.0.0-20240118192953-30b6c7e33dfd h1:PCBbb7lMwfpeYvoxpOc1vG6Lo+4+V8+r69p2aQvYhck=
github.com/dolthub/sqllogictest/go v0.0.0-20240118192953-30b6c7e33dfd/go.mod h1:e/FIZVvT2IR53HBCAo41NjqgtEnjMJGKca3Y/dAmZaA=
github.com/dolthub/swiss v0.1.0 h1:EaGQct3AqeP/MjASHLiH6i4TAmgbG/c4rA6a1bzCOPc=
github.com/dolthub/swiss v0.1.0/go.mod h1:BeucyB08Vb1G9tumVN3Vp/pyY4AMUnr9p7Rz7wJ7kAQ=
github.com/dolthub/vitess v0.0.0-20240110233415-e46007d964c0 h1:P8wb4dR5krirPa0swEJbEObc/I7GaAM/01nOnuQrl0c=
Expand Down
16 changes: 11 additions & 5 deletions testing/logictest/harness/doltgres_harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,25 @@ var _ logictest.Harness = &PostgresqlServerHarness{}

// sqllogictest harness for postgres databases.
type PostgresqlServerHarness struct {
dsn string
db *sql.DB
dsn string
db *sql.DB
timeout int64
}

// compile check for interface compliance
var _ logictest.Harness = &PostgresqlServerHarness{}

// NewPostgresqlHarness returns a new Postgres test harness for the data source name given. Panics if it cannot open a
// connection using the DSN.
func NewPostgresqlHarness(dsn string) *PostgresqlServerHarness {
func NewPostgresqlHarness(dsn string, t int64) *PostgresqlServerHarness {
db, err := sql.Open("pgx", dsn)
if err != nil {
panic(err)
}
return &PostgresqlServerHarness{
dsn: dsn,
db: db,
dsn: dsn,
db: db,
timeout: t,
}
}

Expand Down Expand Up @@ -100,6 +102,10 @@ func (h *PostgresqlServerHarness) ExecuteQuery(statement string) (schema string,
return schema, results, nil
}

func (h *PostgresqlServerHarness) GetTimeout() int64 {
return h.timeout
}

func (h *PostgresqlServerHarness) dropAllTables() error {
var rows *sql.Rows
var err error
Expand Down
9 changes: 8 additions & 1 deletion testing/logictest/harness/doltgres_server_harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,24 @@ type DoltgresHarness struct {
doltgresExec string
server *DoltgresServer
serverDir string
timeout int64 // in seconds
}

// NewDoltgresHarness returns a new Doltgres test harness for the data source name given.
// It starts doltgres server and handles every connection to it.
func NewDoltgresHarness(doltgresExec string) *DoltgresHarness {
func NewDoltgresHarness(doltgresExec string, t int64) *DoltgresHarness {
serverDir := prepareSqlLogicTestDBAndGetServerDir(context.Background(), doltgresExec)
logFile, err := os.OpenFile(harnessLogFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatal(err)
}
log.SetOutput(logFile)
logMsg("creating a new DoltgresHarness")

return &DoltgresHarness{
doltgresExec: doltgresExec,
serverDir: serverDir,
timeout: t,
}
}

Expand Down Expand Up @@ -131,6 +134,10 @@ func (h *DoltgresHarness) ExecuteQuery(statement string) (schema string, results
return schema, results, nil
}

func (h *DoltgresHarness) GetTimeout() int64 {
return h.timeout
}

func (h *DoltgresHarness) dropAllTables() error {
var rows *sql.Rows
var err error
Expand Down
13 changes: 4 additions & 9 deletions testing/logictest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@ import (
"encoding/json"
"flag"
"fmt"
"github.com/dolthub/sqllogictest/go/logictest"
"log"
"os"
"time"

"github.com/dolthub/sqllogictest/go/logictest"

"github.com/dolthub/doltgresql/testing/logictest/harness"
)

var resultFormat = flag.String("r", "json", "format of parsed results")
var withServer = flag.Bool("server", false, "format of parsed results")
var doltgres = flag.String("doltgres", "", "local doltgres binary")
var timeout = flag.Int64("timeout", 0, "set a timeout (in ms) for each test query")
var timeout = flag.Int64("timeout", 0, "set a timeout (in seconds) for each test query")

// Runs all sqllogictest test files (or directories containing them) given as arguments.
// Usage: $command (run|parse) [version] [file1.test dir1/ dir2/]
Expand All @@ -53,14 +51,11 @@ func main() {
if *doltgres == "" {
log.Fatal("Must supply --doltgres=<path to doltgres> with --server=true")
}
dh := harness.NewDoltgresHarness(*doltgres)
dh := harness.NewDoltgresHarness(*doltgres, *timeout)
defer dh.Close()
h = dh
} else {
h = harness.NewPostgresqlHarness("postgresql://postgres:password@localhost:5432/sqllogictest?sslmode=disable")
}
if *timeout != 0 {
logictest.SetTimeout(time.Duration(*timeout))
h = harness.NewPostgresqlHarness("postgresql://postgres:password@localhost:5432/sqllogictest?sslmode=disable", *timeout)
}
logictest.RunTestFiles(h, args[1:]...)
} else if args[0] == "parse" {
Expand Down

0 comments on commit ea4ada3

Please sign in to comment.