tests for close and add IsClosed() method (#659)
This commit is contained in:
parent
a5a917d477
commit
7c2d924794
|
@ -93,11 +93,15 @@ func (session *Session) Close() {
|
||||||
}
|
}
|
||||||
session.Tx = nil
|
session.Tx = nil
|
||||||
session.stmtCache = nil
|
session.stmtCache = nil
|
||||||
session.Init()
|
|
||||||
session.db = nil
|
session.db = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsClosed returns if session is closed
|
||||||
|
func (session *Session) IsClosed() bool {
|
||||||
|
return session.db == nil
|
||||||
|
}
|
||||||
|
|
||||||
func (session *Session) resetStatement() {
|
func (session *Session) resetStatement() {
|
||||||
if session.AutoResetStatement {
|
if session.AutoResetStatement {
|
||||||
session.Statement.Init()
|
session.Statement.Init()
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
// Copyright 2017 The Xorm Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package xorm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestClose(t *testing.T) {
|
||||||
|
assert.NoError(t, prepareEngine())
|
||||||
|
|
||||||
|
sess1 := testEngine.NewSession()
|
||||||
|
sess1.Close()
|
||||||
|
assert.True(t, sess1.IsClosed())
|
||||||
|
|
||||||
|
sess2 := testEngine.Where("a = ?", 1)
|
||||||
|
sess2.Close()
|
||||||
|
assert.True(t, sess2.IsClosed())
|
||||||
|
}
|
Loading…
Reference in New Issue