summaryrefslogtreecommitdiff
path: root/tests/matrix/matrix_test.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2016-07-01 23:29:31 +0200
committerJakob Unterwurzacher2016-07-01 23:32:27 +0200
commitf2b4d57068d13b6dc3de2ccc6550675d11d34cfa (patch)
treeb90d31b0375e41318f2ce879df14f36bff4e3b5e /tests/matrix/matrix_test.go
parentae77d1852793c4dd43c8ddd69de574223aecce5e (diff)
fusefrontend: coalesce grows in Truncate()
We were growing the file block-by-block which was pretty inefficient. We now coalesce all the grows into a single Ftruncate. Also simplifies the code! Simplistic benchmark: Before: $ time truncate -s 1000M foo real 0m0.568s After: $ time truncate -s 1000M foo real 0m0.205s
Diffstat (limited to 'tests/matrix/matrix_test.go')
-rw-r--r--tests/matrix/matrix_test.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/matrix/matrix_test.go b/tests/matrix/matrix_test.go
index eb49d59..d59a677 100644
--- a/tests/matrix/matrix_test.go
+++ b/tests/matrix/matrix_test.go
@@ -113,6 +113,8 @@ func TestWrite100x100(t *testing.T) {
}
}
+// Hint for calculating reference md5sums:
+// dd if=/dev/zero count=1 bs=XYZ | md5sum
func TestTruncate(t *testing.T) {
fn := test_helpers.DefaultPlainDir + "/truncate"
file, err := os.Create(fn)
@@ -143,6 +145,31 @@ func TestTruncate(t *testing.T) {
if test_helpers.Md5fn(fn) != "620f0b67a91f7f74151bc5be745b7110" {
t.Errorf("wrong content")
}
+ // Truncate to zero
+ file.Truncate(0)
+ test_helpers.VerifySize(t, fn, 0)
+ // Grow to 10MB (creates file holes)
+ var sz int
+ sz = 10 * 1024 * 1024
+ file.Truncate(int64(sz))
+ test_helpers.VerifySize(t, fn, sz)
+ if test_helpers.Md5fn(fn) != "f1c9645dbc14efddc7d8a322685f26eb" {
+ t.Errorf("wrong content")
+ }
+ // Grow to 10MB + 100B (partial block on the end)
+ sz = 10*1024*1024 + 100
+ file.Truncate(int64(sz))
+ test_helpers.VerifySize(t, fn, sz)
+ if test_helpers.Md5fn(fn) != "c23ea79b857b91a7ff07c6ecf185f1ca" {
+ t.Errorf("wrong content")
+ }
+ // Grow to 20MB (creates file holes, partial block on the front)
+ sz = 20 * 1024 * 1024
+ file.Truncate(int64(sz))
+ test_helpers.VerifySize(t, fn, sz)
+ if test_helpers.Md5fn(fn) != "8f4e33f3dc3e414ff94e5fb6905cba8c" {
+ t.Errorf("wrong content")
+ }
}
func TestAppend(t *testing.T) {