From 51f6b011351279a433936eeaec1ee16f86b34cca Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Tue, 24 Mar 2015 12:22:25 +1100 Subject: [PATCH] NoErrorsTest.Fdatasync --- samples/flushfs/flush_fs_test.go | 37 +++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/samples/flushfs/flush_fs_test.go b/samples/flushfs/flush_fs_test.go index 1e3bef9..9161b6c 100644 --- a/samples/flushfs/flush_fs_test.go +++ b/samples/flushfs/flush_fs_test.go @@ -410,7 +410,42 @@ func (t *NoErrorsTest) Fsync() { } func (t *NoErrorsTest) Fdatasync() { - AssertTrue(false, "TODO") + var n int + var err error + + // Open the file. + t.f1, err = os.OpenFile(path.Join(t.Dir, "foo"), os.O_WRONLY, 0) + AssertEq(nil, err) + + // Write some contents to the file. + n, err = t.f1.Write([]byte("taco")) + AssertEq(nil, err) + AssertEq(4, n) + + AssertThat(t.getFlushes(), ElementsAre()) + AssertThat(t.getFsyncs(), ElementsAre()) + + // Fdatasync. + err = syscall.Fdatasync(int(t.f1.Fd())) + AssertEq(nil, err) + + AssertThat(t.getFlushes(), ElementsAre()) + AssertThat(t.getFsyncs(), ElementsAre("taco")) + + // Write some more contents. + n, err = t.f1.Write([]byte("s")) + AssertEq(nil, err) + AssertEq(1, n) + + AssertThat(t.getFlushes(), ElementsAre()) + AssertThat(t.getFsyncs(), ElementsAre("taco")) + + // Fdatasync. + err = syscall.Fdatasync(int(t.f1.Fd())) + AssertEq(nil, err) + + AssertThat(t.getFlushes(), ElementsAre()) + AssertThat(t.getFsyncs(), ElementsAre("taco", "tacos")) } func (t *NoErrorsTest) Dup() {