Skip to content

Commit

Permalink
refactoring based on review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ashmeenkaur committed Nov 24, 2023
1 parent 3bd9264 commit 7323f1c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
7 changes: 5 additions & 2 deletions tools/integration_tests/log_rotation/log_rotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,20 @@ func TestMain(m *testing.M) {
setup.ExitWithFailureIfBothTestBucketAndMountedDirectoryFlagsAreNotSet()

// Run tests for mountedDirectory only if --mountedDirectory flag is set.
logDirPath = path.Join("/tmp", logDirName)

logDirPath = setup.ValidateLogDirForMountedDirTests(logDirName)
logFilePath = path.Join(logDirPath, logFileName)
setup.RunTestsForMountedDirectoryFlag(m)

// Else run tests for testBucket.
// Set up test directory.
setup.SetUpTestDirForTestBucketFlag()

logDirPath = setup.SetUpLogDir(logDirName)
// Set up directory for logs.
logDirPath = setup.SetUpLogDirForTestDirTests(logDirName)
logFilePath = path.Join(logDirPath, logFileName)

// Set up config files.
configFile1 := setup.YAMLConfigFile(
getMountConfigForLogRotation(maxFileSizeMB, logFileCount, true, logFilePath),
"config1.yaml")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ func validateLogFileSize(t *testing.T, dirEntry os.DirEntry) {
func TestLogRotation(t *testing.T) {
setup.SetupTestDirectory(testDirName)

// Perform log rotation once.
runParallelOperationsInMountedDirectoryTillLogRotation(t)

// Perform log rotation 4 times.
for i := 0; i < 4; i++ {
runParallelOperationsInMountedDirectoryTillLogRotation(t)
}
// Adding 1-second sleep here because there is slight delay in compression
// of log files.
time.Sleep(1 * time.Second)
Expand Down
6 changes: 3 additions & 3 deletions tools/integration_tests/run_tests_mounted_directory.sh
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,15 @@ GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/local_file/... -p 1
sudo umount $MOUNT_DIR

# Run tests with log rotation config.
mkdir /tmp/gcsfuse_integration_test_logs
rm -r /tmp/gcsfuse_integration_test_logs
mkdir /tmp/gcsfuse_integration_test_logs
echo "logging:
file-path: /tmp/gcsfuse_integration_test_logs/log.txt
format: text
severity: trace
log-rotate:
max-file-size-mb: 1
file-count: 1
max-file-size-mb: 2
file-count: 3
compress: true
" > /tmp/gcsfuse_config.yaml
gcsfuse --config-file=/tmp/gcsfuse_config.yaml $TEST_BUCKET_NAME $MOUNT_DIR
Expand Down
17 changes: 15 additions & 2 deletions tools/integration_tests/util/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,24 @@ func SetUpTestDirForTestBucketFlag() {
}
}

func SetUpLogDir(logDirName string) (logDir string) {
func SetUpLogDirForTestDirTests(logDirName string) (logDir string) {
logDir = path.Join(TestDir(), logDirName)
err := os.Mkdir(logDir, DirPermission_0755)
if err != nil {
log.Printf("SetUpLogDir: %v\n", err)
log.Printf("os.Mkdir %s: %v\n", logDir, err)
os.Exit(1)
}
return
}

func ValidateLogDirForMountedDirTests(logDirName string) (logDir string) {
if *mountedDirectory == "" {
return ""
}
logDir = path.Join(os.TempDir(), logDirName)
_, err := os.Stat(logDir)
if err != nil {
log.Printf("validateLogDirForMountedDirTests %s: %v\n", logDir, err)
os.Exit(1)
}
return
Expand Down

0 comments on commit 7323f1c

Please sign in to comment.