forked from keybase/kbfs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqr_test.go
More file actions
193 lines (183 loc) · 4.01 KB
/
Copy pathqr_test.go
File metadata and controls
193 lines (183 loc) · 4.01 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// Copyright 2016 Keybase Inc. All rights reserved.
// Use of this source code is governed by a BSD
// license that can be found in the LICENSE file.
// These tests exercise quota reclamation.
package test
import (
"fmt"
"testing"
"time"
)
// Check that simple quota reclamation works
func TestQRSimple(t *testing.T) {
test(t,
users("alice"),
as(alice,
addTime(1*time.Minute),
mkfile("a", "hello"),
rm("a"),
addTime(2*time.Minute),
forceQuotaReclamation(),
),
)
}
// Check that quota reclamation works, eventually, after enough iterations.
func TestQRLargePointerSet(t *testing.T) {
var busyWork []fileOp
iters := 100
for i := 0; i < iters; i++ {
name := fmt.Sprintf("a%d", i)
busyWork = append(busyWork, mkfile(name, "hello"), rm(name))
}
// 5 unreferenced pointers per iteration -- 3 updates to the root
// block, one empty file written to, and one non-empty file
// deleted.
ptrsPerIter := 5
var qrOps []optionOp
// Each reclamation needs a sync after it (e.g., a new "as"
// clause) to ensure it completes before the next force
// reclamation.
for i := 0; i < ptrsPerIter*iters/100; i++ {
qrOps = append(qrOps, as(alice,
addTime(2*time.Minute),
forceQuotaReclamation(),
))
}
totalOps := []optionOp{users("alice"), as(alice, busyWork...)}
totalOps = append(totalOps, qrOps...)
test(t, totalOps...)
}
// Test that quota reclamation handles conflict resolution correctly.
func TestQRAfterCR(t *testing.T) {
test(t,
users("alice", "bob"),
as(alice,
mkfile("a/b", "hello"),
),
as(bob,
disableUpdates(),
),
as(alice,
write("a/c", "world"),
),
as(bob, noSync(),
rm("a/b"),
reenableUpdates(),
),
as(alice,
addTime(2*time.Minute),
forceQuotaReclamation(),
),
)
}
// Check that quota reclamation after two syncOps CR leaves the TLF in
// a readable state. Regression test for KBFS-1562.
func TestQRAfterCRWithTwoSyncOps(t *testing.T) {
test(t,
users("alice", "bob"),
as(alice,
mkfile("a/b", "hello"),
),
as(bob,
disableUpdates(),
),
as(alice,
write("a/c", "hello2"),
),
as(bob, noSync(),
write("a/b", "hello world"),
write("a/b", "hello world etc"),
reenableUpdates(),
),
as(alice,
addTime(2*time.Minute),
forceQuotaReclamation(),
read("a/b", "hello world etc"),
read("a/c", "hello2"),
),
)
}
// Check that quota reclamation works on multi-block files
func TestQRWithMultiBlockFiles(t *testing.T) {
test(t,
blockSize(20), users("alice"),
as(alice,
addTime(1*time.Minute),
mkfile("a", ntimesString(15, "0123456789")),
rm("a"),
addTime(2*time.Minute),
forceQuotaReclamation(),
),
)
}
// Test that conflict resolution fails gracefully after quota
// reclamation deletes some necessary blocks.
func TestCRAfterQR(t *testing.T) {
test(t,
users("alice", "bob"),
as(alice,
mkfile("a/b", "hello"),
),
as(bob,
disableUpdates(),
),
as(alice,
rm("a/b"),
),
as(bob, noSync(),
setex("a/b", true),
),
as(alice,
addTime(2*time.Minute),
// Force rmd.data.Dir.MTime to something recent. TODO: remove me.
mkfile("c", "test"),
forceQuotaReclamation(),
),
as(bob, noSync(),
reenableUpdates(),
notExists("a/b"),
),
as(alice,
notExists("a/b"),
),
)
}
// Test that conflict resolution works gracefully after quota
// reclamation deletes a modified+deleted directory from the merged
// branch. Regression for KBFS-1202.
func TestCRAfterRmdirAndQR(t *testing.T) {
test(t,
users("alice", "bob"),
as(alice,
mkdir("a/b"),
mkfile("a/b/c", "world"),
),
as(bob,
disableUpdates(),
),
as(alice,
mkfile("a/b/d", "world2"),
rm("a/b/c"),
rm("a/b/d"),
rmdir("a/b"),
),
as(bob, noSync(),
setmtime("a/b/c", time.Now().Add(1*time.Minute)),
rm("a/b/c"),
rmdir("a/b"),
),
as(alice,
addTime(2*time.Minute),
// Force rmd.data.Dir.MTime to something recent. TODO: remove me.
mkfile("c", "test"),
forceQuotaReclamation(),
),
as(bob, noSync(),
reenableUpdates(),
lsdir("a/", m{}),
),
as(alice,
lsdir("a/", m{}),
),
)
}