Esempio n. 1
0
func (t *NoErrorsTest) Fdatasync() {
	var n int
	var err error

	if !fsutil.FdatasyncSupported {
		return
	}

	// 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 = fsutil.Fdatasync(t.f1)
	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 = fsutil.Fdatasync(t.f1)
	AssertEq(nil, err)

	AssertThat(t.getFlushes(), ElementsAre())
	AssertThat(t.getFsyncs(), ElementsAre("taco", "tacos"))
}
Esempio n. 2
0
func (t *FsyncErrorTest) Fdatasync() {
	var err error

	if !fsutil.FdatasyncSupported {
		return
	}

	// Open the file.
	t.f1, err = os.OpenFile(path.Join(t.Dir, "foo"), os.O_RDWR, 0)
	AssertEq(nil, err)

	// Fdatasync.
	err = fsutil.Fdatasync(t.f1)

	ExpectThat(err, Error(HasSubstr("no such file")))
}