-
-
Notifications
You must be signed in to change notification settings - Fork 18
Improve coverage #138
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
Merged
Merged
Improve coverage #138
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
3b6f24a
Add SimpleCov filters for non-gem files
fractaledmind d9d4637
Add SimpleCov support for multi-database coverage merging
fractaledmind 41b8a46
Add comprehensive workflow errors tests
fractaledmind acb222a
Add Execution model tests
fractaledmind fc4d89f
Add TransactionalStep plugin tests
fractaledmind 9ea9365
Add Arguments module tests
fractaledmind dbe675f
Add Entry model tests
fractaledmind b35d818
Add Context tests
fractaledmind da83b4c
Add Engine tests
fractaledmind 0354787
Add PluginContext tests
fractaledmind 75cded5
Add error message tests
fractaledmind 52a2fc7
Add :nocov: pragmas for environment-specific code
fractaledmind 32b13e8
Raise SimpleCov minimum coverage thresholds
fractaledmind 9c3ffa3
Fix Ruby 2.7 compatibility in tests
fractaledmind f4b95cc
fix again
fractaledmind 605c5b6
Address PR review feedback
fractaledmind b211f25
Address PR review feedback
fractaledmind 0852109
Address code review suggestions
fractaledmind e60a638
Address code review suggestions
fractaledmind File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "test_helper" | ||
|
|
||
| class AcidicJob::ArgumentsTest < ActiveSupport::TestCase | ||
| # The GlobalID key used by ActiveJob for serialization | ||
| GLOBALID_KEY = "_aj_globalid" | ||
|
|
||
| # ============================================ | ||
| # deserialize_global_id | ||
| # ============================================ | ||
|
|
||
| test "deserialize_global_id locates existing record" do | ||
| thing = Thing.create! | ||
| gid_hash = { GLOBALID_KEY => thing.to_global_id.to_s } | ||
|
|
||
| result = AcidicJob::Arguments.deserialize_global_id(gid_hash) | ||
|
|
||
| assert_equal thing, result | ||
| end | ||
|
|
||
| test "deserialize_global_id returns nil for deleted record" do | ||
| thing = Thing.create! | ||
| gid_hash = { GLOBALID_KEY => thing.to_global_id.to_s } | ||
| thing.destroy! | ||
|
|
||
| result = AcidicJob::Arguments.deserialize_global_id(gid_hash) | ||
|
|
||
| assert_nil result | ||
| end | ||
|
|
||
| test "deserialize_global_id returns nil for non-existent record ID" do | ||
| # Create a GlobalID for a record that doesn't exist | ||
| gid_hash = { GLOBALID_KEY => "gid://dummy/Thing/999999" } | ||
|
|
||
| result = AcidicJob::Arguments.deserialize_global_id(gid_hash) | ||
|
|
||
| assert_nil result | ||
| end | ||
|
|
||
| # ============================================ | ||
| # convert_to_global_id_hash | ||
| # ============================================ | ||
|
|
||
| test "convert_to_global_id_hash returns GlobalID hash for persisted record" do | ||
| thing = Thing.create! | ||
|
|
||
| result = AcidicJob::Arguments.convert_to_global_id_hash(thing) | ||
|
|
||
| assert_kind_of Hash, result | ||
| assert result.key?(GLOBALID_KEY) | ||
| assert_match(/gid:\/\/.*\/Thing\/#{thing.id}/, result[GLOBALID_KEY]) | ||
| end | ||
|
|
||
| test "convert_to_global_id_hash falls back to ActiveJob serializer for new record" do | ||
| new_thing = Thing.new # not persisted, no ID | ||
|
|
||
| result = AcidicJob::Arguments.convert_to_global_id_hash(new_thing) | ||
|
|
||
| # Should use ActiveJob::Serializers.serialize which uses our NewRecordSerializer | ||
| assert_kind_of Hash, result | ||
| # The result should have some serialization key (exact key depends on serializer) | ||
| assert result.key?("_aj_serialized") || result.key?(GLOBALID_KEY) | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,216 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "test_helper" | ||
|
|
||
| class AcidicJob::ContextTest < ActiveSupport::TestCase | ||
| def create_execution | ||
| serialized_job = { | ||
| "job_class" => "TestJob", | ||
| "job_id" => SecureRandom.uuid, | ||
| "arguments" => [] | ||
| } | ||
| definition = { | ||
| "meta" => { "version" => AcidicJob::VERSION }, | ||
| "steps" => { | ||
| "step_1" => { "does" => "step_1", "then" => AcidicJob::FINISHED_RECOVERY_POINT } | ||
| } | ||
| } | ||
| AcidicJob::Execution.create!( | ||
| idempotency_key: SecureRandom.hex(32), | ||
| serialized_job: serialized_job, | ||
| definition: definition, | ||
| recover_to: "step_1" | ||
| ) | ||
| end | ||
|
|
||
| # ============================================ | ||
| # set | ||
| # ============================================ | ||
|
|
||
| test "set stores a single key-value pair" do | ||
| execution = create_execution | ||
| context = AcidicJob::Context.new(execution) | ||
|
|
||
| context.set(foo: "bar") | ||
|
|
||
| assert_equal 1, execution.values.count | ||
| assert_equal "bar", execution.values.find_by(key: "foo").value | ||
| end | ||
|
|
||
| test "set stores multiple key-value pairs" do | ||
| execution = create_execution | ||
| context = AcidicJob::Context.new(execution) | ||
|
|
||
| context.set(foo: "bar", baz: 123, qux: [ 1, 2, 3 ]) | ||
|
|
||
| assert_equal 3, execution.values.count | ||
| assert_equal "bar", execution.values.find_by(key: "foo").value | ||
| assert_equal 123, execution.values.find_by(key: "baz").value | ||
| assert_equal [ 1, 2, 3 ], execution.values.find_by(key: "qux").value | ||
| end | ||
|
|
||
| test "set upserts existing keys" do | ||
| execution = create_execution | ||
| context = AcidicJob::Context.new(execution) | ||
|
|
||
| context.set(foo: "original") | ||
| context.set(foo: "updated") | ||
|
|
||
| assert_equal 1, execution.values.count | ||
| assert_equal "updated", execution.values.find_by(key: "foo").value | ||
| end | ||
|
|
||
| # ============================================ | ||
| # get | ||
| # ============================================ | ||
|
|
||
| test "get retrieves a single value" do | ||
| execution = create_execution | ||
| context = AcidicJob::Context.new(execution) | ||
| context.set(foo: "bar") | ||
|
|
||
| result = context.get(:foo) | ||
|
|
||
| assert_equal [ "bar" ], result | ||
| end | ||
|
|
||
| test "get retrieves multiple values" do | ||
| execution = create_execution | ||
| context = AcidicJob::Context.new(execution) | ||
| context.set(foo: "bar", baz: 123) | ||
|
|
||
| result = context.get(:foo, :baz) | ||
|
|
||
| # Order is not guaranteed, so check both values are present | ||
| assert_equal 2, result.size | ||
| assert_includes result, "bar" | ||
| assert_includes result, 123 | ||
| end | ||
|
|
||
| test "get returns empty array for non-existent key" do | ||
| execution = create_execution | ||
| context = AcidicJob::Context.new(execution) | ||
|
|
||
| result = context.get(:nonexistent) | ||
|
|
||
| assert_equal [], result | ||
| end | ||
|
|
||
| # ============================================ | ||
| # fetch | ||
| # ============================================ | ||
|
|
||
| test "fetch returns existing value" do | ||
| execution = create_execution | ||
| context = AcidicJob::Context.new(execution) | ||
| context.set(foo: "existing") | ||
|
|
||
| result = context.fetch(:foo, "default") | ||
|
|
||
| assert_equal "existing", result | ||
| end | ||
|
|
||
| test "fetch uses default when key does not exist" do | ||
| execution = create_execution | ||
| context = AcidicJob::Context.new(execution) | ||
|
|
||
| result = context.fetch(:foo, "default") | ||
|
|
||
| assert_equal "default", result | ||
| # Should also store the default | ||
| assert_equal "default", execution.values.find_by(key: "foo").value | ||
| end | ||
|
|
||
| test "fetch uses block when key does not exist and no default" do | ||
| execution = create_execution | ||
| context = AcidicJob::Context.new(execution) | ||
|
|
||
| result = context.fetch(:foo) { |key| "computed_#{key}" } | ||
|
|
||
| assert_equal "computed_foo", result | ||
| assert_equal "computed_foo", execution.values.find_by(key: "foo").value | ||
| end | ||
|
|
||
| # ============================================ | ||
| # []= and [] | ||
| # ============================================ | ||
|
|
||
| test "[]= sets a value" do | ||
| execution = create_execution | ||
| context = AcidicJob::Context.new(execution) | ||
|
|
||
| context[:foo] = "bar" | ||
|
|
||
| assert_equal "bar", execution.values.find_by(key: "foo").value | ||
| end | ||
|
|
||
| test "[] gets a value" do | ||
| execution = create_execution | ||
| context = AcidicJob::Context.new(execution) | ||
| context.set(foo: "bar") | ||
|
|
||
| result = context[:foo] | ||
|
|
||
| assert_equal "bar", result | ||
| end | ||
|
|
||
| test "[] returns nil for non-existent key" do | ||
| execution = create_execution | ||
| context = AcidicJob::Context.new(execution) | ||
|
|
||
| result = context[:nonexistent] | ||
|
|
||
| assert_nil result | ||
| end | ||
|
|
||
| # ============================================ | ||
| # Integration with workflow | ||
| # ============================================ | ||
|
|
||
| # This test verifies that workflow context values persist across job retries. | ||
| # | ||
| # How it works: | ||
| # 1. First execution (executions=1): set_context stores attempt=1, then raises DefaultsError | ||
| # 2. retry_on triggers a retry, incrementing the job's `executions` counter to 2 | ||
| # 3. Second execution (executions=2): set_context stores attempt=2 (overwriting), completes successfully | ||
| # 4. read_context runs and logs the final context values | ||
| # | ||
| # The assertion checks that attempt=2 because set_context ran twice (once per execution), | ||
| # each time storing the current `executions` value. The nested data persists unchanged | ||
| # since it was set identically in both executions. | ||
| test "context persists across job retries" do | ||
| class ContextRetryJob < ActiveJob::Base | ||
| include AcidicJob::Workflow | ||
|
|
||
| retry_on DefaultsError | ||
|
|
||
| def perform | ||
| execute_workflow(unique_by: job_id) do |w| | ||
| w.step :set_context | ||
| w.step :read_context | ||
| end | ||
| end | ||
|
|
||
| def set_context | ||
| ctx[:attempt] = executions | ||
| ctx[:data] = { nested: "value" } | ||
| raise DefaultsError if executions == 1 | ||
| end | ||
|
|
||
| def read_context | ||
| ChaoticJob.log_to_journal!({ | ||
| "attempt" => ctx[:attempt], | ||
| "data" => ctx[:data] | ||
| }) | ||
| end | ||
| end | ||
|
|
||
| ContextRetryJob.perform_later | ||
| perform_all_jobs | ||
|
|
||
| entry = ChaoticJob.top_journal_entry | ||
| # After retry, attempt=2 because set_context ran twice, storing executions each time | ||
| assert_equal 2, entry["attempt"] | ||
| assert_equal "value", entry["data"][:nested] | ||
| end | ||
| end | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.