From 454f3959f78a5f9fc210c28a786d144a983a19cb Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Wed, 29 Jul 2015 05:46:13 +0000 Subject: [PATCH] PageCacheTest.TwoFileHandles_NoKeepCache --- samples/cachingfs/caching_fs_test.go | 55 +++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/samples/cachingfs/caching_fs_test.go b/samples/cachingfs/caching_fs_test.go index be7ead2..164080d 100644 --- a/samples/cachingfs/caching_fs_test.go +++ b/samples/cachingfs/caching_fs_test.go @@ -614,7 +614,60 @@ func (t *PageCacheTest) SingleFileHandle_KeepCache() { } func (t *PageCacheTest) TwoFileHandles_NoKeepCache() { - AssertTrue(false, "TODO") + t.fs.SetKeepCache(false) + + // Open the file. + f1, err := os.Open(path.Join(t.Dir, "foo")) + AssertEq(nil, err) + + defer f1.Close() + + // Read its contents once. + f1.Seek(0, 0) + AssertEq(nil, err) + + c1, err := ioutil.ReadAll(f1) + AssertEq(nil, err) + AssertEq(cachingfs.FooSize, len(c1)) + + // Open a second handle. + f2, err := os.Open(path.Join(t.Dir, "foo")) + AssertEq(nil, err) + + defer f2.Close() + + // We should see different contents if we read from that handle, due to the + // cache being invalidated at the time of opening. + f2.Seek(0, 0) + AssertEq(nil, err) + + c2, err := ioutil.ReadAll(f2) + AssertEq(nil, err) + AssertEq(cachingfs.FooSize, len(c2)) + + ExpectFalse(bytes.Equal(c1, c2)) + + // Another read from the second handle should give the same result as the + // first one from that handle. + f2.Seek(0, 0) + AssertEq(nil, err) + + c3, err := ioutil.ReadAll(f2) + AssertEq(nil, err) + AssertEq(cachingfs.FooSize, len(c3)) + + ExpectTrue(bytes.Equal(c2, c3)) + + // And another read from the first handle should give the same result yet + // again. + f1.Seek(0, 0) + AssertEq(nil, err) + + c4, err := ioutil.ReadAll(f1) + AssertEq(nil, err) + AssertEq(cachingfs.FooSize, len(c4)) + + ExpectTrue(bytes.Equal(c2, c4)) } func (t *PageCacheTest) TwoFileHandles_KeepCache() {