Skip to content

Commit

Permalink
Remove derivedFrom data when it is too big (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
TAGraves authored Nov 25, 2024
1 parent 691a2b5 commit aad1913
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 11 deletions.
1 change: 1 addition & 0 deletions internal/backend/local/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ func (c Client) UpdateTestResults(
_ context.Context,
_ string,
testResults v1.TestResults,
_ bool,
) ([]backend.TestResultsUploadResult, error) {
if c.Timings == nil {
c.Timings = make(map[string]time.Duration)
Expand Down
2 changes: 1 addition & 1 deletion internal/backend/local/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ var _ = Describe("local backend client", func() {
})

JustBeforeEach(func() {
uploadResults, err = client.UpdateTestResults(context.Background(), suiteID, testResults)
uploadResults, err = client.UpdateTestResults(context.Background(), suiteID, testResults, true)
})

It("updates the timings file", func() {
Expand Down
23 changes: 23 additions & 0 deletions internal/backend/remote/update_test_results.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func (c Client) UpdateTestResults(
ctx context.Context,
testSuite string,
testResults v1.TestResults,
adjustDerivedFromDueToContentLength bool,
) ([]backend.TestResultsUploadResult, error) {
if testSuite == "" {
return nil, errors.NewInputError("test suite name required")
Expand Down Expand Up @@ -191,6 +192,28 @@ func (c Client) UpdateTestResults(
}

fileSizeLookup[testResultsFile.ExternalID] = fileInfo.Size()

// strip out derivedFrom when over 5MB
if adjustDerivedFromDueToContentLength && fileInfo.Size() > 5242880 {
c.Log.Warnf("removing original test result data from uploaded Captain test results due to content size threshold")
cleanedDerivedFrom := make([]v1.OriginalTestResults, len(testResults.DerivedFrom))

for i, originalTestResults := range testResults.DerivedFrom {
cleanedDerivedFrom[i] = v1.OriginalTestResults{
OriginalFilePath: originalTestResults.OriginalFilePath,
GroupNumber: originalTestResults.GroupNumber,
Contents: "W29taXR0ZWRd", // base64 encoded "[omitted]"
}
}
testResultsWithoutDerivedFrom := v1.TestResults{
Framework: testResults.Framework,
Summary: testResults.Summary,
Tests: testResults.Tests,
OtherErrors: testResults.OtherErrors,
DerivedFrom: cleanedDerivedFrom,
}
return c.UpdateTestResults(ctx, testSuite, testResultsWithoutDerivedFrom, false)
}
}

testResultsFiles, err = c.registerTestResults(ctx, testSuite, testResultsFiles)
Expand Down
10 changes: 5 additions & 5 deletions internal/backend/remote/update_test_results_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ var _ = Describe("Uploading Test Results", func() {
})

It("registers, uploads, and updates the test result in sequence", func() {
uploadResults, err := apiClient.UpdateTestResults(context.Background(), "test suite id", testResults)
uploadResults, err := apiClient.UpdateTestResults(context.Background(), "test suite id", testResults, true)
Expect(err).To(Succeed())
Expect(uploadResults).To(HaveLen(1))
Expect(uploadResults[0].Uploaded).To(Equal(true))
Expand Down Expand Up @@ -132,7 +132,7 @@ var _ = Describe("Uploading Test Results", func() {
})

It("registers, uploads, and updates the test result in sequence", func() {
uploadResults, err := apiClient.UpdateTestResults(context.Background(), "test suite id", testResults)
uploadResults, err := apiClient.UpdateTestResults(context.Background(), "test suite id", testResults, true)
Expect(err).To(Succeed())
Expect(uploadResults).To(HaveLen(1))
Expect(uploadResults[0].Uploaded).To(Equal(true))
Expand All @@ -148,7 +148,7 @@ var _ = Describe("Uploading Test Results", func() {
})

It("returns an error to the user", func() {
uploadResults, err := apiClient.UpdateTestResults(context.Background(), "test suite id", testResults)
uploadResults, err := apiClient.UpdateTestResults(context.Background(), "test suite id", testResults, true)
Expect(uploadResults).To(BeNil())
Expect(err).ToNot(Succeed())
})
Expand Down Expand Up @@ -188,7 +188,7 @@ var _ = Describe("Uploading Test Results", func() {
})

It("updates the upload status as failed", func() {
uploadResults, err := apiClient.UpdateTestResults(context.Background(), "test suite id", testResults)
uploadResults, err := apiClient.UpdateTestResults(context.Background(), "test suite id", testResults, true)
Expect(err).To(Succeed())
Expect(uploadResults).To(HaveLen(1))
Expect(uploadResults[0].Uploaded).To(Equal(false))
Expand Down Expand Up @@ -225,7 +225,7 @@ var _ = Describe("Uploading Test Results", func() {
})

It("does not return an error to the user", func() {
uploadResults, err := apiClient.UpdateTestResults(context.Background(), "test suite id", testResults)
uploadResults, err := apiClient.UpdateTestResults(context.Background(), "test suite id", testResults, true)
Expect(err).To(Succeed())
Expect(uploadResults).To(HaveLen(1))
Expect(uploadResults[0].Uploaded).To(Equal(true))
Expand Down
2 changes: 1 addition & 1 deletion internal/backend/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
type Client interface {
GetRunConfiguration(ctx context.Context, testSuiteIdentifier string) (RunConfiguration, error)
GetTestTimingManifest(context.Context, string) ([]testing.TestFileTiming, error)
UpdateTestResults(context.Context, string, v1.TestResults) ([]TestResultsUploadResult, error)
UpdateTestResults(context.Context, string, v1.TestResults, bool) ([]TestResultsUploadResult, error)
}

type QuarantinedTest struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ func (s Service) reportTestResults(
return nil, nil
}

result, err := s.API.UpdateTestResults(ctx, cfg.SuiteID, newlyExecutedTestResults)
result, err := s.API.UpdateTestResults(ctx, cfg.SuiteID, newlyExecutedTestResults, true)
if err != nil {
return nil, errors.Wrap(err, "unable to update test results")
}
Expand Down
4 changes: 4 additions & 0 deletions internal/cli/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ var _ = Describe("Run", func() {
_ context.Context,
_ string,
_ v1.TestResults,
_ bool,
) ([]backend.TestResultsUploadResult, error) {
testResultsFileUploaded = true
return []backend.TestResultsUploadResult{{OriginalPaths: []string{testResultsFilePath}, Uploaded: true}}, nil
Expand Down Expand Up @@ -556,6 +557,7 @@ var _ = Describe("Run", func() {
_ context.Context,
_ string,
testResults v1.TestResults,
_ bool,
) ([]backend.TestResultsUploadResult, error) {
testResultsFileUploaded = true

Expand Down Expand Up @@ -1032,6 +1034,7 @@ var _ = Describe("Run", func() {
_ context.Context,
_ string,
_ v1.TestResults,
_ bool,
) ([]backend.TestResultsUploadResult, error) {
testResultsFileUploaded = true

Expand Down Expand Up @@ -1159,6 +1162,7 @@ var _ = Describe("Run", func() {
_ context.Context,
_ string,
testResults v1.TestResults,
_ bool,
) ([]backend.TestResultsUploadResult, error) {
testResultsFileUploaded = true

Expand Down
2 changes: 1 addition & 1 deletion internal/cli/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (s Service) UpdateTestResults(
return nil, errors.WithStack(err)
}

result, err := s.API.UpdateTestResults(ctx, testSuiteID, *parsedResults)
result, err := s.API.UpdateTestResults(ctx, testSuiteID, *parsedResults, true)
if err != nil {
return nil, errors.Wrap(err, "unable to update test results")
}
Expand Down
5 changes: 3 additions & 2 deletions internal/mocks/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
type API struct {
MockGetRunConfiguration func(context.Context, string) (backend.RunConfiguration, error)
MockGetTestTimingManifest func(context.Context, string) ([]testing.TestFileTiming, error)
MockUpdateTestResults func(context.Context, string, v1.TestResults) (
MockUpdateTestResults func(context.Context, string, v1.TestResults, bool) (
[]backend.TestResultsUploadResult, error,
)
}
Expand Down Expand Up @@ -47,9 +47,10 @@ func (a *API) UpdateTestResults(
ctx context.Context,
testSuiteID string,
testResults v1.TestResults,
_ bool,
) ([]backend.TestResultsUploadResult, error) {
if a.MockUpdateTestResults != nil {
return a.MockUpdateTestResults(ctx, testSuiteID, testResults)
return a.MockUpdateTestResults(ctx, testSuiteID, testResults, true)
}

return nil, errors.NewInternalError("MockUpdateTestResults was not configured")
Expand Down

0 comments on commit aad1913

Please sign in to comment.