From 2f3b25c19a973f73441a5fd24c1bc47cef174c2d Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Fri, 20 Mar 2015 12:03:25 +1100 Subject: [PATCH] FlushFSTest.FsyncReports --- samples/flushfs/flush_fs_test.go | 45 ++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/samples/flushfs/flush_fs_test.go b/samples/flushfs/flush_fs_test.go index ce155d7..1ab3c47 100644 --- a/samples/flushfs/flush_fs_test.go +++ b/samples/flushfs/flush_fs_test.go @@ -341,7 +341,7 @@ func (t *FlushFSTest) CloseReports_MultipleTimes_OverlappingFileHandles() { } func (t *FlushFSTest) CloseError() { - // Open a file. + // Open the file. f, err := os.OpenFile(path.Join(t.Dir, "foo"), os.O_RDWR, 0) AssertEq(nil, err) @@ -363,7 +363,48 @@ func (t *FlushFSTest) CloseError() { } func (t *FlushFSTest) FsyncReports() { - AssertTrue(false, "TODO") + var n int + var err error + + // Open the file. + f, err := os.OpenFile(path.Join(t.Dir, "foo"), os.O_WRONLY, 0) + AssertEq(nil, err) + + defer func() { + if f != nil { + ExpectEq(nil, f.Close()) + } + }() + + // Write some contents to the file. + n, err = f.Write([]byte("taco")) + AssertEq(nil, err) + AssertEq(4, n) + + AssertThat(t.getFlushes(), ElementsAre()) + AssertThat(t.getFsyncs(), ElementsAre()) + + // Fsync. + err = f.Sync() + AssertEq(nil, err) + + AssertThat(t.getFlushes(), ElementsAre()) + AssertThat(t.getFsyncs(), ElementsAre("taco")) + + // Write some more contents. + n, err = f.Write([]byte("s")) + AssertEq(nil, err) + AssertEq(1, n) + + AssertThat(t.getFlushes(), ElementsAre()) + AssertThat(t.getFsyncs(), ElementsAre("taco")) + + // Fsync. + err = f.Sync() + AssertEq(nil, err) + + AssertThat(t.getFlushes(), ElementsAre()) + AssertThat(t.getFsyncs(), ElementsAre("taco", "tacos")) } func (t *FlushFSTest) FsyncError() {