TestTx_Check_ReadOnly tests consistency checking on a ReadOnly database.
(t *testing.T)
| 20 | |
| 21 | // TestTx_Check_ReadOnly tests consistency checking on a ReadOnly database. |
| 22 | func TestTx_Check_ReadOnly(t *testing.T) { |
| 23 | db := btesting.MustCreateDB(t) |
| 24 | if err := db.Update(func(tx *bolt.Tx) error { |
| 25 | b, err := tx.CreateBucket([]byte("widgets")) |
| 26 | if err != nil { |
| 27 | t.Fatal(err) |
| 28 | } |
| 29 | if err := b.Put([]byte("foo"), []byte("bar")); err != nil { |
| 30 | t.Fatal(err) |
| 31 | } |
| 32 | return nil |
| 33 | }); err != nil { |
| 34 | t.Fatal(err) |
| 35 | } |
| 36 | if err := db.Close(); err != nil { |
| 37 | t.Fatal(err) |
| 38 | } |
| 39 | |
| 40 | readOnlyDB, err := bolt.Open(db.Path(), 0600, &bolt.Options{ReadOnly: true}) |
| 41 | if err != nil { |
| 42 | t.Fatal(err) |
| 43 | } |
| 44 | defer readOnlyDB.Close() |
| 45 | |
| 46 | tx, err := readOnlyDB.Begin(false) |
| 47 | if err != nil { |
| 48 | t.Fatal(err) |
| 49 | } |
| 50 | // ReadOnly DB will load freelist on Check call. |
| 51 | numChecks := 2 |
| 52 | errc := make(chan error, numChecks) |
| 53 | check := func() { |
| 54 | errc <- <-tx.Check() |
| 55 | } |
| 56 | // Ensure the freelist is not reloaded and does not race. |
| 57 | for i := 0; i < numChecks; i++ { |
| 58 | go check() |
| 59 | } |
| 60 | for i := 0; i < numChecks; i++ { |
| 61 | if err := <-errc; err != nil { |
| 62 | t.Fatal(err) |
| 63 | } |
| 64 | } |
| 65 | // Close the view transaction |
| 66 | err = tx.Rollback() |
| 67 | if err != nil { |
| 68 | t.Fatal(err) |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | // Ensure that committing a closed transaction returns an error. |
| 73 | func TestTx_Commit_ErrTxClosed(t *testing.T) { |
nothing calls this directly
no test coverage detected