todo to check is there any deadlock here?
(t *testing.T)
| 25 | |
| 26 | // todo to check is there any deadlock here? |
| 27 | func TestTx_Rollback(t *testing.T) { |
| 28 | |
| 29 | withDefaultDB(t, func(t *testing.T, db *DB) { |
| 30 | bucket := "bucket_rollback_test" |
| 31 | txCreateBucket(t, db, DataStructureBTree, bucket, nil) |
| 32 | tx, err := db.Begin(true) |
| 33 | assert.NoError(t, err) |
| 34 | |
| 35 | for i := 0; i < 10; i++ { |
| 36 | key := []byte("key_" + fmt.Sprintf("%03d", i)) |
| 37 | val := []byte("val_" + fmt.Sprintf("%03d", i)) |
| 38 | if i == 7 { |
| 39 | key = []byte("") // set error key to make tx rollback |
| 40 | } |
| 41 | if err = tx.Put(bucket, key, val, Persistent); err != nil { |
| 42 | // tx rollback |
| 43 | _ = tx.Rollback() |
| 44 | |
| 45 | if i < 7 { |
| 46 | t.Fatal("err TestTx_Rollback") |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | // no one found |
| 52 | for i := 0; i <= 10; i++ { |
| 53 | tx, err = db.Begin(false) |
| 54 | assert.NoError(t, err) |
| 55 | |
| 56 | key := []byte("key_" + fmt.Sprintf("%03d", i)) |
| 57 | if _, err := tx.Get(bucket, key); err != nil { |
| 58 | // tx rollback |
| 59 | _ = tx.Rollback() |
| 60 | } else { |
| 61 | t.Fatal("err TestTx_Rollback") |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | }) |
| 66 | } |
| 67 | |
| 68 | func TestTx_Begin(t *testing.T) { |
| 69 | t.Run("Begin with default options, with only read", func(t *testing.T) { |
nothing calls this directly
no test coverage detected