Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1378)

Delta Between Two Patch Sets: src/pkg/database/sql/fakedb_test.go

Issue 14611045: code review 14611045: database/sql: Fix connection leak and potential deadlock (Closed)
Left Patch Set: diff -r 062f1f0ea8ba https://code.google.com/p/go Created 10 years, 5 months ago
Right Patch Set: diff -r 9d0d95344a6c https://code.google.com/p/go Created 10 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | src/pkg/database/sql/sql.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2011 The Go Authors. All rights reserved. 1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package sql 5 package sql
6 6
7 import ( 7 import (
8 "database/sql/driver" 8 "database/sql/driver"
9 "errors" 9 "errors"
10 "fmt" 10 "fmt"
(...skipping 20 matching lines...) Expand all
31 // where types are: "string", [u]int{8,16,32,64}, "bool" 31 // where types are: "string", [u]int{8,16,32,64}, "bool"
32 // INSERT|<tablename>|col=val,col2=val2,col3=? 32 // INSERT|<tablename>|col=val,col2=val2,col3=?
33 // SELECT|<tablename>|projectcol1,projectcol2|filtercol=?,filtercol2=? 33 // SELECT|<tablename>|projectcol1,projectcol2|filtercol=?,filtercol2=?
34 // 34 //
35 // When opening a fakeDriver's database, it starts empty with no 35 // When opening a fakeDriver's database, it starts empty with no
36 // tables. All tables and data are stored in memory only. 36 // tables. All tables and data are stored in memory only.
37 type fakeDriver struct { 37 type fakeDriver struct {
38 mu sync.Mutex // guards 3 following fields 38 mu sync.Mutex // guards 3 following fields
39 openCount int // conn opens 39 openCount int // conn opens
40 closeCount int // conn closes 40 closeCount int // conn closes
41 waitCh chan struct{}
42 waitingCh chan struct{}
41 dbs map[string]*fakeDB 43 dbs map[string]*fakeDB
42 } 44 }
43 45
44 type fakeDB struct { 46 type fakeDB struct {
45 name string 47 name string
46 48
47 mu sync.Mutex 49 mu sync.Mutex
48 free []*fakeConn 50 free []*fakeConn
49 tables map[string]*table 51 tables map[string]*table
50 badConn bool 52 badConn bool
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 140
139 db := d.getDB(name) 141 db := d.getDB(name)
140 142
141 d.mu.Lock() 143 d.mu.Lock()
142 d.openCount++ 144 d.openCount++
143 d.mu.Unlock() 145 d.mu.Unlock()
144 conn := &fakeConn{db: db} 146 conn := &fakeConn{db: db}
145 147
146 if len(parts) >= 2 && parts[1] == "badConn" { 148 if len(parts) >= 2 && parts[1] == "badConn" {
147 conn.bad = true 149 conn.bad = true
150 }
151 if d.waitCh != nil {
152 d.waitingCh <- struct{}{}
153 <-d.waitCh
148 } 154 }
149 return conn, nil 155 return conn, nil
150 } 156 }
151 157
152 func (d *fakeDriver) getDB(name string) *fakeDB { 158 func (d *fakeDriver) getDB(name string) *fakeDB {
153 d.mu.Lock() 159 d.mu.Lock()
154 defer d.mu.Unlock() 160 defer d.mu.Unlock()
155 if d.dbs == nil { 161 if d.dbs == nil {
156 d.dbs = make(map[string]*fakeDB) 162 d.dbs = make(map[string]*fakeDB)
157 } 163 }
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 // TODO(coopernurse): add type-specific converter 764 // TODO(coopernurse): add type-specific converter
759 return driver.NotNull{Converter: driver.DefaultParameterConverte r} 765 return driver.NotNull{Converter: driver.DefaultParameterConverte r}
760 case "nullfloat64": 766 case "nullfloat64":
761 // TODO(coopernurse): add type-specific converter 767 // TODO(coopernurse): add type-specific converter
762 return driver.Null{Converter: driver.DefaultParameterConverter} 768 return driver.Null{Converter: driver.DefaultParameterConverter}
763 case "datetime": 769 case "datetime":
764 return driver.DefaultParameterConverter 770 return driver.DefaultParameterConverter
765 } 771 }
766 panic("invalid fakedb column type of " + typ) 772 panic("invalid fakedb column type of " + typ)
767 } 773 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b