MCPcopy Create free account
hub / github.com/nutsdb/nutsdb / TestTx_Rollback

Function TestTx_Rollback

tx_test.go:27–66  ·  view source on GitHub ↗

todo to check is there any deadlock here?

(t *testing.T)

Source from the content-addressed store, hash-verified

25
26// todo to check is there any deadlock here?
27func 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
68func TestTx_Begin(t *testing.T) {
69 t.Run("Begin with default options, with only read", func(t *testing.T) {

Callers

nothing calls this directly

Calls 6

withDefaultDBFunction · 0.85
txCreateBucketFunction · 0.85
BeginMethod · 0.80
RollbackMethod · 0.80
PutMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected