Skip to content

Commit

Permalink
Kernel List Cache: Composite Test (#2036)
Browse files Browse the repository at this point in the history
* Added simple cache hit/miss test

* Added cache related test, remaining: refactoring and with different operation

* pushing the internal changes

* Refactoring for basic test

* Fixing lint issue

* some cleaning

* review comments

* pushing missed file

* Rebase

* review comments
  • Loading branch information
raj-prince authored and gargnitingoogle committed Jul 11, 2024
1 parent 33c0db5 commit 9072a39
Show file tree
Hide file tree
Showing 4 changed files with 502 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/fs/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ func (t *fsTest) createObjects(in map[string]string) error {
return err
}

func (t *fsTest) deleteObject(name string) error {
return bucket.DeleteObject(ctx, &gcs.DeleteObjectRequest{Name: name})
}

func (t *fsTest) createEmptyObjects(names []string) error {
err := storageutil.CreateEmptyObjects(ctx, bucket, names)
return err
Expand Down
88 changes: 88 additions & 0 deletions internal/fs/kernel_list_cache_inifinite_ttl_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright 2024 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Please refer kernel_list_cache_test.go for the documentation.

package fs_test

import (
"os"
"path"
"testing"
"time"

"github.com/googlecloudplatform/gcsfuse/v2/internal/config"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)

type KernelListCacheTestWithInfiniteTtl struct {
suite.Suite
fsTest
KernelListCacheTestCommon
}

func (t *KernelListCacheTestWithInfiniteTtl) SetupSuite() {
t.serverCfg.ImplicitDirectories = true
t.serverCfg.MountConfig = &config.MountConfig{
FileSystemConfig: config.FileSystemConfig{
KernelListCacheTtlSeconds: -1,
},
MetadataCacheConfig: config.MetadataCacheConfig{
TtlInSeconds: 0,
},
}
t.serverCfg.RenameDirLimit = 10
t.fsTest.SetUpTestSuite()
}

func TestKernelListCacheTestInfiniteTtlSuite(t *testing.T) {
suite.Run(t, new(KernelListCacheTestWithInfiniteTtl))
}

// (a) First ReadDir() will be served from GCSFuse filesystem.
// (b) Second ReadDir() will also be served from GCSFuse filesystem.
func (t *KernelListCacheTestWithInfiniteTtl) TestKernelListCache_AlwaysCacheHit() {
// First read, kernel will cache the dir response.
f, err := os.Open(path.Join(mntDir, "explicitDir"))
assert.Nil(t.T(), err)
defer func() {
assert.Nil(t.T(), f.Close())
}()
names1, err := f.Readdirnames(-1)
assert.Nil(t.T(), err)
require.Equal(t.T(), 2, len(names1))
assert.Equal(t.T(), "file1.txt", names1[0])
assert.Equal(t.T(), "file2.txt", names1[1])
err = f.Close()
assert.Nil(t.T(), err)
// Adding one object to make sure to change the ReadDir() response.
assert.Nil(t.T(), t.createObjects(map[string]string{
"explicitDir/file3.txt": "123456",
}))
defer t.deleteObjectOrFail("explicitDir/file3.txt")
// Advancing time by 5 years (157800000 seconds).
cacheClock.AdvanceTime(157800000 * time.Second)

// No invalidation since infinite ttl.
f, err = os.Open(path.Join(mntDir, "explicitDir"))
assert.Nil(t.T(), err)
names2, err := f.Readdirnames(-1)

assert.Nil(t.T(), err)
require.Equal(t.T(), 2, len(names2))
assert.Equal(t.T(), "file1.txt", names2[0])
assert.Equal(t.T(), "file2.txt", names2[1])
}
Loading

0 comments on commit 9072a39

Please sign in to comment.