/
server.go
714 lines (601 loc) · 20.7 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
/*
Copyright 2019 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package fakesqldb provides a MySQL server for tests.
package fakesqldb
import (
"errors"
"fmt"
"io/ioutil"
"os"
"path"
"regexp"
"strings"
"sync"
"testing"
"time"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/vt/dbconfigs"
querypb "vitess.io/vitess/go/vt/proto/query"
)
const appendEntry = -1
// DB is a fake database and all its methods are thread safe. It
// creates a mysql.Listener and implements the mysql.Handler
// interface. We use a Unix socket to connect to the database, as
// this is the most common way for clients to connect to MySQL. This
// impacts the error codes we're getting back: when the server side is
// closed, the client queries will return CRServerGone(2006) when sending
// the data, as opposed to CRServerLost(2013) when reading the response.
type DB struct {
// Fields set at construction time.
// t is our testing.TB instance
t testing.TB
// listener is our mysql.Listener.
listener *mysql.Listener
// socketFile is the path to the unix socket file.
socketFile string
// acceptWG is set when we listen, and can be waited on to
// make sure we don't accept any more.
acceptWG sync.WaitGroup
// orderMatters is set when the query order matters.
orderMatters bool
// Fields set at runtime.
// mu protects all the following fields.
mu sync.Mutex
// name is the name of this DB. Set to 'fakesqldb' by default.
// Use SetName() to change.
name string
// isConnFail trigger a panic in the connection handler.
isConnFail bool
// connDelay causes a sleep in the connection handler
connDelay time.Duration
// shouldClose, if true, tells ComQuery() to close the connection when
// processing the next query. This will trigger a MySQL client error with
// errno 2013 ("server lost").
shouldClose bool
// AllowAll: if set to true, ComQuery returns an empty result
// for all queries. This flag is used for benchmarking.
AllowAll bool
// Handler: interface that allows a caller to override the query handling
// implementation. By default it points to the DB itself
Handler QueryHandler
// This next set of fields is used when ordering of the queries doesn't
// matter.
// data maps tolower(query) to a result.
data map[string]*ExpectedResult
// rejectedData maps tolower(query) to an error.
rejectedData map[string]error
// patternData is a list of regexp to results.
patternData []exprResult
// queryCalled keeps track of how many times a query was called.
queryCalled map[string]int
// querylog keeps track of all called queries
querylog []string
// This next set of fields is used when ordering of the queries matters.
// expectedExecuteFetch is the array of expected queries.
expectedExecuteFetch []ExpectedExecuteFetch
// expectedExecuteFetchIndex is the current index of the query.
expectedExecuteFetchIndex int
// Infinite is true when executed queries beyond our expectation list
// should respond with the last entry from the list.
infinite bool
// connections tracks all open connections.
// The key for the map is the value of mysql.Conn.ConnectionID.
connections map[uint32]*mysql.Conn
// queryPatternUserCallback stores optional callbacks when a query with a pattern is called
queryPatternUserCallback map[*regexp.Regexp]func(string)
}
// QueryHandler is the interface used by the DB to simulate executed queries
type QueryHandler interface {
HandleQuery(*mysql.Conn, string, func(*sqltypes.Result) error) error
}
// ExpectedResult holds the data for a matched query.
type ExpectedResult struct {
*sqltypes.Result
// BeforeFunc() is synchronously called before the server returns the result.
BeforeFunc func()
}
type exprResult struct {
expr *regexp.Regexp
result *sqltypes.Result
err string
}
// ExpectedExecuteFetch defines for an expected query the to be faked output.
// It is used for ordered expected output.
type ExpectedExecuteFetch struct {
Query string
QueryResult *sqltypes.Result
Error error
// AfterFunc is a callback which is executed while the query
// is executed i.e., before the fake responds to the client.
AfterFunc func()
}
// New creates a server, and starts listening.
func New(t testing.TB) *DB {
// Pick a path for our socket.
socketDir, err := ioutil.TempDir("", "fakesqldb")
if err != nil {
t.Fatalf("ioutil.TempDir failed: %v", err)
}
socketFile := path.Join(socketDir, "fakesqldb.sock")
// Create our DB.
db := &DB{
t: t,
socketFile: socketFile,
name: "fakesqldb",
data: make(map[string]*ExpectedResult),
rejectedData: make(map[string]error),
queryCalled: make(map[string]int),
connections: make(map[uint32]*mysql.Conn),
queryPatternUserCallback: make(map[*regexp.Regexp]func(string)),
}
db.Handler = db
authServer := &mysql.AuthServerNone{}
// Start listening.
db.listener, err = mysql.NewListener("unix", socketFile, authServer, db, 0, 0, false)
if err != nil {
t.Fatalf("NewListener failed: %v", err)
}
db.acceptWG.Add(1)
go func() {
defer db.acceptWG.Done()
db.listener.Accept()
}()
// Return the db.
return db
}
// SetName sets the name of the DB. to differentiate them in tests if needed.
func (db *DB) SetName(name string) *DB {
db.mu.Lock()
defer db.mu.Unlock()
db.name = name
return db
}
// OrderMatters sets the orderMatters flag.
func (db *DB) OrderMatters() *DB {
db.mu.Lock()
defer db.mu.Unlock()
db.orderMatters = true
return db
}
// Close closes the Listener and waits for it to stop accepting.
// It then closes all connections, and cleans up the temporary directory.
func (db *DB) Close() {
db.listener.Close()
db.acceptWG.Wait()
db.CloseAllConnections()
tmpDir := path.Dir(db.socketFile)
os.RemoveAll(tmpDir)
}
// CloseAllConnections can be used to provoke MySQL client errors for open
// connections.
// Make sure to call WaitForClose() as well.
func (db *DB) CloseAllConnections() {
db.mu.Lock()
defer db.mu.Unlock()
for _, c := range db.connections {
c.Close()
}
}
// WaitForClose should be used after CloseAllConnections() is closed and
// you want to provoke a MySQL client error with errno 2006.
//
// If you don't call this function and execute the next query right away, you
// will very likely see errno 2013 instead due to timing issues.
// That's because the following can happen:
//
// 1. vttablet MySQL client is able to send the query to this fake server.
// 2. The fake server sees the query and calls the ComQuery() callback.
// 3. The fake server tries to write the response back on the connection.
// => This will finally fail because the connection is already closed.
// In this example, the client would have been able to send off the query and
// therefore return errno 2013 ("server lost").
// Instead, if step 1 already fails, the client returns errno 2006 ("gone away").
// By waiting for the connections to close, you make sure of that.
func (db *DB) WaitForClose(timeout time.Duration) error {
start := time.Now()
for {
db.mu.Lock()
count := len(db.connections)
db.mu.Unlock()
if count == 0 {
return nil
}
if d := time.Since(start); d > timeout {
return fmt.Errorf("connections were not correctly closed after %v: %v are left", d, count)
}
time.Sleep(1 * time.Microsecond)
}
}
// ConnParams returns the ConnParams to connect to the DB.
func (db *DB) ConnParams() dbconfigs.Connector {
return dbconfigs.New(&mysql.ConnParams{
UnixSocket: db.socketFile,
Uname: "user1",
Pass: "password1",
Charset: "utf8",
})
}
// ConnParamsWithUname returns ConnParams to connect to the DB with the Uname set to the provided value.
func (db *DB) ConnParamsWithUname(uname string) dbconfigs.Connector {
return dbconfigs.New(&mysql.ConnParams{
UnixSocket: db.socketFile,
Uname: uname,
Pass: "password1",
Charset: "utf8",
})
}
//
// mysql.Handler interface
//
// NewConnection is part of the mysql.Handler interface.
func (db *DB) NewConnection(c *mysql.Conn) {
db.mu.Lock()
defer db.mu.Unlock()
if db.isConnFail {
panic(fmt.Errorf("simulating a connection failure"))
}
if db.connDelay != 0 {
time.Sleep(db.connDelay)
}
if conn, ok := db.connections[c.ConnectionID]; ok {
db.t.Fatalf("BUG: connection with id: %v is already active. existing conn: %v new conn: %v", c.ConnectionID, conn, c)
}
db.connections[c.ConnectionID] = c
}
// ConnectionClosed is part of the mysql.Handler interface.
func (db *DB) ConnectionClosed(c *mysql.Conn) {
db.mu.Lock()
defer db.mu.Unlock()
if _, ok := db.connections[c.ConnectionID]; !ok {
panic(fmt.Errorf("BUG: Cannot delete connection from list of open connections because it is not registered. ID: %v Conn: %v", c.ConnectionID, c))
}
delete(db.connections, c.ConnectionID)
}
// ComQuery is part of the mysql.Handler interface.
func (db *DB) ComQuery(c *mysql.Conn, query string, callback func(*sqltypes.Result) error) error {
return db.Handler.HandleQuery(c, query, callback)
}
// WarningCount is part of the mysql.Handler interface.
func (db *DB) WarningCount(c *mysql.Conn) uint16 {
return 0
}
// HandleQuery is the default implementation of the QueryHandler interface
func (db *DB) HandleQuery(c *mysql.Conn, query string, callback func(*sqltypes.Result) error) error {
if db.AllowAll {
return callback(&sqltypes.Result{})
}
if db.orderMatters {
result, err := db.comQueryOrdered(query)
if err != nil {
return err
}
return callback(result)
}
key := strings.ToLower(query)
db.mu.Lock()
defer db.mu.Unlock()
db.queryCalled[key]++
db.querylog = append(db.querylog, key)
// Check if we should close the connection and provoke errno 2013.
if db.shouldClose {
c.Close()
//log error
if err := callback(&sqltypes.Result{}); err != nil {
log.Errorf("callback failed : %v", err)
}
return nil
}
// Using special handling for 'SET NAMES utf8'. The driver
// may send this at connection time, and we don't want it to
// interfere.
if key == "set names utf8" {
//log error
if err := callback(&sqltypes.Result{}); err != nil {
log.Errorf("callback failed : %v", err)
}
return nil
}
// check if we should reject it.
if err, ok := db.rejectedData[key]; ok {
return err
}
// Check explicit queries from AddQuery().
result, ok := db.data[key]
if ok {
if f := result.BeforeFunc; f != nil {
f()
}
return callback(result.Result)
}
// Check query patterns from AddQueryPattern().
for _, pat := range db.patternData {
if pat.expr.MatchString(query) {
userCallback, ok := db.queryPatternUserCallback[pat.expr]
if ok {
userCallback(query)
}
if pat.err != "" {
return fmt.Errorf(pat.err)
}
return callback(pat.result)
}
}
// Nothing matched.
return fmt.Errorf("query: '%s' is not supported on %v", query, db.name)
}
func (db *DB) comQueryOrdered(query string) (*sqltypes.Result, error) {
db.mu.Lock()
defer db.mu.Unlock()
index := db.expectedExecuteFetchIndex
if db.infinite && index == len(db.expectedExecuteFetch) {
// Although we already executed all queries, we'll continue to answer the
// last one in the infinite mode.
index--
}
if index >= len(db.expectedExecuteFetch) {
db.t.Errorf("%v: got unexpected out of bound fetch: %v >= %v", db.name, index, len(db.expectedExecuteFetch))
return nil, errors.New("unexpected out of bound fetch")
}
entry := db.expectedExecuteFetch[index]
db.expectedExecuteFetchIndex++
// If the infinite mode is on, reverse the increment and keep the index at
// len(db.expectedExecuteFetch).
if db.infinite && db.expectedExecuteFetchIndex > len(db.expectedExecuteFetch) {
db.expectedExecuteFetchIndex--
}
if entry.AfterFunc != nil {
defer entry.AfterFunc()
}
expected := entry.Query
if strings.HasSuffix(expected, "*") {
if !strings.HasPrefix(query, expected[0:len(expected)-1]) {
db.t.Errorf("%v: got unexpected query start (index=%v): %v != %v", db.name, index, query, expected)
}
} else {
if query != expected {
db.t.Errorf("%v: got unexpected query (index=%v): %v != %v", db.name, index, query, expected)
return nil, errors.New("unexpected query")
}
}
db.t.Logf("ExecuteFetch: %v: %v", db.name, query)
if entry.Error != nil {
return nil, entry.Error
}
return entry.QueryResult, nil
}
// ComPrepare is part of the mysql.Handler interface.
func (db *DB) ComPrepare(c *mysql.Conn, query string, bindVars map[string]*querypb.BindVariable) ([]*querypb.Field, error) {
return nil, nil
}
// ComStmtExecute is part of the mysql.Handler interface.
func (db *DB) ComStmtExecute(c *mysql.Conn, prepare *mysql.PrepareData, callback func(*sqltypes.Result) error) error {
return nil
}
// ComResetConnection is part of the mysql.Handler interface.
func (db *DB) ComResetConnection(c *mysql.Conn) {
}
//
// Methods to add expected queries and results.
//
// AddQuery adds a query and its expected result.
func (db *DB) AddQuery(query string, expectedResult *sqltypes.Result) *ExpectedResult {
if len(expectedResult.Rows) > 0 && len(expectedResult.Fields) == 0 {
panic(fmt.Errorf("please add Fields to this Result so it's valid: %v", query))
}
resultCopy := &sqltypes.Result{}
*resultCopy = *expectedResult
db.mu.Lock()
defer db.mu.Unlock()
key := strings.ToLower(query)
r := &ExpectedResult{resultCopy, nil}
db.data[key] = r
db.queryCalled[key] = 0
return r
}
// SetBeforeFunc sets the BeforeFunc field for the previously registered "query".
func (db *DB) SetBeforeFunc(query string, f func()) {
db.mu.Lock()
defer db.mu.Unlock()
key := strings.ToLower(query)
r, ok := db.data[key]
if !ok {
db.t.Fatalf("BUG: no query registered for: %v", query)
}
r.BeforeFunc = f
}
// AddQueryPattern adds an expected result for a set of queries.
// These patterns are checked if no exact matches from AddQuery() are found.
// This function forces the addition of begin/end anchors (^$) and turns on
// case-insensitive matching mode.
func (db *DB) AddQueryPattern(queryPattern string, expectedResult *sqltypes.Result) {
if len(expectedResult.Rows) > 0 && len(expectedResult.Fields) == 0 {
panic(fmt.Errorf("please add Fields to this Result so it's valid: %v", queryPattern))
}
expr := regexp.MustCompile("(?is)^" + queryPattern + "$")
result := *expectedResult
db.mu.Lock()
defer db.mu.Unlock()
db.patternData = append(db.patternData, exprResult{expr: expr, result: &result})
}
// RejectQueryPattern allows a query pattern to be rejected with an error
func (db *DB) RejectQueryPattern(queryPattern, error string) {
expr := regexp.MustCompile("(?is)^" + queryPattern + "$")
db.mu.Lock()
defer db.mu.Unlock()
db.patternData = append(db.patternData, exprResult{expr: expr, err: error})
}
// ClearQueryPattern removes all query patterns set up
func (db *DB) ClearQueryPattern() {
db.patternData = nil
}
// AddQueryPatternWithCallback is similar to AddQueryPattern: in addition it calls the provided callback function
// The callback can be used to set user counters/variables for testing specific usecases
func (db *DB) AddQueryPatternWithCallback(queryPattern string, expectedResult *sqltypes.Result, callback func(string)) {
db.AddQueryPattern(queryPattern, expectedResult)
db.queryPatternUserCallback[db.patternData[len(db.patternData)-1].expr] = callback
}
// DeleteQuery deletes query from the fake DB.
func (db *DB) DeleteQuery(query string) {
db.mu.Lock()
defer db.mu.Unlock()
key := strings.ToLower(query)
delete(db.data, key)
delete(db.queryCalled, key)
}
// AddRejectedQuery adds a query which will be rejected at execution time.
func (db *DB) AddRejectedQuery(query string, err error) {
db.mu.Lock()
defer db.mu.Unlock()
db.rejectedData[strings.ToLower(query)] = err
}
// DeleteRejectedQuery deletes query from the fake DB.
func (db *DB) DeleteRejectedQuery(query string) {
db.mu.Lock()
defer db.mu.Unlock()
delete(db.rejectedData, strings.ToLower(query))
}
// GetQueryCalledNum returns how many times db executes a certain query.
func (db *DB) GetQueryCalledNum(query string) int {
db.mu.Lock()
defer db.mu.Unlock()
num, ok := db.queryCalled[strings.ToLower(query)]
if !ok {
return 0
}
return num
}
//QueryLog returns the query log in a semicomma separated string
func (db *DB) QueryLog() string {
return strings.Join(db.querylog, ";")
}
//ResetQueryLog resets the query log
func (db *DB) ResetQueryLog() {
db.querylog = nil
}
// EnableConnFail makes connection to this fake DB fail.
func (db *DB) EnableConnFail() {
db.mu.Lock()
defer db.mu.Unlock()
db.isConnFail = true
}
// DisableConnFail makes connection to this fake DB success.
func (db *DB) DisableConnFail() {
db.mu.Lock()
defer db.mu.Unlock()
db.isConnFail = false
}
// SetConnDelay delays connections to this fake DB for the given duration
func (db *DB) SetConnDelay(d time.Duration) {
db.mu.Lock()
defer db.mu.Unlock()
db.connDelay = d
}
// EnableShouldClose closes the connection when processing the next query.
func (db *DB) EnableShouldClose() {
db.mu.Lock()
defer db.mu.Unlock()
db.shouldClose = true
}
//
// The following methods are used for ordered expected queries.
//
// AddExpectedExecuteFetch adds an ExpectedExecuteFetch directly.
func (db *DB) AddExpectedExecuteFetch(entry ExpectedExecuteFetch) {
db.AddExpectedExecuteFetchAtIndex(appendEntry, entry)
}
// EnableInfinite turns on the infinite flag (the last ordered query is used).
func (db *DB) EnableInfinite() {
db.mu.Lock()
defer db.mu.Unlock()
db.infinite = true
}
// AddExpectedExecuteFetchAtIndex inserts a new entry at index.
// index values start at 0.
func (db *DB) AddExpectedExecuteFetchAtIndex(index int, entry ExpectedExecuteFetch) {
db.mu.Lock()
defer db.mu.Unlock()
if db.expectedExecuteFetch == nil || index < 0 || index >= len(db.expectedExecuteFetch) {
index = appendEntry
}
if index == appendEntry {
db.expectedExecuteFetch = append(db.expectedExecuteFetch, entry)
} else {
// Grow the slice by one element.
if cap(db.expectedExecuteFetch) == len(db.expectedExecuteFetch) {
db.expectedExecuteFetch = append(db.expectedExecuteFetch, make([]ExpectedExecuteFetch, 1)...)
} else {
db.expectedExecuteFetch = db.expectedExecuteFetch[0 : len(db.expectedExecuteFetch)+1]
}
// Use copy to move the upper part of the slice out of the way and open a hole.
copy(db.expectedExecuteFetch[index+1:], db.expectedExecuteFetch[index:])
// Store the new value.
db.expectedExecuteFetch[index] = entry
}
}
// AddExpectedQuery adds a single query with no result.
func (db *DB) AddExpectedQuery(query string, err error) {
db.AddExpectedExecuteFetch(ExpectedExecuteFetch{
Query: query,
QueryResult: &sqltypes.Result{},
Error: err,
})
}
// AddExpectedQueryAtIndex adds an expected ordered query at an index.
func (db *DB) AddExpectedQueryAtIndex(index int, query string, err error) {
db.AddExpectedExecuteFetchAtIndex(index, ExpectedExecuteFetch{
Query: query,
QueryResult: &sqltypes.Result{},
Error: err,
})
}
// GetEntry returns the expected entry at "index". If index is out of bounds,
// the return value will be nil.
func (db *DB) GetEntry(index int) *ExpectedExecuteFetch {
db.mu.Lock()
defer db.mu.Unlock()
if index < 0 || index >= len(db.expectedExecuteFetch) {
panic(fmt.Sprintf("index out of range. current length: %v", len(db.expectedExecuteFetch)))
}
return &db.expectedExecuteFetch[index]
}
// DeleteAllEntries removes all ordered entries.
func (db *DB) DeleteAllEntries() {
db.mu.Lock()
defer db.mu.Unlock()
db.expectedExecuteFetch = make([]ExpectedExecuteFetch, 0)
db.expectedExecuteFetchIndex = 0
}
// DeleteAllEntriesAfterIndex removes all queries after the index.
func (db *DB) DeleteAllEntriesAfterIndex(index int) {
db.mu.Lock()
defer db.mu.Unlock()
if index < 0 || index >= len(db.expectedExecuteFetch) {
panic(fmt.Sprintf("index out of range. current length: %v", len(db.expectedExecuteFetch)))
}
if index+1 < db.expectedExecuteFetchIndex {
// Don't delete entries which were already answered.
return
}
db.expectedExecuteFetch = db.expectedExecuteFetch[:index+1]
}
// VerifyAllExecutedOrFail checks that all expected queries where actually
// received and executed. If not, it will let the test fail.
func (db *DB) VerifyAllExecutedOrFail() {
db.mu.Lock()
defer db.mu.Unlock()
if db.expectedExecuteFetchIndex != len(db.expectedExecuteFetch) {
db.t.Errorf("%v: not all expected queries were executed. leftovers: %v", db.name, db.expectedExecuteFetch[db.expectedExecuteFetchIndex:])
}
}