From 04dad40a080f4f6a74088028fa295d6187bed642 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Wed, 29 Jul 2015 05:47:18 +0000 Subject: [PATCH] PageCacheTest.TwoFileHandles_KeepCache --- samples/cachingfs/caching_fs_test.go | 42 +++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/samples/cachingfs/caching_fs_test.go b/samples/cachingfs/caching_fs_test.go index 164080d..5634034 100644 --- a/samples/cachingfs/caching_fs_test.go +++ b/samples/cachingfs/caching_fs_test.go @@ -671,5 +671,45 @@ func (t *PageCacheTest) TwoFileHandles_NoKeepCache() { } func (t *PageCacheTest) TwoFileHandles_KeepCache() { - AssertTrue(false, "TODO") + t.fs.SetKeepCache(true) + + // 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 the same contents when we read via the second handle. + f2.Seek(0, 0) + AssertEq(nil, err) + + c2, err := ioutil.ReadAll(f2) + AssertEq(nil, err) + AssertEq(cachingfs.FooSize, len(c2)) + + ExpectTrue(bytes.Equal(c1, c2)) + + // Ditto if we read again from the first. + f1.Seek(0, 0) + AssertEq(nil, err) + + c3, err := ioutil.ReadAll(f1) + AssertEq(nil, err) + AssertEq(cachingfs.FooSize, len(c3)) + + ExpectTrue(bytes.Equal(c1, c3)) }