Skip to content

Commit cb4e54f

Browse files
committed
fix TestRegressionKikimr17104
1 parent b55b6e3 commit cb4e54f

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

tests/integration/database_sql_regression_test.go

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"errors"
1010
"fmt"
1111
"math/rand"
12-
"net/url"
1312
"os"
13+
"path"
1414
"strconv"
1515
"testing"
1616
"time"
@@ -81,14 +81,7 @@ func TestRegressionCloud109307(t *testing.T) {
8181
}
8282

8383
func TestRegressionKikimr17104(t *testing.T) {
84-
tablePath := "/database/sql/kikimr/17104/stream_query"
85-
if dsn, has := os.LookupEnv("YDB_CONNECTION_STRING"); !has {
86-
t.Errorf("expected YDB_CONNECTION_STRING environment variable")
87-
} else {
88-
u, err := url.Parse(dsn)
89-
require.NoError(t, err)
90-
tablePath = u.Path + tablePath
91-
}
84+
const tableRelativePath = "database/sql/kikimr/17104/big_table"
9285

9386
var (
9487
upsertRowsCount = 100000
@@ -100,16 +93,22 @@ func TestRegressionKikimr17104(t *testing.T) {
10093

10194
t.Run("data", func(t *testing.T) {
10295
t.Run("prepare", func(t *testing.T) {
103-
var db *sql.DB
96+
var (
97+
db *sql.DB
98+
tableAbsolutePath string
99+
)
104100
defer func() {
105101
if db != nil {
106102
_ = db.Close()
107103
}
108104
}()
109105
t.Run("connect", func(t *testing.T) {
110-
var err error
111-
db, err = sql.Open("ydb", os.Getenv("YDB_CONNECTION_STRING"))
106+
cc, err := ydb.Open(ctx, os.Getenv("YDB_CONNECTION_STRING"))
112107
require.NoError(t, err)
108+
connector, err := ydb.Connector(cc)
109+
require.NoError(t, err)
110+
db = sql.OpenDB(connector)
111+
tableAbsolutePath = path.Join(cc.Name(), tableRelativePath)
113112
})
114113
t.Run("scheme", func(t *testing.T) {
115114
var cc ydb.Connection
@@ -121,15 +120,15 @@ func TestRegressionKikimr17104(t *testing.T) {
121120
var tableExists bool
122121
t.Run("check_exists", func(t *testing.T) {
123122
var err error
124-
tableExists, err = sugar.IsTableExists(ctx, cc.Scheme(), tablePath)
123+
tableExists, err = sugar.IsTableExists(ctx, cc.Scheme(), tableAbsolutePath)
125124
require.NoError(t, err)
126125
})
127126
if tableExists {
128127
t.Run("drop", func(t *testing.T) {
129128
err := retry.Do(ydb.WithQueryMode(ctx, ydb.SchemeQueryMode), db,
130129
func(ctx context.Context, cc *sql.Conn) (err error) {
131130
_, err = cc.ExecContext(ctx,
132-
fmt.Sprintf("DROP TABLE `%s`", tablePath),
131+
fmt.Sprintf("DROP TABLE `%s`", tableAbsolutePath),
133132
)
134133
if err != nil {
135134
return err
@@ -144,7 +143,7 @@ func TestRegressionKikimr17104(t *testing.T) {
144143
err := retry.Do(ydb.WithQueryMode(ctx, ydb.SchemeQueryMode), db,
145144
func(ctx context.Context, cc *sql.Conn) (err error) {
146145
_, err = cc.ExecContext(ctx,
147-
fmt.Sprintf("CREATE TABLE `%s` (val Int32, PRIMARY KEY (val))", tablePath),
146+
fmt.Sprintf("CREATE TABLE `%s` (val Int32, PRIMARY KEY (val))", tableAbsolutePath),
148147
)
149148
if err != nil {
150149
return err
@@ -180,7 +179,7 @@ func TestRegressionKikimr17104(t *testing.T) {
180179
declares, err := sugar.GenerateDeclareSection(values)
181180
require.NoError(t, err)
182181
_, err = cc.ExecContext(ctx,
183-
declares+fmt.Sprintf("UPSERT INTO `%s` SELECT val FROM AS_TABLE($values);", tablePath),
182+
declares+fmt.Sprintf("UPSERT INTO `%s` SELECT val FROM AS_TABLE($values);", tableAbsolutePath),
184183
values,
185184
)
186185
if err != nil {
@@ -193,19 +192,22 @@ func TestRegressionKikimr17104(t *testing.T) {
193192
})
194193
})
195194
t.Run("scan", func(t *testing.T) {
196-
var db *sql.DB
195+
var (
196+
db *sql.DB
197+
tableAbsolutePath string
198+
)
197199
defer func() {
198200
if db != nil {
199201
_ = db.Close()
200202
}
201203
}()
202204
t.Run("connect", func(t *testing.T) {
203-
var err error
204205
cc, err := ydb.Open(ctx, os.Getenv("YDB_CONNECTION_STRING"))
205206
require.NoError(t, err)
206207
connector, err := ydb.Connector(cc, ydb.WithDefaultQueryMode(ydb.ScanQueryMode))
207208
require.NoError(t, err)
208209
db = sql.OpenDB(connector)
210+
tableAbsolutePath = path.Join(cc.Name(), tableRelativePath)
209211
})
210212
t.Run("query", func(t *testing.T) {
211213
var (
@@ -217,7 +219,7 @@ func TestRegressionKikimr17104(t *testing.T) {
217219
var rows *sql.Rows
218220
rowsCount = 0
219221
checkSum = 0
220-
rows, err = cc.QueryContext(ctx, fmt.Sprintf("SELECT val FROM `%s`", tablePath))
222+
rows, err = cc.QueryContext(ctx, fmt.Sprintf("SELECT val FROM `%s`", tableAbsolutePath))
221223
if err != nil {
222224
return err
223225
}

0 commit comments

Comments
 (0)