MCPcopy
hub / github.com/etcd-io/bbolt / TestDB_BatchFull

Function TestDB_BatchFull

db_test.go:1393–1449  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1391}
1392
1393func TestDB_BatchFull(t *testing.T) {
1394 db := btesting.MustCreateDB(t)
1395 if err := db.Update(func(tx *bolt.Tx) error {
1396 _, err := tx.CreateBucket([]byte("widgets"))
1397 return err
1398 }); err != nil {
1399 t.Fatal(err)
1400 }
1401
1402 const size = 3
1403 // buffered so we never leak goroutines
1404 ch := make(chan error, size)
1405 put := func(i int) {
1406 ch <- db.Batch(func(tx *bolt.Tx) error {
1407 return tx.Bucket([]byte("widgets")).Put(u64tob(uint64(i)), []byte{})
1408 })
1409 }
1410
1411 db.MaxBatchSize = size
1412 // high enough to never trigger here
1413 db.MaxBatchDelay = 1 * time.Hour
1414
1415 go put(1)
1416 go put(2)
1417
1418 // Give the batch a chance to exhibit bugs.
1419 time.Sleep(10 * time.Millisecond)
1420
1421 // not triggered yet
1422 select {
1423 case <-ch:
1424 t.Fatalf("batch triggered too early")
1425 default:
1426 }
1427
1428 go put(3)
1429
1430 // Check all responses to make sure there's no error.
1431 for i := 0; i < size; i++ {
1432 if err := <-ch; err != nil {
1433 t.Fatal(err)
1434 }
1435 }
1436
1437 // Ensure data is correct.
1438 if err := db.View(func(tx *bolt.Tx) error {
1439 b := tx.Bucket([]byte("widgets"))
1440 for i := 1; i <= size; i++ {
1441 if v := b.Get(u64tob(uint64(i))); v == nil {
1442 t.Errorf("key not found: %d", i)
1443 }
1444 }
1445 return nil
1446 }); err != nil {
1447 t.Fatal(err)
1448 }
1449}
1450

Callers

nothing calls this directly

Calls 12

MustCreateDBFunction · 0.92
u64tobFunction · 0.85
UpdateMethod · 0.80
BatchMethod · 0.80
ViewMethod · 0.80
FatalMethod · 0.65
FatalfMethod · 0.65
ErrorfMethod · 0.65
CreateBucketMethod · 0.45
PutMethod · 0.45
BucketMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected