Skip to content

Commit

Permalink
Persist logs in read_cache test (#2968)
Browse files Browse the repository at this point in the history
* get logs from cache test

* remove "/" from test name
  • Loading branch information
ashmeenkaur authored Feb 4, 2025
1 parent 4ad2e18 commit 22a5354
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func TestManagedFolders_FolderAdminPermission(t *testing.T) {
}

setup.MountGCSFuseWithGivenMountFunc(flags, mountFunc)
defer setup.UnmountGCSFuseAndDeleteLogFile(rootDir)
defer setup.UnmountGCSFuse(rootDir)
setup.SetMntDir(mountDir)

// Run tests on given {Bucket permission, Managed folder permission}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func TestManagedFolders_FolderViewPermission(t *testing.T) {
flags = append(flags, "--key-file="+localKeyFilePath)
}
setup.MountGCSFuseWithGivenMountFunc(flags, mountFunc)
defer setup.UnmountGCSFuseAndDeleteLogFile(rootDir)
defer setup.UnmountGCSFuse(rootDir)
setup.SetMntDir(mountDir)

bucket, testDir = setup.GetBucketAndObjectBasedOnTypeOfMount(TestDirForManagedFolderTest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"log"
"path"
"strings"
"sync"
"testing"

Expand Down Expand Up @@ -50,6 +51,9 @@ func (s *cacheFileForRangeReadFalseTest) Setup(t *testing.T) {
}

func (s *cacheFileForRangeReadFalseTest) Teardown(t *testing.T) {
if t.Failed() {
setup.SaveLogFileToKOKOROArtifact("gcsfuse-failed-integration-test-logs-" + strings.Replace(t.Name(), "/", "-", -1))
}
setup.UnmountGCSFuseAndDeleteLogFile(rootDir)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"log"
"path"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -47,6 +48,9 @@ func (s *cacheFileForRangeReadTrueTest) Setup(t *testing.T) {
}

func (s *cacheFileForRangeReadTrueTest) Teardown(t *testing.T) {
if t.Failed() {
setup.SaveLogFileToKOKOROArtifact("gcsfuse-failed-integration-test-logs-" + strings.Replace(t.Name(), "/", "-", -1))
}
setup.UnmountGCSFuseAndDeleteLogFile(rootDir)
}

Expand Down
4 changes: 4 additions & 0 deletions tools/integration_tests/read_cache/disabled_cache_ttl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package read_cache
import (
"context"
"log"
"strings"
"testing"

"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/client"
Expand Down Expand Up @@ -46,6 +47,9 @@ func (s *disabledCacheTTLTest) Setup(t *testing.T) {
}

func (s *disabledCacheTTLTest) Teardown(t *testing.T) {
if t.Failed() {
setup.SaveLogFileToKOKOROArtifact("gcsfuse-failed-integration-test-logs-" + strings.Replace(t.Name(), "/", "-", -1))
}
setup.UnmountGCSFuseAndDeleteLogFile(rootDir)
}

Expand Down
4 changes: 4 additions & 0 deletions tools/integration_tests/read_cache/job_chunk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"log"
"path"
"strings"
"sync"
"testing"

Expand Down Expand Up @@ -51,6 +52,9 @@ func (s *jobChunkTest) Setup(t *testing.T) {
}

func (s *jobChunkTest) Teardown(t *testing.T) {
if t.Failed() {
setup.SaveLogFileToKOKOROArtifact("gcsfuse-failed-integration-test-logs-" + strings.Replace(t.Name(), "/", "-", -1))
}
setup.UnmountGCSFuseAndDeleteLogFile(rootDir)
}

Expand Down
4 changes: 4 additions & 0 deletions tools/integration_tests/read_cache/local_modification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"log"
"path"
"strings"
"testing"

"cloud.google.com/go/storage"
Expand Down Expand Up @@ -45,6 +46,9 @@ func (s *localModificationTest) Setup(t *testing.T) {
}

func (s *localModificationTest) Teardown(t *testing.T) {
if t.Failed() {
setup.SaveLogFileToKOKOROArtifact("gcsfuse-failed-integration-test-logs-" + strings.Replace(t.Name(), "/", "-", -1))
}
setup.UnmountGCSFuseAndDeleteLogFile(rootDir)
}

Expand Down
4 changes: 4 additions & 0 deletions tools/integration_tests/read_cache/range_read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package read_cache
import (
"context"
"log"
"strings"
"testing"

"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/client"
Expand Down Expand Up @@ -47,6 +48,9 @@ func (s *rangeReadTest) Setup(t *testing.T) {
}

func (s *rangeReadTest) Teardown(t *testing.T) {
if t.Failed() {
setup.SaveLogFileToKOKOROArtifact("gcsfuse-failed-integration-test-logs-" + strings.Replace(t.Name(), "/", "-", -1))
}
setup.UnmountGCSFuseAndDeleteLogFile(rootDir)
}

Expand Down
4 changes: 4 additions & 0 deletions tools/integration_tests/read_cache/read_only_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package read_cache
import (
"context"
"log"
"strings"
"testing"

"cloud.google.com/go/storage"
Expand Down Expand Up @@ -45,6 +46,9 @@ func (s *readOnlyTest) Setup(t *testing.T) {
}

func (s *readOnlyTest) Teardown(t *testing.T) {
if t.Failed() {
setup.SaveLogFileToKOKOROArtifact("gcsfuse-failed-integration-test-logs-" + strings.Replace(t.Name(), "/", "-", -1))
}
setup.UnmountGCSFuseAndDeleteLogFile(rootDir)
}

Expand Down
4 changes: 4 additions & 0 deletions tools/integration_tests/read_cache/remount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"log"
"path"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -47,6 +48,9 @@ func (s *remountTest) Setup(t *testing.T) {
}

func (s *remountTest) Teardown(t *testing.T) {
if t.Failed() {
setup.SaveLogFileToKOKOROArtifact("gcsfuse-failed-integration-test-logs-" + strings.Replace(t.Name(), "/", "-", -1))
}
setup.UnmountGCSFuseAndDeleteLogFile(rootDir)
}

Expand Down
3 changes: 3 additions & 0 deletions tools/integration_tests/read_cache/small_cache_ttl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ func (s *smallCacheTTLTest) Setup(t *testing.T) {
}

func (s *smallCacheTTLTest) Teardown(t *testing.T) {
if t.Failed() {
setup.SaveLogFileToKOKOROArtifact("gcsfuse-failed-integration-test-logs-" + strings.Replace(t.Name(), "/", "-", -1))
}
setup.UnmountGCSFuseAndDeleteLogFile(rootDir)
}

Expand Down
16 changes: 10 additions & 6 deletions tools/integration_tests/util/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,16 @@ func SaveLogFileInCaseOfFailure(successCode int) {
if successCode != 0 {
// Logfile name will be gcsfuse-failed-integration-test-log-xxxxx
failedlogsFileName := "gcsfuse-failed-integration-test-logs-" + GenerateRandomString(5)
log.Printf("log file is available on kokoro artifacts with file name: %s", failedlogsFileName)
logFileInKokoroArtifact := path.Join(os.Getenv("KOKORO_ARTIFACTS_DIR"), failedlogsFileName)
err := operations.CopyFile(logFile, logFileInKokoroArtifact)
if err != nil {
log.Fatalf("Error in coping logfile in kokoro artifact: %v", err)
}
SaveLogFileToKOKOROArtifact(failedlogsFileName)
}
}

func SaveLogFileToKOKOROArtifact(artifactName string) {
log.Printf("log file is available on kokoro artifacts with file name: %s", artifactName)
logFileInKokoroArtifact := path.Join(os.Getenv("KOKORO_ARTIFACTS_DIR"), artifactName)
err := operations.CopyFile(logFile, logFileInKokoroArtifact)
if err != nil {
log.Fatalf("Error in coping logfile in kokoro artifact: %v", err)
}
}

Expand Down

0 comments on commit 22a5354

Please sign in to comment.