Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage: use connection string for postgres #7

Merged
merged 1 commit into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions gtfs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package gtfs_test

// Most tests in this package run against the in-memory and storage
// backends by default. If PostgresConnStr is set, they'll also run
// against postgres.

const (
PostgresConnStr = "" // "postgres://postgres:mysecretpassword@localhost:5432/gtfs?sslmode=disable"
)
2 changes: 0 additions & 2 deletions realtime_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ func TestRealtimeIntegrationNYCFerryDelaysOnER(t *testing.T) {
},
}, departures)

fmt.Println("Failure below")

// Makes sure delay got propagated to Dumbo.
//
// Minor note: the original schedule has this departing 11:13,
Expand Down
10 changes: 1 addition & 9 deletions realtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,9 @@ func staticAndReaderFromFiles(t *testing.T, backend string, files map[string][]s
s, err = storage.NewSQLiteStorage()
require.NoError(t, err)
} else if backend == "postgres" {
s, err = storage.NewPSQLStorage(storage.PSQLConfig{
Host: "localhost",
Port: 5432,
User: "postgres",
Password: "mysecretpassword",
DBName: "gtfs",
ClearDB: true,
})
s, err = storage.NewPSQLStorage(PostgresConnStr, true)
require.NoError(t, err)
} else {

t.Fatalf("Unknown backend: %s", backend)
}

Expand Down
31 changes: 16 additions & 15 deletions static_bench_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package gtfs
package gtfs_test

import (
"io/ioutil"
"testing"
"time"

"tidbyt.dev/gtfs"
"tidbyt.dev/gtfs/parse"
"tidbyt.dev/gtfs/storage"
)

func loadFeed(b *testing.B, backend string, filename string) *Static {
func loadFeed(b *testing.B, backend string, filename string) *gtfs.Static {
var s storage.Storage
var err error
if backend == "memory" {
Expand All @@ -20,14 +21,7 @@ func loadFeed(b *testing.B, backend string, filename string) *Static {
b.Error(err)
}
} else if backend == "postgres" {
s, err = storage.NewPSQLStorage(storage.PSQLConfig{
Host: "localhost",
Port: 5432,
User: "postgres",
Password: "mysecretpassword",
DBName: "gtfs",
ClearDB: false,
})
s, err = storage.NewPSQLStorage(PostgresConnStr, true)
if err != nil {
b.Error(err)
}
Expand Down Expand Up @@ -58,7 +52,7 @@ func loadFeed(b *testing.B, backend string, filename string) *Static {
b.Error(err)
}

static, err := NewStatic(reader, metadata)
static, err := gtfs.NewStatic(reader, metadata)
if err != nil {
b.Error(err)
}
Expand All @@ -83,7 +77,12 @@ func benchNearbyStops(b *testing.B, backend string) {
func benchDepartures(b *testing.B, backend string) {
static := loadFeed(b, backend, "testdata/caltrain_20160406.zip")

when := time.Date(2020, 2, 3, 8, 0, 0, 0, static.location)
tz, err := time.LoadLocation("America/Los_Angeles")
if err != nil {
b.Error(err)
}

when := time.Date(2020, 2, 3, 8, 0, 0, 0, tz)
window := 1 * time.Hour

stops, err := static.NearbyStops(40.734673, -73.989951, 0, nil)
Expand Down Expand Up @@ -118,8 +117,10 @@ func BenchmarkGTFSStatic(b *testing.B) {
b.Run(test.Name+"_sqlite", func(b *testing.B) {
test.Bench(b, "sqlite")
})
b.Run(test.Name+"_postgres", func(b *testing.B) {
test.Bench(b, "postgres")
})
if PostgresConnStr != "" {
b.Run(test.Name+"_postgres", func(b *testing.B) {
test.Bench(b, "postgres")
})
}
}
}
17 changes: 6 additions & 11 deletions static_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,7 @@ func loadFeed2(t *testing.T, backend string, filename string) (*gtfs.Static, sto
s, err = storage.NewSQLiteStorage()
require.NoError(t, err)
} else if backend == "postgres" {
s, err = storage.NewPSQLStorage(storage.PSQLConfig{
Host: "localhost",
Port: 5432,
User: "postgres",
Password: "mysecretpassword",
DBName: "gtfs",
ClearDB: true,
})
s, err = storage.NewPSQLStorage(PostgresConnStr, true)
require.NoError(t, err)
} else {
t.Fatalf("unknown backend %q", backend)
Expand Down Expand Up @@ -247,8 +240,10 @@ func TestStaticIntegration(t *testing.T) {
t.Run(test.Name+"_memory", func(t *testing.T) {
test.Test(t, "memory")
})
// t.Run(test.Name+"_postgres", func(t *testing.T) {
// test.Test(t, "postgres")
// })
if PostgresConnStr != "" {
t.Run(test.Name+"_postgres", func(t *testing.T) {
test.Test(t, "postgres")
})
}
}
}
Loading