diff --git a/tools/integration_tests/log_rotation/log_rotation_test.go b/tools/integration_tests/log_rotation/log_rotation_test.go index 6381b69474..a49582a9d0 100644 --- a/tools/integration_tests/log_rotation/log_rotation_test.go +++ b/tools/integration_tests/log_rotation/log_rotation_test.go @@ -65,7 +65,8 @@ 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) @@ -73,9 +74,11 @@ func TestMain(m *testing.M) { // 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") diff --git a/tools/integration_tests/log_rotation/logrotate_logfile_test.go b/tools/integration_tests/log_rotation/logrotate_logfile_test.go index ffa40b730c..737328dbb6 100644 --- a/tools/integration_tests/log_rotation/logrotate_logfile_test.go +++ b/tools/integration_tests/log_rotation/logrotate_logfile_test.go @@ -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) diff --git a/tools/integration_tests/run_tests_mounted_directory.sh b/tools/integration_tests/run_tests_mounted_directory.sh index 56254ebb7d..8537e16408 100755 --- a/tools/integration_tests/run_tests_mounted_directory.sh +++ b/tools/integration_tests/run_tests_mounted_directory.sh @@ -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 diff --git a/tools/integration_tests/util/setup/setup.go b/tools/integration_tests/util/setup/setup.go index 2967d51271..5bff1c8974 100644 --- a/tools/integration_tests/util/setup/setup.go +++ b/tools/integration_tests/util/setup/setup.go @@ -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