Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion go/mysql/fakesqldb/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ func (db *DB) Close() {
db.listener.Close()
db.acceptWG.Wait()

db.WaitForClose(250 * time.Millisecond)
db.CloseAllConnections()

tmpDir := path.Dir(db.socketFile)
Expand Down
46 changes: 14 additions & 32 deletions go/vt/vttablet/tabletserver/tx_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,15 @@ func TestTxEngineClose(t *testing.T) {
config := tabletenv.NewDefaultConfig()
config.DB = newDBConfigs(db)
config.TxPool.Size = 10
config.Oltp.TxTimeoutSeconds = 1
config.Oltp.TxTimeoutSeconds = 0.1
config.ShutdownGracePeriodSeconds = 0
te := NewTxEngine(tabletenv.NewEnv(config, "TabletServerTest"))

// Normal close.
te.open()
start := time.Now()
te.shutdown(false)
if diff := time.Since(start); diff > 500*time.Millisecond {
t.Errorf("Close time: %v, must be under 0.5s", diff)
}
assert.Greater(t, int64(50*time.Millisecond), int64(time.Since(start)))

// Normal close with timeout wait.
te.open()
Expand All @@ -66,9 +64,7 @@ func TestTxEngineClose(t *testing.T) {
c.Unlock()
start = time.Now()
te.shutdown(false)
if diff := time.Since(start); diff < 500*time.Millisecond {
t.Errorf("Close time: %v, must be over 0.5s", diff)
}
assert.Less(t, int64(50*time.Millisecond), int64(time.Since(start)))

// Immediate close.
te.open()
Expand All @@ -79,49 +75,35 @@ func TestTxEngineClose(t *testing.T) {
c.Unlock()
start = time.Now()
te.shutdown(true)
if diff := time.Since(start); diff > 500*time.Millisecond {
t.Errorf("Close time: %v, must be under 0.5s", diff)
}
assert.Greater(t, int64(50*time.Millisecond), int64(time.Since(start)))

// Normal close with short grace period.
te.shutdownGracePeriod = 250 * time.Millisecond
te.shutdownGracePeriod = 25 * time.Millisecond
te.open()
c, _, err = te.txPool.Begin(ctx, &querypb.ExecuteOptions{}, false, 0)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
c.Unlock()
start = time.Now()
te.shutdown(false)
if diff := time.Since(start); diff > 500*time.Millisecond {
t.Errorf("Close time: %v, must be under 0.5s", diff)
}
if diff := time.Since(start); diff < 250*time.Millisecond {
t.Errorf("Close time: %v, must be over 0.25s", diff)
}
assert.Less(t, int64(1*time.Millisecond), int64(time.Since(start)))
assert.Greater(t, int64(50*time.Millisecond), int64(time.Since(start)))

// Normal close with short grace period, but pool gets empty early.
te.shutdownGracePeriod = 250 * time.Millisecond
te.shutdownGracePeriod = 25 * time.Millisecond
te.open()
c, _, err = te.txPool.Begin(ctx, &querypb.ExecuteOptions{}, false, 0)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
c.Unlock()
go func() {
time.Sleep(100 * time.Millisecond)
time.Sleep(10 * time.Millisecond)
_, err := te.txPool.GetAndLock(c.ID(), "return")
assert.NoError(t, err)
te.txPool.RollbackAndRelease(ctx, c)
}()
start = time.Now()
te.shutdown(false)
if diff := time.Since(start); diff > 250*time.Millisecond {
t.Errorf("Close time: %v, must be under 0.25s", diff)
}
if diff := time.Since(start); diff < 100*time.Millisecond {
t.Errorf("Close time: %v, must be over 0.1", diff)
}
assert.Less(t, int64(10*time.Millisecond), int64(time.Since(start)))
assert.Greater(t, int64(25*time.Millisecond), int64(time.Since(start)))

// Immediate close, but connection is in use.
te.open()
Expand Down Expand Up @@ -511,7 +493,7 @@ func setupTxEngine(db *fakesqldb.DB) *TxEngine {
config := tabletenv.NewDefaultConfig()
config.DB = newDBConfigs(db)
config.TxPool.Size = 10
config.Oltp.TxTimeoutSeconds = 1
config.Oltp.TxTimeoutSeconds = 0.1
config.ShutdownGracePeriodSeconds = 0
te := NewTxEngine(tabletenv.NewEnv(config, "TabletServerTest"))
return te
Expand Down