Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
Merge branch 'barnacle'
Browse files Browse the repository at this point in the history
  • Loading branch information
sougou committed Oct 31, 2013
2 parents 9ded2b3 + f6eaac8 commit 444b32f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions go/vt/vtgate/sandbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package vtgate

import (
"fmt"
"sync"
"time"

mproto "github.com/youtube/vitess/go/mysql/proto"
Expand All @@ -22,6 +23,9 @@ func init() {
}

var (
// Use sandmu to access the variables below
sandmu sync.Mutex

// endPointCounter tracks how often GetEndPoints was called
endPointCounter int

Expand All @@ -33,12 +37,16 @@ var (

// dialMustFail specifies how often sandboxDialer must fail before succeeding
dialMustFail int
)

var (
// transaction id generator
transactionId sync2.AtomicInt64
)

func resetSandbox() {
sandmu.Lock()
defer sandmu.Unlock()
testConns = make(map[string]TabletConn)
endPointCounter = 0
dialCounter = 0
Expand All @@ -49,6 +57,8 @@ type sandboxTopo struct {
}

func (sct *sandboxTopo) GetEndPoints(cell, keyspace, shard string, tabletType topo.TabletType) (*topo.EndPoints, error) {
sandmu.Lock()
defer sandmu.Unlock()
endPointCounter++
if endPointMustFail > 0 {
endPointMustFail--
Expand All @@ -62,6 +72,8 @@ func (sct *sandboxTopo) GetEndPoints(cell, keyspace, shard string, tabletType to
var testConns map[string]TabletConn

func sandboxDialer(addr, keyspace, shard, username, password string, encrypted bool) (TabletConn, error) {
sandmu.Lock()
defer sandmu.Unlock()
dialCounter++
if dialMustFail > 0 {
dialMustFail--
Expand Down

0 comments on commit 444b32f

Please sign in to comment.