forked from cockroachdb/pebble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flush_test.go
83 lines (70 loc) · 1.6 KB
/
flush_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright 2018 The LevelDB-Go and Pebble Authors. All rights reserved. Use
// of this source code is governed by a BSD-style license that can be found in
// the LICENSE file.
package pebble
import (
"fmt"
"testing"
"time"
"github.com/cockroachdb/pebble/internal/datadriven"
"github.com/cockroachdb/pebble/vfs"
)
func TestManualFlush(t *testing.T) {
d, err := Open("", &Options{
FS: vfs.NewMem(),
})
if err != nil {
t.Fatal(err)
}
datadriven.RunTest(t, "testdata/manual_flush", func(td *datadriven.TestData) string {
switch td.Cmd {
case "batch":
b := d.NewBatch()
if err := runBatchDefineCmd(td, b); err != nil {
return err.Error()
}
b.Commit(nil)
return ""
case "flush":
if err := d.Flush(); err != nil {
return err.Error()
}
d.mu.Lock()
s := d.mu.versions.currentVersion().DebugString()
d.mu.Unlock()
return s
case "async-flush":
d.mu.Lock()
cur := d.mu.versions.currentVersion()
d.mu.Unlock()
if _, err := d.AsyncFlush(); err != nil {
return err.Error()
}
err := try(100*time.Microsecond, 20*time.Second, func() error {
d.mu.Lock()
defer d.mu.Unlock()
if cur == d.mu.versions.currentVersion() {
return fmt.Errorf("flush has not occurred")
}
return nil
})
if err != nil {
return err.Error()
}
d.mu.Lock()
s := d.mu.versions.currentVersion().DebugString()
d.mu.Unlock()
return s
case "reset":
d, err = Open("", &Options{
FS: vfs.NewMem(),
})
if err != nil {
return err.Error()
}
return ""
default:
return fmt.Sprintf("unknown command: %s", td.Cmd)
}
})
}