From b8ce0bcb8d7ef7a2ca186a815647f8a5218d76ca Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Fri, 20 Mar 2015 11:56:38 +1100 Subject: [PATCH] FlushFSTest.CloseReports_MultipleTimes_NonOverlappingFileHandles --- samples/flushfs/flush_fs_test.go | 51 +++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/samples/flushfs/flush_fs_test.go b/samples/flushfs/flush_fs_test.go index 346a00c..c72b5be 100644 --- a/samples/flushfs/flush_fs_test.go +++ b/samples/flushfs/flush_fs_test.go @@ -234,7 +234,56 @@ func (t *FlushFSTest) CloseReports_WriteOnly() { } func (t *FlushFSTest) CloseReports_MultipleTimes_NonOverlappingFileHandles() { - 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) + + // At this point, no flushes or fsyncs should have happened. + AssertThat(t.getFlushes(), ElementsAre()) + AssertThat(t.getFsyncs(), ElementsAre()) + + // Close the file. + err = f.Close() + f = nil + AssertEq(nil, err) + + // Now we should have received the flush operation (but still no fsync). + AssertThat(t.getFlushes(), ElementsAre(byteSliceEq("taco"))) + AssertThat(t.getFsyncs(), ElementsAre()) + + // Open the file again. + f, err = os.OpenFile(path.Join(t.Dir, "foo"), os.O_WRONLY, 0) + AssertEq(nil, err) + + // Write again; expect no further flushes. + n, err = f.Write([]byte("p")) + AssertEq(nil, err) + AssertEq(1, n) + + AssertThat(t.getFlushes(), ElementsAre(byteSliceEq("taco"))) + AssertThat(t.getFsyncs(), ElementsAre()) + + // Close the file. Now the new contents should be flushed. + err = f.Close() + f = nil + AssertEq(nil, err) + + AssertThat(t.getFlushes(), ElementsAre(byteSliceEq("taco"), byteSliceEq("paco"))) + AssertThat(t.getFsyncs(), ElementsAre()) } func (t *FlushFSTest) CloseReports_MultipleTimes_OverlappingFileHandles() {