-
Notifications
You must be signed in to change notification settings - Fork 372
Expand file tree
/
Copy pathpostgres_test.go
More file actions
96 lines (79 loc) · 2.83 KB
/
postgres_test.go
File metadata and controls
96 lines (79 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//go:build ci && docker && postgres
package postgres
import (
"fmt"
"os"
"testing"
"time"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/stretchr/testify/require"
"github.com/authzed/spicedb/internal/datastore/postgres/common"
"github.com/authzed/spicedb/internal/datastore/postgres/version"
testdatastore "github.com/authzed/spicedb/internal/testserver/datastore"
)
func postgresTestVersion() string {
ver := os.Getenv("POSTGRES_TEST_VERSION")
if ver != "" {
return ver
}
return version.LatestTestedPostgresVersion
}
var postgresConfig = postgresTestConfig{"head", "", postgresTestVersion(), false}
func TestPostgresDatastore(t *testing.T) {
testPostgresDatastore(t, postgresConfig)
}
func TestPostgresDatastoreWithoutCommitTimestamps(t *testing.T) {
testPostgresDatastoreWithoutCommitTimestamps(t, postgresConfig)
}
func TestPostgresDatastoreGC(t *testing.T) {
config := postgresConfig
pgbouncerStr := ""
if config.pgbouncer {
pgbouncerStr = "pgbouncer-"
}
t.Run(fmt.Sprintf("%spostgres-gc-%s-%s-%s", pgbouncerStr, config.pgVersion, config.targetMigration, config.migrationPhase), func(t *testing.T) {
b := testdatastore.RunPostgresForTesting(t, "", config.targetMigration, config.pgVersion, config.pgbouncer)
t.Run("GarbageCollection", createDatastoreTest(
b,
GarbageCollectionTest,
RevisionQuantization(0),
GCWindow(1*time.Millisecond),
GCInterval(veryLargeGCInterval),
WatchBufferLength(1),
MigrationPhase(config.migrationPhase),
))
t.Run("GarbageCollectionByTime", createDatastoreTest(
b,
GarbageCollectionByTimeTest,
RevisionQuantization(0),
GCWindow(1*time.Millisecond),
GCInterval(veryLargeGCInterval),
WatchBufferLength(1),
MigrationPhase(config.migrationPhase),
))
t.Run("ChunkedGarbageCollection", createDatastoreTest(
b,
ChunkedGarbageCollectionTest,
RevisionQuantization(0),
GCWindow(1*time.Millisecond),
GCInterval(veryLargeGCInterval),
WatchBufferLength(1),
MigrationPhase(config.migrationPhase),
WithRevisionHeartbeat(false),
))
})
}
func TestDefaultQueryExecMode(t *testing.T) {
parsedConfig, err := pgxpool.ParseConfig("postgres://username:password@localhost:5432/dbname")
require.NoError(t, err)
require.Equal(t, pgx.QueryExecModeCacheStatement, parsedConfig.ConnConfig.DefaultQueryExecMode)
common.ConfigureDefaultQueryExecMode(parsedConfig.ConnConfig)
require.Equal(t, pgx.QueryExecModeExec, parsedConfig.ConnConfig.DefaultQueryExecMode)
}
func TestDefaultQueryExecModeOverridden(t *testing.T) {
parsedConfig, err := pgxpool.ParseConfig("postgres://username:password@localhost:5432/dbname?default_query_exec_mode=cache_statement")
require.NoError(t, err)
common.ConfigureDefaultQueryExecMode(parsedConfig.ConnConfig)
require.Equal(t, pgx.QueryExecModeCacheStatement, parsedConfig.ConnConfig.DefaultQueryExecMode)
}