Ensure that opening a database beyond the max step size does not increase its size. https://github.com/boltdb/bolt/issues/303
(t *testing.T)
| 329 | // Ensure that opening a database beyond the max step size does not increase its size. |
| 330 | // https://github.com/boltdb/bolt/issues/303 |
| 331 | func TestOpen_Size_Large(t *testing.T) { |
| 332 | if testing.Short() { |
| 333 | t.Skip("short mode") |
| 334 | } |
| 335 | |
| 336 | // Open a data file. |
| 337 | db := btesting.MustCreateDB(t) |
| 338 | path := db.Path() |
| 339 | |
| 340 | pagesize := db.Info().PageSize |
| 341 | |
| 342 | // Insert until we get above the minimum 4MB size. |
| 343 | var index uint64 |
| 344 | for i := 0; i < 10000; i++ { |
| 345 | if err := db.Update(func(tx *bolt.Tx) error { |
| 346 | b, _ := tx.CreateBucketIfNotExists([]byte("data")) |
| 347 | for j := 0; j < 1000; j++ { |
| 348 | if err := b.Put(u64tob(index), make([]byte, 50)); err != nil { |
| 349 | t.Fatal(err) |
| 350 | } |
| 351 | index++ |
| 352 | } |
| 353 | return nil |
| 354 | }); err != nil { |
| 355 | t.Fatal(err) |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | // Close database and grab the size. |
| 360 | if err := db.Close(); err != nil { |
| 361 | t.Fatal(err) |
| 362 | } |
| 363 | sz := fileSize(path) |
| 364 | if sz == 0 { |
| 365 | t.Fatalf("unexpected new file size: %d", sz) |
| 366 | } else if sz < (1 << 30) { |
| 367 | t.Fatalf("expected larger initial size: %d", sz) |
| 368 | } |
| 369 | |
| 370 | // Reopen database, update, and check size again. |
| 371 | db0, err := bolt.Open(path, 0600, nil) |
| 372 | if err != nil { |
| 373 | t.Fatal(err) |
| 374 | } |
| 375 | if err := db0.Update(func(tx *bolt.Tx) error { |
| 376 | return tx.Bucket([]byte("data")).Put([]byte{0}, []byte{0}) |
| 377 | }); err != nil { |
| 378 | t.Fatal(err) |
| 379 | } |
| 380 | if err := db0.Close(); err != nil { |
| 381 | t.Fatal(err) |
| 382 | } |
| 383 | |
| 384 | newSz := fileSize(path) |
| 385 | if newSz == 0 { |
| 386 | t.Fatalf("unexpected new file size: %d", newSz) |
| 387 | } |
| 388 |
nothing calls this directly
no test coverage detected