chaotic_job 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +5 -3
- data/lib/chaotic_job/simulation.rb +3 -0
- data/lib/chaotic_job/version.rb +1 -1
- data/lib/chaotic_job.rb +25 -0
- metadata +4 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c84ddd59307328e8986c00f5c03da961e4d3910c4e42eb81f847e2703f2fe128
|
4
|
+
data.tar.gz: 9d65a1efddcb025569d5f97c8f87d3e5a920fee0c40f3b6d2bedf3f8c907b857
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1fe18d93d38e9e15ecb011fc578b94543b2fd8c83c017d7df3f69d0ad243d7f676e8892562c346b07e0b86631891d16465f358c5c5999b639191cad34796543
|
7
|
+
data.tar.gz: 6837ab188e03fc32cb66feb689f561bc3a7e37dd98bbdff412504876f713d6d1ac4721b4cd4d0bd217a0423cfe938064b441203cd70b60f8c2bf1fe66b687502
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.3.0] - 2024-12-17
|
4
|
+
|
5
|
+
- Ensure that assertion failure messages raised within a simulation contain the scenario description
|
6
|
+
- Add a `ChaoticJob.journal_entries` top-level method
|
7
|
+
|
3
8
|
## [0.2.0] - 2024-11-06
|
4
9
|
|
5
10
|
- Update the `perform_all` helper method to `perform_all_jobs`
|
data/README.md
CHANGED
@@ -42,6 +42,10 @@ end
|
|
42
42
|
|
43
43
|
The `ChaoticJob::Helpers` module provides 6 methods, 4 of which simply allow you to perform a job with retries in the proper way while the other 2 allow you to simulate failures and glitches.
|
44
44
|
|
45
|
+
### Glitches
|
46
|
+
|
47
|
+
A central concept in `ChaoticJob` is the _glitch_. A glitch is an error injected into the job execution flow via a [`TracePoint`](https://docs.ruby-lang.org/en/master/TracePoint.html). Glitches are transient errors, which means they occur once and only once, making them perfect for testing a job's resilience to unpredictable failures that can occur while running jobs, like network issues, upstream API outages, rate limits, or infrastructure failure. By default, `ChaoticJob` raises a custom error defined by the gem (`ChaoticJob::RetryableError`), which the internals of the gem ensure that the job under test is configured to retry on; you can, however, raise specific errors as needed when setting up your [scenarios](#simulating-failures). By forcing a retry via the error handling mechanisms of Active Job, glitches are a simple but effective way to test that your job is resilient to any kind of transient error that the job is configured to retry on.
|
48
|
+
|
45
49
|
### Performing Jobs
|
46
50
|
|
47
51
|
When testing job resilience, you will necessarily be testing how a job behaves when it retries. Unfortunately, the helpers provided by `ActiveJob::TestHelper` are tailored to testing the job's behavior on the first attempt.
|
@@ -120,7 +124,7 @@ end
|
|
120
124
|
> | `Journal.entries` | get all of the logged values under the default scope |
|
121
125
|
> | `Journal.entries(scope: :special)` | get all of the logged values under a particular scope |
|
122
126
|
|
123
|
-
In this example, the job being tested is defined within the test case. You can, of course, also test jobs defined in your application. The key detail is the `glitch` keyword argument. A "glitch" is simply a tuple that describes precisely where you would like the failure to occur. The first element of the tuple is the location of the glitch, which can be either *before* or *after
|
127
|
+
In this example, the job being tested is defined within the test case. You can, of course, also test jobs defined in your application. The key detail is the `glitch` keyword argument. A "glitch" is simply a tuple that describes precisely where you would like the failure to occur. The first element of the tuple is the location of the glitch, which can be either *before* or *after* a line of code. The second element is the location of the code that will be affected by the glitch, defined by its file path and line number. What this example scenario does is inject a glitch before the `step_3` method is called, here:
|
124
128
|
|
125
129
|
```ruby
|
126
130
|
def perform
|
@@ -131,8 +135,6 @@ def perform
|
|
131
135
|
end
|
132
136
|
```
|
133
137
|
|
134
|
-
This glitch is a transient error, which are the only kind of errors that matter when testing resilience, as permanent errors mean your job will simply end up in the dead set. So, the glitch failure will occur once and only once, this forces a retry but does not prevent the job from completing.
|
135
|
-
|
136
138
|
If you want to simulate multiple glitches affecting a job run, you can use the plural `glitches` keyword argument instead and pass an array of tuples:
|
137
139
|
|
138
140
|
```ruby
|
@@ -84,9 +84,12 @@ module ChaoticJob
|
|
84
84
|
def run_scenario(scenario, &callback)
|
85
85
|
debug "👾 Running simulation with scenario: #{scenario}"
|
86
86
|
@test.before_setup
|
87
|
+
@test.simulation_scenario = scenario.to_s
|
87
88
|
scenario.run
|
88
89
|
@test.after_teardown
|
89
90
|
callback.call(scenario)
|
91
|
+
ensure
|
92
|
+
@test.simulation_scenario = nil
|
90
93
|
end
|
91
94
|
|
92
95
|
def clone_job_template
|
data/lib/chaotic_job/version.rb
CHANGED
data/lib/chaotic_job.rb
CHANGED
@@ -23,6 +23,14 @@ module ChaoticJob
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
def self.journal_entries(scope: nil)
|
27
|
+
if scope
|
28
|
+
Journal.entries(scope: scope)
|
29
|
+
else
|
30
|
+
Journal.entries
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
26
34
|
def self.journal_size(scope: nil)
|
27
35
|
if scope
|
28
36
|
Journal.size(scope: scope)
|
@@ -40,6 +48,8 @@ module ChaoticJob
|
|
40
48
|
end
|
41
49
|
|
42
50
|
module Helpers
|
51
|
+
attr_accessor :simulation_scenario
|
52
|
+
|
43
53
|
def perform_all_jobs
|
44
54
|
Performer.perform_all
|
45
55
|
end
|
@@ -58,6 +68,7 @@ module ChaoticJob
|
|
58
68
|
kwargs = {test: self, seed: seed}
|
59
69
|
kwargs[:depth] = depth if depth
|
60
70
|
kwargs[:variations] = variations if variations
|
71
|
+
self.simulation_scenario = nil
|
61
72
|
Simulation.new(job, **kwargs).run(&block)
|
62
73
|
end
|
63
74
|
|
@@ -71,5 +82,19 @@ module ChaoticJob
|
|
71
82
|
Scenario.new(job, **kwargs).run
|
72
83
|
end
|
73
84
|
end
|
85
|
+
|
86
|
+
def assert(test, msg = nil)
|
87
|
+
return super unless @simulation_scenario
|
88
|
+
|
89
|
+
contextual_msg = lambda do
|
90
|
+
# copied from the original `assert` method in Minitest::Assertions
|
91
|
+
default_msg = "Expected #{mu_pp test} to be truthy."
|
92
|
+
custom_msg = original_msg.is_a?(Proc) ? original_msg.call : original_msg
|
93
|
+
full_msg = custom_msg || default_msg
|
94
|
+
" #{@simulation_scenario}\n#{full_msg}"
|
95
|
+
end
|
96
|
+
|
97
|
+
super(test, contextual_msg)
|
98
|
+
end
|
74
99
|
end
|
75
100
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chaotic_job
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
|
+
original_platform: ''
|
6
7
|
authors:
|
7
8
|
- Stephen Margheim
|
8
|
-
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -24,7 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '7.0'
|
27
|
-
description:
|
28
27
|
email:
|
29
28
|
- stephen.margheim@gmail.com
|
30
29
|
executables: []
|
@@ -52,7 +51,6 @@ metadata:
|
|
52
51
|
homepage_uri: https://github.com/fractaledmind/chaotic_job
|
53
52
|
source_code_uri: https://github.com/fractaledmind/chaotic_job
|
54
53
|
changelog_uri: https://github.com/fractaledmind/chaotic_job/CHANGELOG.md
|
55
|
-
post_install_message:
|
56
54
|
rdoc_options: []
|
57
55
|
require_paths:
|
58
56
|
- lib
|
@@ -67,8 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
65
|
- !ruby/object:Gem::Version
|
68
66
|
version: '0'
|
69
67
|
requirements: []
|
70
|
-
rubygems_version: 3.
|
71
|
-
signing_key:
|
68
|
+
rubygems_version: 3.6.0
|
72
69
|
specification_version: 4
|
73
70
|
summary: Test ActiveJobs for reliability and resilience.
|
74
71
|
test_files: []
|