Ensure that opening a database does not increase its size. https://github.com/boltdb/bolt/issues/291
(t *testing.T)
| 280 | // Ensure that opening a database does not increase its size. |
| 281 | // https://github.com/boltdb/bolt/issues/291 |
| 282 | func TestOpen_Size(t *testing.T) { |
| 283 | // Open a data file. |
| 284 | db := btesting.MustCreateDB(t) |
| 285 | |
| 286 | pagesize := db.Info().PageSize |
| 287 | |
| 288 | // Insert until we get above the minimum 4MB size. |
| 289 | err := db.Fill([]byte("data"), 1, 10000, |
| 290 | func(tx int, k int) []byte { return []byte(fmt.Sprintf("%04d", k)) }, |
| 291 | func(tx int, k int) []byte { return make([]byte, 1000) }, |
| 292 | ) |
| 293 | if err != nil { |
| 294 | t.Fatal(err) |
| 295 | } |
| 296 | |
| 297 | path := db.Path() |
| 298 | db.MustClose() |
| 299 | |
| 300 | sz := fileSize(path) |
| 301 | if sz == 0 { |
| 302 | t.Fatalf("unexpected new file size: %d", sz) |
| 303 | } |
| 304 | |
| 305 | db.MustReopen() |
| 306 | if err := db.Update(func(tx *bolt.Tx) error { |
| 307 | if err := tx.Bucket([]byte("data")).Put([]byte{0}, []byte{0}); err != nil { |
| 308 | t.Fatal(err) |
| 309 | } |
| 310 | return nil |
| 311 | }); err != nil { |
| 312 | t.Fatal(err) |
| 313 | } |
| 314 | if err := db.Close(); err != nil { |
| 315 | t.Fatal(err) |
| 316 | } |
| 317 | newSz := fileSize(path) |
| 318 | if newSz == 0 { |
| 319 | t.Fatalf("unexpected new file size: %d", newSz) |
| 320 | } |
| 321 | |
| 322 | // Compare the original size with the new size. |
| 323 | // db size might increase by a few page sizes due to the new small update. |
| 324 | if sz < newSz-5*int64(pagesize) { |
| 325 | t.Fatalf("unexpected file growth: %d => %d", sz, newSz) |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | // Ensure that opening a database beyond the max step size does not increase its size. |
| 330 | // https://github.com/boltdb/bolt/issues/303 |
nothing calls this directly
no test coverage detected