Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to save test results to disk #64

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

hwidiapradja
Copy link

@hwidiapradja hwidiapradja commented Jun 7, 2024

💬 Summary of Changes

  • Add the ability to save test results to disk when analytics token isn't provided (opt-in by default).
    • To ensure that data is stored on to the disk, opt-in by passing true into a new environment value of BUILDKITE_ANALYTICS_CACHING_ENABLED. When this value is false, traces won't be recorded and will also prevent data from being written to disk .
    • Test results are saved into a json file, containing the data that would otherwise be sent over to the API.
    • Test results can be batched into separate files (default of 5000 items per file).
  • Addresses Github issue Allow writing test results to disk instead of uploading #49

🧾 Checklist

  • 🧐 Performed a self-review of the changes
  • ✅ Added tests to cover changes
  • 🏎 Ran Unit Tests and they all passed
  • 🏷 Labeled this PR appropriately

📝 Items of Note

Due to the app sandbox restrictions, test results can't be written to an arbitrary folder in the macOS file systems when unit tests are being run on Xcode simulators. As such, test results are saved in the app container's directory, in Documents/BuildkiteTestCollector.

@hwidiapradja hwidiapradja added the enhancement New feature or request label Jun 7, 2024
@hwidiapradja hwidiapradja marked this pull request as ready for review June 7, 2024 05:53
@hwidiapradja hwidiapradja requested a review from a team as a code owner June 7, 2024 05:53
@hwidiapradja hwidiapradja force-pushed the tech/local-result-storage branch from c830440 to 43100d7 Compare June 7, 2024 07:55
Copy link
Member

@pda pda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really good!
Sorry that we missed it earlier.

Is it still useful for you to get it merged?
Just a couple of line notes.

@@ -72,6 +72,7 @@ extension EnvironmentValues {
var analyticsBaseURL: URL? { self.url(for: "BUILDKITE_ANALYTICS_BASE_URL") }

var isAnalyticsDebugEnabled: Bool { self.bool(for: "BUILDKITE_ANALYTICS_DEBUG_ENABLED") ?? false }
var isAnalyticsCachingEnabled: Bool { self.bool(for: "BUILDKITE_ANALYTICS_CACHING_ENABLED") ?? true }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this default to false?

}

private func saveTestData(_ testData: TestResults) throws {
try fileController.saveData(testData, fileName: "TestResults-\(UUID().uuidString)", fileExtension: "json")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if a timestamp near the left of the filename would be useful for sort order, and to differentiate e.g. todays results from stale results sitting around?

Comment on lines +44 to +45
/// Whether caching is enabled.
var isCacheEnabled: Bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about calling this “cache” 🤔

I figure cache is generally an additional layer of storage, often for performance, and the cache subsystem manages writing and reading from that store.

Whereas this feels like an output mode; it's storing data in a location for some other process to pick up later (for subsequent out-of-band uploading).

Maybe it's “store local files” e.g. isStoreLocalFilesEnabled?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants