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

Function TestDB_BatchTime

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

Source from the content-addressed store, hash-verified

1449}
1450
1451func TestDB_BatchTime(t *testing.T) {
1452 db := btesting.MustCreateDB(t)
1453 if err := db.Update(func(tx *bolt.Tx) error {
1454 _, err := tx.CreateBucket([]byte("widgets"))
1455 return err
1456 }); err != nil {
1457 t.Fatal(err)
1458 }
1459
1460 const size = 1
1461 // buffered so we never leak goroutines
1462 ch := make(chan error, size)
1463 put := func(i int) {
1464 ch <- db.Batch(func(tx *bolt.Tx) error {
1465 return tx.Bucket([]byte("widgets")).Put(u64tob(uint64(i)), []byte{})
1466 })
1467 }
1468
1469 db.MaxBatchSize = 1000
1470 db.MaxBatchDelay = 0
1471
1472 go put(1)
1473
1474 // Batch must trigger by time alone.
1475
1476 // Check all responses to make sure there's no error.
1477 for i := 0; i < size; i++ {
1478 if err := <-ch; err != nil {
1479 t.Fatal(err)
1480 }
1481 }
1482
1483 // Ensure data is correct.
1484 if err := db.View(func(tx *bolt.Tx) error {
1485 b := tx.Bucket([]byte("widgets"))
1486 for i := 1; i <= size; i++ {
1487 if v := b.Get(u64tob(uint64(i))); v == nil {
1488 t.Errorf("key not found: %d", i)
1489 }
1490 }
1491 return nil
1492 }); err != nil {
1493 t.Fatal(err)
1494 }
1495}
1496
1497// TestDBUnmap verifes that `dataref`, `data` and `datasz` must be reset
1498// to zero values respectively after unmapping the db.

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected