Skip to content

Commit e409e01

Browse files
committed
added tests for check BAD_SESSION retry status
1 parent 8e89390 commit e409e01

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

internal/conn/error_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import (
55
"testing"
66

77
"github.com/stretchr/testify/require"
8+
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
9+
10+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/backoff"
11+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
812
)
913

1014
func TestNodeErrorError(t *testing.T) {
@@ -59,3 +63,17 @@ func TestNodeErrorAs(t *testing.T) {
5963
target2 := testType2Error{}
6064
require.False(t, errors.As(nodeErr, &target2))
6165
}
66+
67+
// https://github.com/ydb-platform/ydb-go-sdk/issues/1227
68+
func TestIssue1227NodeErrorUnwrapBadSession(t *testing.T) {
69+
nodeErr := xerrors.WithStackTrace(newConnError(1, "localhost:1234", xerrors.Operation(
70+
xerrors.WithStatusCode(Ydb.StatusIds_BAD_SESSION),
71+
)))
72+
73+
code, errType, backoffType, invalidObject := xerrors.Check(nodeErr)
74+
75+
require.EqualValues(t, Ydb.StatusIds_BAD_SESSION, code)
76+
require.EqualValues(t, xerrors.TypeRetryable, errType)
77+
require.EqualValues(t, backoff.TypeNoBackoff, backoffType)
78+
require.True(t, invalidObject)
79+
}

tests/integration/helpers_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ func (t *testLogger) Log(ctx context.Context, msg string, fields ...log.Field) {
369369

370370
func (t *testLogger) flush() {
371371
t.m.WithLock(func() {
372+
t.test.Helper()
372373
t.closed = true
373374
message := "\n" + strings.Join(t.messages, "\n")
374375
t.test.Log(message)

tests/integration/table_regress_test.go renamed to tests/integration/table_regression_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import (
1111
"testing"
1212

1313
"github.com/stretchr/testify/require"
14+
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
1415

16+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
1517
"github.com/ydb-platform/ydb-go-sdk/v3/table"
1618
"github.com/ydb-platform/ydb-go-sdk/v3/table/result"
1719
"github.com/ydb-platform/ydb-go-sdk/v3/table/result/indexed"
@@ -93,3 +95,21 @@ func TestIssueWideResultWithUnwrap(t *testing.T) {
9395
}
9496
})
9597
}
98+
99+
// https://github.com/ydb-platform/ydb-go-sdk/issues/1227
100+
func TestRegressionIssue1227RetryBadSession(t *testing.T) {
101+
var (
102+
scope = newScope(t)
103+
cnt = 0
104+
)
105+
err := scope.Driver().Table().Do(scope.Ctx, func(ctx context.Context, s table.Session) error {
106+
cnt++
107+
if cnt < 100 {
108+
return xerrors.WithStackTrace(xerrors.Operation(xerrors.WithStatusCode(Ydb.StatusIds_BAD_SESSION)))
109+
}
110+
111+
return nil
112+
})
113+
require.NoError(t, err)
114+
require.EqualValues(t, 100, cnt)
115+
}

0 commit comments

Comments
 (0)