Skip to content

Commit c2bddfc

Browse files
committed
add connection reset and fix test log msgs
1 parent ac20594 commit c2bddfc

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

internal/xsql/conn.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ var (
8080
_ driver.QueryerContext = &conn{}
8181
_ driver.Pinger = &conn{}
8282
_ driver.NamedValueChecker = &conn{}
83+
_ driver.SessionResetter = &conn{}
8384
)
8485

8586
func newConn(c *Connector, s table.ClosableSession, opts ...connOption) *conn {
@@ -343,3 +344,13 @@ func (c *conn) BeginTx(ctx context.Context, txOptions driver.TxOptions) (_ drive
343344
}
344345
return c.currentTx, nil
345346
}
347+
348+
func (c *conn) ResetSession(ctx context.Context) error {
349+
if c.currentTx != nil {
350+
_ = c.currentTx.Rollback()
351+
}
352+
if c.isClosed() {
353+
return errClosedConn
354+
}
355+
return nil
356+
}

sql_e2e_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func TestDatabaseSql(t *testing.T) {
163163
return nil
164164
}, retry.WithDoTxRetryOptions(retry.WithIdempotent(true)))
165165
if err != nil {
166-
t.Fatalf("begin tx failed: %v\n", err)
166+
t.Fatalf("do tx failed: %v\n", err)
167167
}
168168
err = retry.DoTx(ctx, db,
169169
func(ctx context.Context, tx *sql.Tx) error {
@@ -198,7 +198,7 @@ func TestDatabaseSql(t *testing.T) {
198198
}),
199199
)
200200
if err != nil {
201-
t.Fatalf("begin tx failed: %v\n", err)
201+
t.Fatalf("do tx failed: %v\n", err)
202202
}
203203
})
204204
}

0 commit comments

Comments
 (0)