obs-status-service: add --test-run using interface-based Redis mock (fixes #113) #123
Reference in New Issue
Block a user
Delete Branch "schrodinger/autogits:issue-113"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR adds a --test-run mode to obs-status-service to allow local development without requiring access to OBS Redis.
The implementation follows an interface-based design for the Redis client, allowing a clean separation between the real Redis client and a mock implementation (redismock.go), while keeping production logic unchanged.
This approach avoids conditional logic in the core code paths and aligns with the design discussed in #113.
Fixes #113.
@@ -21,2 +26,3 @@if err != nil {panic(err)common.LogError("Invalid Redis URL", err)returnWhy no more panic()?
I removed panic because I think that this code runs in a long-lived service so like any invalid Redis URL might give a runtime error, so logging the error and exiting cleanly felt more appropriate than crashing with a stack trace.
This also keeps the behavior consistent with the --test-run mode, where we want predictable startup failures instead of panics.
If you prefer keeping panic here for consistency with the rest of the codebase, I’m happy to switch it back.
Invalid Redis URL means we cannot start so it's fine to panic(). in *testRun you're already not calling this function anyway. Maybe have an error log here too and then panic.
It's long running only when it has an actual URL to try.
Ok I understand, thanks for the clarification!
I’ve updated RedisConnect to panic on an invalid Redis URL.
bb37ea8718toac19fecf01ac19fecf01tod563763f63d563763f63to7730b39b0fOne improvement that we can do here is to use the current existing testing files instead of hardcoding the values.
We've two json files (
factory.results.json.bz2andgcc15.results.json.bz2) already in the repository with sample data like:So what can we do is to unzip those files, maybe just
factory.results.json.bz2, like what we are doing right now inmain_test.go, and iterate over theBuildResultarray to build the mock return.7730b39b0fto3e69597d66I understand the suggestion.
I’ve refactored the mock to reuse the existing .json.bz2 test data instead of hardcoded values. The mock now loads factory.results.json.bz2, parses the BuildResult array, and dynamically generates the ScanType and HGetAll responses from it.
Looks good. It's true that instead of iterating over the results and building the return data for every request, we can do that once and store the pre-calculated data. But this is for testing so we don't need to be performant.
3e69597d66tofeb589f571I rebased this branch onto the latest main, after that the integration tests started failing in some workflow-related tests.
This PR only touches obs-status-service, so I’m not sure if the failures are related to these changes. I’m seeing the same failures on my issue-114 branch as well after rebasing.
Just wanted to flag it, let me know if you’d like me to dig into it further.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.