Skip to content

Commit 7f634e7

Browse files
committed
port of go-sql-server-driver tests from dolt
1 parent 498df5f commit 7f634e7

56 files changed

Lines changed: 9472 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2024 Dolthub, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package main
16+
17+
import "testing"
18+
19+
// TestAutoGC is ported from Dolt's auto_gc_test.go. It exercises the server's
20+
// automatic garbage-collection behavior under load. Doltgres currently
21+
// disables automatic GC (servercfg DoltgresAutoGCBehavior.Enable() returns
22+
// false and there is no dolt_auto_gc_enabled / auto_gc_behavior config), so
23+
// this test is skipped until auto-GC is supported.
24+
//
25+
// The full test logic lives in the Dolt source at
26+
// integration-tests/go-sql-server-driver/auto_gc_test.go and should be ported
27+
// once Doltgres supports automatic GC.
28+
func TestAutoGC(t *testing.T) {
29+
t.Skip("automatic GC is not yet implemented in Doltgres (AutoGCBehavior.Enable() == false)")
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2024 Dolthub, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package main
16+
17+
import "testing"
18+
19+
// TestCloneNoConjoin is ported from Dolt's clone_no_conjoin_test.go. It clones
20+
// a database through a running sql-server and asserts the clone does not
21+
// trigger a conjoin of table files. This depends on Dolt's remotes/clone
22+
// behavior and on inspecting on-disk table-file/conjoin storage internals,
23+
// neither of which is available from the doltgres test driver yet (the
24+
// remotes API is not implemented in Doltgres).
25+
//
26+
// The full test logic lives in the Dolt source at
27+
// integration-tests/go-sql-server-driver/clone_no_conjoin_test.go.
28+
func TestCloneNoConjoin(t *testing.T) {
29+
t.Skip("clone/conjoin storage internals and the remotes API are not yet supported in Doltgres")
30+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
// Copyright 2026 Dolthub, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package main
16+
17+
import (
18+
"context"
19+
"fmt"
20+
"strings"
21+
"sync/atomic"
22+
"testing"
23+
24+
"github.com/stretchr/testify/require"
25+
"golang.org/x/sync/errgroup"
26+
27+
driver "github.com/dolthub/doltgresql/integration-tests/go-sql-server-driver/driver"
28+
)
29+
30+
// TestConcurrentDropDatabase is a regression test for #10692.
31+
//
32+
// A lock-ordering bug between *DatabaseProvider and *DoltSession meant that
33+
// DROP DATABASE during concurrency could cause the DatabaseProvider to
34+
// deadlock and the server databases to become unavailable.
35+
func TestConcurrentDropDatabase(t *testing.T) {
36+
t.Parallel()
37+
ports := newPorts(t)
38+
u, err := driver.NewDoltUser()
39+
require.NoError(t, err)
40+
t.Cleanup(func() {
41+
u.Cleanup()
42+
})
43+
44+
rs, err := u.MakeRepoStore()
45+
require.NoError(t, err)
46+
47+
_, err = rs.MakeRepo("concurrent_drop_database_test")
48+
require.NoError(t, err)
49+
50+
srvSettings := &driver.Server{
51+
Args: []string{},
52+
DynamicPort: "server_port",
53+
}
54+
server := StartServer(t, rs, "concurrent_drop_database_test", srvSettings, ports)
55+
56+
db, err := server.DB(driver.Connection{})
57+
require.NoError(t, err)
58+
db.SetMaxIdleConns(0)
59+
defer func() {
60+
require.NoError(t, db.Close())
61+
}()
62+
ctx := t.Context()
63+
64+
eg, ctx := errgroup.WithContext(ctx)
65+
var numcreates int32 = 0
66+
const numWriters = 8
67+
const numDatabasesPerWriter = 12
68+
startCh := make(chan struct{})
69+
readyCh := make(chan struct{})
70+
for i := range numWriters {
71+
eg.Go(func() error {
72+
conn, err := db.Conn(ctx)
73+
if err != nil {
74+
return err
75+
}
76+
defer conn.Close()
77+
select {
78+
case readyCh <- struct{}{}:
79+
case <-ctx.Done():
80+
return nil
81+
}
82+
select {
83+
case <-startCh:
84+
case <-ctx.Done():
85+
return nil
86+
}
87+
for j := range numDatabasesPerWriter {
88+
if ctx.Err() != nil {
89+
return context.Cause(ctx)
90+
}
91+
database := fmt.Sprintf("db%08d%08d", i, j)
92+
_, err := conn.ExecContext(ctx, "CREATE DATABASE "+database)
93+
if err != nil {
94+
return err
95+
}
96+
atomic.AddInt32(&numcreates, 1)
97+
_, err = conn.ExecContext(ctx, "DROP DATABASE "+database)
98+
if err != nil {
99+
return err
100+
}
101+
}
102+
return nil
103+
})
104+
}
105+
for range numWriters {
106+
select {
107+
case <-readyCh:
108+
case <-ctx.Done():
109+
// This will fail.
110+
require.NoError(t, eg.Wait())
111+
t.FailNow()
112+
}
113+
}
114+
close(startCh)
115+
require.NoError(t, eg.Wait())
116+
ctx = t.Context()
117+
conn, err := db.Conn(ctx)
118+
require.NoError(t, err)
119+
defer conn.Close()
120+
rows, err := conn.QueryContext(ctx, "SELECT datname FROM pg_database")
121+
require.NoError(t, err)
122+
defer rows.Close()
123+
var databases []string
124+
for rows.Next() {
125+
var db string
126+
err = rows.Scan(&db)
127+
require.NoError(t, err)
128+
databases = append(databases, db)
129+
}
130+
require.NoError(t, rows.Err())
131+
// The provider must still be functional, and none of the created-and-dropped
132+
// databases should remain. The test database must still be present.
133+
require.Contains(t, databases, "concurrent_drop_database_test")
134+
for _, name := range databases {
135+
require.False(t, strings.HasPrefix(name, "db0000"),
136+
"created-and-dropped database %q should not remain", name)
137+
}
138+
t.Logf("created and dropped %d databases", numcreates)
139+
}

0 commit comments

Comments
 (0)