TestTx_TruncateBeforeWrite ensures the file is truncated ahead whether we sync freelist or not.
(t *testing.T)
| 1015 | |
| 1016 | // TestTx_TruncateBeforeWrite ensures the file is truncated ahead whether we sync freelist or not. |
| 1017 | func TestTx_TruncateBeforeWrite(t *testing.T) { |
| 1018 | if runtime.GOOS == "windows" { |
| 1019 | return |
| 1020 | } |
| 1021 | for _, isSyncFreelist := range []bool{false, true} { |
| 1022 | t.Run(fmt.Sprintf("isSyncFreelist:%v", isSyncFreelist), func(t *testing.T) { |
| 1023 | // Open the database. |
| 1024 | db := btesting.MustCreateDBWithOption(t, &bolt.Options{ |
| 1025 | NoFreelistSync: isSyncFreelist, |
| 1026 | }) |
| 1027 | |
| 1028 | bigvalue := make([]byte, db.AllocSize/100) |
| 1029 | count := 0 |
| 1030 | for { |
| 1031 | count++ |
| 1032 | tx, err := db.Begin(true) |
| 1033 | require.NoError(t, err) |
| 1034 | b, err := tx.CreateBucketIfNotExists([]byte("bucket")) |
| 1035 | require.NoError(t, err) |
| 1036 | err = b.Put([]byte{byte(count)}, bigvalue) |
| 1037 | require.NoError(t, err) |
| 1038 | err = tx.Commit() |
| 1039 | require.NoError(t, err) |
| 1040 | |
| 1041 | size := fileSize(db.Path()) |
| 1042 | |
| 1043 | if size > int64(db.AllocSize) && size < int64(db.AllocSize)*2 { |
| 1044 | // db.grow expands the file aggresively, that double the size while smaller than db.AllocSize, |
| 1045 | // or increase with a step of db.AllocSize if larger, by which we can test if db.grow has run. |
| 1046 | t.Fatalf("db.grow doesn't run when file size changes. file size: %d", size) |
| 1047 | } |
| 1048 | if size > int64(db.AllocSize) { |
| 1049 | break |
| 1050 | } |
| 1051 | } |
| 1052 | db.MustClose() |
| 1053 | db.MustDeleteFile() |
| 1054 | }) |
| 1055 | } |
| 1056 | } |
nothing calls this directly
no test coverage detected