Skip to content

Commit

Permalink
GKE e2e test fix (#2416)
Browse files Browse the repository at this point in the history
* fix cache dir name

* fix cache dir name

* add test bucket flag

* lint fix

* lint fix

* lint fix

* test script

* lint fix

* lint fix

* test on VM

* test on VM

* undo test changes

* review comment

* lint fix

* small fix
  • Loading branch information
Tulsishah authored Aug 30, 2024
1 parent fef2857 commit f5bb7c9
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 40 deletions.
29 changes: 19 additions & 10 deletions tools/integration_tests/operations/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"log"
"os"
"path"
"strconv"
"testing"

"cloud.google.com/go/storage"
Expand Down Expand Up @@ -88,8 +89,14 @@ const ContentInFileInDirThreeInCreateThreeLevelDirTest = "Hello world!!"
const Content = "line 1\nline 2\n"
const onlyDirMounted = "OnlyDirMountOperations"

var (
cacheDir string
storageClient *storage.Client
ctx context.Context
)

func createMountConfigsAndEquivalentFlags() (flags [][]string) {
cacheDirPath := path.Join(os.Getenv("HOME"), "operations-cache-dir"+setup.GenerateRandomString(5))
cacheDirPath := path.Join(os.TempDir(), cacheDir)

// Set up config file with create-empty-file: true.
mountConfig1 := map[string]interface{}{
Expand Down Expand Up @@ -137,15 +144,17 @@ func TestMain(m *testing.M) {
setup.ExitWithFailureIfBothTestBucketAndMountedDirectoryFlagsAreNotSet()

// Create storage client before running tests.
ctx := context.Background()
var storageClient *storage.Client
closeStorageClient := client.CreateStorageClientWithCancel(&ctx, &storageClient)
defer func() {
err := closeStorageClient()
if err != nil {
log.Fatalf("closeStorageClient failed: %v", err)
}
}()
var err error
ctx = context.Background()
storageClient, err = client.CreateStorageClient(ctx)
if err != nil {
log.Printf("Error creating storage client: %v\n", err)
os.Exit(1)
}
defer storageClient.Close()

cacheDir = "cache-dir-operations-hns-" + strconv.FormatBool(setup.IsHierarchicalBucket(ctx, storageClient))

// To run mountedDirectory tests, we need both testBucket and mountedDirectory
// flags to be set, as operations tests validates content from the bucket.
if setup.AreBothMountedDirectoryAndTestBucketFlagsSet() {
Expand Down
6 changes: 4 additions & 2 deletions tools/integration_tests/read_cache/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"log"
"os"
"path"
"strconv"
"testing"

"cloud.google.com/go/storage"
Expand Down Expand Up @@ -67,10 +68,9 @@ const (
enableCrcCheck = true
)

var cacheDirName = "cache-dir" + setup.GenerateRandomString(5)

var (
testDirPath string
cacheDirName string
cacheDirPath string
mountFunc func([]string) error
// mount directory is where our tests run.
Expand Down Expand Up @@ -150,6 +150,8 @@ func TestMain(m *testing.M) {
}
}()

cacheDirName = "cache-dir-read-cache-hns-" + strconv.FormatBool(setup.IsHierarchicalBucket(ctx, storageClient))

setup.ExitWithFailureIfBothTestBucketAndMountedDirectoryFlagsAreNotSet()

setup.RunTestsForMountedDirectoryFlag(m)
Expand Down
26 changes: 22 additions & 4 deletions tools/integration_tests/read_large_files/read_large_files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
package read_large_files

import (
"context"
"log"
"os"
"path"
"strconv"
"testing"

"cloud.google.com/go/storage"
"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/client"
"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/mounting/static_mounting"
"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/operations"
"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/setup"
Expand All @@ -35,10 +38,15 @@ const MinReadableByteFromFile = 0
const MaxReadableByteFromFile = 500 * OneMB
const DirForReadLargeFilesTests = "dirForReadLargeFilesTests"

var FiveHundredMBFile string = "fiveHundredMBFile" + setup.GenerateRandomString(5) + ".txt"
var (
storageClient *storage.Client
ctx context.Context
FiveHundredMBFile = "fiveHundredMBFile" + setup.GenerateRandomString(5) + ".txt"
cacheDir string
)

func createMountConfigsAndEquivalentFlags() (flags [][]string) {
cacheDirPath := path.Join(os.Getenv("HOME"), "cache-dri")
cacheDirPath := path.Join(os.TempDir(), cacheDir)

// Set up config file for file cache with cache-file-for-range-read: false
mountConfig1 := map[string]interface{}{
Expand Down Expand Up @@ -70,14 +78,24 @@ func createMountConfigsAndEquivalentFlags() (flags [][]string) {
func TestMain(m *testing.M) {
setup.ParseSetUpFlags()

var err error
ctx = context.Background()
storageClient, err = client.CreateStorageClient(ctx)
if err != nil {
log.Printf("Error creating storage client: %v\n", err)
os.Exit(1)
}
defer storageClient.Close()
cacheDir = "cache-dir-read-large-files-hns-" + strconv.FormatBool(setup.IsHierarchicalBucket(ctx, storageClient))

flags := [][]string{{"--implicit-dirs"}}
mountConfigFlags := createMountConfigsAndEquivalentFlags()
flags = append(flags, mountConfigFlags...)

setup.ExitWithFailureIfBothTestBucketAndMountedDirectoryFlagsAreNotSet()

if setup.TestBucket() != "" && setup.MountedDirectory() != "" {
log.Print("Both --testbucket and --mountedDirectory can't be specified at the same time.")
if setup.TestBucket() == "" && setup.MountedDirectory() != "" {
log.Print("Please pass the name of bucket mounted at mountedDirectory to --testBucket flag.")
os.Exit(1)
}

Expand Down
12 changes: 5 additions & 7 deletions tools/integration_tests/readonly/readonly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (
"log"
"os"
"path"
"strconv"
"strings"
"testing"
"time"

"cloud.google.com/go/storage"
"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/client"
Expand Down Expand Up @@ -52,6 +52,7 @@ const RenameDir = "rename"
var (
storageClient *storage.Client
ctx context.Context
cacheDir string
)

func createTestDataForReadOnlyTests(ctx context.Context, storageClient *storage.Client) {
Expand Down Expand Up @@ -93,7 +94,7 @@ func checkErrorForObjectNotExist(err error, t *testing.T) {
}

func createMountConfigsAndEquivalentFlags() (flags [][]string) {
cacheDirPath := path.Join(os.Getenv("HOME"), "cache-dir"+setup.GenerateRandomString(5))
cacheDirPath := path.Join(os.TempDir(), cacheDir)

// Set up config file for file cache.
mountConfig := map[string]interface{}{
Expand All @@ -115,18 +116,15 @@ func TestMain(m *testing.M) {

var err error
ctx = context.Background()
var cancel context.CancelFunc

ctx, cancel = context.WithTimeout(ctx, time.Minute*20)
storageClient, err = client.CreateStorageClient(ctx)
if err != nil {
log.Printf("Error creating storage client: %v\n", err)
os.Exit(1)
}

defer cancel()
defer storageClient.Close()

cacheDir = "cache-dir-readonly-hns-" + strconv.FormatBool(setup.IsHierarchicalBucket(ctx, storageClient))

flags := [][]string{{"--o=ro", "--implicit-dirs=true"}, {"--file-mode=544", "--dir-mode=544", "--implicit-dirs=true"}}

if !testing.Short() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"log"
"os"
"testing"
"time"

"cloud.google.com/go/storage"
"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/client"
Expand Down Expand Up @@ -53,13 +52,11 @@ func TestMain(m *testing.M) {
var err error

ctx = context.Background()
ctx, cancel := context.WithTimeout(ctx, time.Minute*20)
storageClient, err = client.CreateStorageClient(ctx)
if err != nil {
log.Printf("Error creating storage client: %v\n", err)
os.Exit(1)
}
defer cancel()
defer storageClient.Close()

flags := [][]string{{"--rename-dir-limit=3", "--implicit-dirs"}, {"--rename-dir-limit=3"}}
Expand Down
27 changes: 13 additions & 14 deletions tools/integration_tests/run_tests_mounted_directory.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ sudo umount $MOUNT_DIR
# Run tests with config "file-cache: max-size-mb" static mounting.
echo "file-cache:
max-size-mb: 2
cache-dir: ./cache-dir
cache-dir: /tmp/cache-dir-operations-hns-false
" > /tmp/gcsfuse_config.yaml
gcsfuse --config-file=/tmp/gcsfuse_config.yaml $TEST_BUCKET_NAME $MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/operations/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME
Expand Down Expand Up @@ -163,7 +163,7 @@ sudo umount $MOUNT_DIR
# Run tests with config "file-cache: max-size-mb" static mounting.
echo "file-cache:
max-size-mb: 3
cache-dir: ./cache-dir
cache-dir: /tmp/cache-dir-readonly-hns-false
" > /tmp/gcsfuse_config.yaml
gcsfuse --config-file /tmp/gcsfuse_config.yaml --only-dir testDir --file-mode=544 --dir-mode=544 --implicit-dirs=true $TEST_BUCKET_NAME $MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/readonly/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME/testDir
Expand Down Expand Up @@ -261,27 +261,27 @@ sudo umount $MOUNT_DIR
# package read_large_files
# Run tests with static mounting. (flags: --implicit-dirs)
gcsfuse --implicit-dirs $TEST_BUCKET_NAME $MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/read_large_files/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/read_large_files/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME
sudo umount $MOUNT_DIR

# Run tests with config "file-cache: max-size-mb, cache-file-for-range-read".
echo "file-cache:
max-size-mb: 700
cache-file-for-range-read: true
cache-dir: ./cache-dir
cache-dir: /tmp/cache-dir-read-large-files-hns-false
" > /tmp/gcsfuse_config.yaml
gcsfuse --config-file /tmp/gcsfuse_config.yaml --implicit-dirs=true $TEST_BUCKET_NAME $MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/read_large_files/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/read_large_files/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME
sudo umount $MOUNT_DIR

# Run tests with config "file-cache: max-size-mb".
echo "file-cache:
max-size-mb: -1
cache-file-for-range-read: false
cache-dir: ./cache-dir
cache-dir: /tmp/cache-dir-read-large-files-hns-false
" > /tmp/gcsfuse_config.yaml
gcsfuse --config-file /tmp/gcsfuse_config.yaml --implicit-dirs=true $TEST_BUCKET_NAME $MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/read_large_files/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/read_large_files/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME
sudo umount $MOUNT_DIR

# package write_large_files
Expand Down Expand Up @@ -342,8 +342,8 @@ function read_cache_test_setup() {

function cleanup_test_environment() {
# Clean up any pre-existing log files and cache directory.
rm -rf /tmp/gcsfuse_read_cache_test_logs /tmp/cache-dir
mkdir -p /tmp/gcsfuse_read_cache_test_logs /tmp/cache-dir
rm -rf /tmp/gcsfuse_read_cache_test_logs /tmp/cache-dir-read-cache-hns-false
mkdir -p /tmp/gcsfuse_read_cache_test_logs /tmp/cache-dir-read-cache-hns-false
}

function generate_config_file() {
Expand All @@ -368,7 +368,7 @@ metadata-cache:
stat-cache-max-size-mb: 4
ttl-secs: $cache_ttl
type-cache-max-size-mb: 32
cache-dir: /tmp/cache-dir" > /tmp/gcsfuse_config.yaml
cache-dir: /tmp/cache-dir-read-cache-hns-false" > /tmp/gcsfuse_config.yaml
}

function run_read_cache_test() {
Expand Down Expand Up @@ -552,7 +552,7 @@ test_cases=(
)
for test_case in "${test_cases[@]}"; do
gcsfuse --kernel-list-cache-ttl-secs=-1 "$TEST_BUCKET_NAME" "$MOUNT_DIR"
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/kernel-list-cache/... -p 1 --integrationTest -v --mountedDirectory="$MOUNT_DIR" --testbucket="$TEST_BUCKET_NAME" -run "$test_case"
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/kernel_list_cache/... -p 1 --integrationTest -v --mountedDirectory="$MOUNT_DIR" --testbucket="$TEST_BUCKET_NAME" -run "$test_case"
sudo umount "$MOUNT_DIR"
done

Expand All @@ -562,7 +562,7 @@ test_cases=(
)
for test_case in "${test_cases[@]}"; do
gcsfuse --kernel-list-cache-ttl-secs=5 --rename-dir-limit=10 "$TEST_BUCKET_NAME" "$MOUNT_DIR"
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/kernel-list-cache/... -p 1 --integrationTest -v --mountedDirectory="$MOUNT_DIR" --testbucket="$TEST_BUCKET_NAME" -run "$test_case"
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/kernel_list_cache/... -p 1 --integrationTest -v --mountedDirectory="$MOUNT_DIR" --testbucket="$TEST_BUCKET_NAME" -run "$test_case"
sudo umount "$MOUNT_DIR"
done

Expand All @@ -572,7 +572,6 @@ test_cases=(
)
for test_case in "${test_cases[@]}"; do
gcsfuse --kernel-list-cache-ttl-secs=0 --stat-cache-ttl=0 --rename-dir-limit=10 "$TEST_BUCKET_NAME" "$MOUNT_DIR"
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/kernel-list-cache/... -p 1 --integrationTest -v --mountedDirectory="$MOUNT_DIR" --testbucket="$TEST_BUCKET_NAME" -run "$test_case"
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/kernel_list_cache/... -p 1 --integrationTest -v --mountedDirectory="$MOUNT_DIR" --testbucket="$TEST_BUCKET_NAME" -run "$test_case"
sudo umount "$MOUNT_DIR"
done

0 comments on commit f5bb7c9

Please sign in to comment.