chaotic_job 0.9.1 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 69ba3f56584d3a5c325f63635d547c3959a911e2b435ac7138e3d894b738ca71
4
- data.tar.gz: 6ca762936806d56ca6daf75777eb9dffe3f392769f6084acaecc1b29065f02e9
3
+ metadata.gz: fdea10dcc7bacf98d54e4281e1739576fe7512d305d4c431f0e0a143b7739c79
4
+ data.tar.gz: 98f16351090d9aae7bbf408fc81e392a9c9f7fb199c229866a89e56d03b3aaee
5
5
  SHA512:
6
- metadata.gz: d56bcb11292c634407d4f05880747e0da4c56b88c99d7c24d128ea66d559c5fc86e59cbb49abc93ca07434fb02c7db11a0f4083d31b3c929ba1f1ca5a69214ad
7
- data.tar.gz: f2ad5c18837b2f186cbeb58da5ce59ba751649516a6b381dcf3a7c018fda68d73cbcb284e81315064f000f64767ab05200bfe4cacd00969722deb0baf0bf903a
6
+ metadata.gz: 7babde960cf8d244d49e3d7e6f3b486f8466df777e000d899f1e8bc41cd5044517efecbf21d825a20bbac73431e2d794813de5fda78c90fdeb03e8c15810570a
7
+ data.tar.gz: 5a1f7caf42a3293b1184e8c4ac5811a2e97d53d08fa81f3c886de3a50ca6827c4bcfd66d534d8e6fa77d0d42f97016aa52848c34cbfffda564b4e630bc1fd773
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.10.0] - 2025-06-18
4
+
5
+ - Run the assertions block within the scenario run to ensure the glitch is executed [#17](https://github.com/fractaledmind/chaotic_job/pull/17)
6
+ - Add a Switch class to allow tests to control a binary switch [#18](https://github.com/fractaledmind/chaotic_job/pull/18)
7
+
8
+ ## [0.9.2] - 2025-06-17
9
+
10
+ - Allow option to constrain which jobs are performed for a `Simulation` [#16](https://github.com/fractaledmind/chaotic_job/pull/16)
11
+ - Make the jobs run for a `Simulation` have a distinct `job_id` with glitch details [#15](https://github.com/fractaledmind/chaotic_job/pull/15)
12
+
3
13
  ## [0.9.1] - 2025-06-12
4
14
 
5
15
  - The simulation tracer should only capture events on the template job [#14](https://github.com/fractaledmind/chaotic_job/pull/14)
@@ -5,13 +5,14 @@
5
5
  # Simulation.new(job).scenarios
6
6
  module ChaoticJob
7
7
  class Simulation
8
- def initialize(job, callstack: nil, variations: nil, test: nil, seed: nil)
8
+ def initialize(job, callstack: nil, variations: nil, test: nil, seed: nil, perform_only_jobs_within: nil)
9
9
  @template = job
10
10
  @callstack = callstack || capture_callstack
11
11
  @variations = variations
12
12
  @test = test
13
13
  @seed = seed || Random.new_seed
14
14
  @random = Random.new(@seed)
15
+ @perform_only_jobs_within = perform_only_jobs_within
15
16
 
16
17
  raise Error.new("callstack must be a generated via ChaoticJob::Tracer") unless @callstack.is_a?(Stack)
17
18
  end
@@ -41,6 +42,7 @@ module ChaoticJob
41
42
  variants.map do |(event, key)|
42
43
  job = clone_job_template
43
44
  glitch = Glitch.public_send(event, key)
45
+ job.job_id = [job.job_id.split("-").first, glitch.event, glitch.key].join("-")
44
46
  Scenario.new(job, glitch: glitch)
45
47
  end
46
48
  end
@@ -63,10 +65,19 @@ module ChaoticJob
63
65
  debug "👾 Running simulation with scenario: #{scenario}"
64
66
  @test.before_setup
65
67
  @test.simulation_scenario = scenario
66
- scenario.run
68
+
69
+ if @perform_only_jobs_within
70
+ scenario.run do
71
+ Performer.perform_all_before(@perform_only_jobs_within)
72
+ assertions.call(scenario)
73
+ end
74
+ else
75
+ scenario.run
76
+ assertions.call(scenario)
77
+ end
78
+
67
79
  @test.after_teardown
68
80
  @test.assert scenario.glitched?, "Scenario did not execute glitch: #{scenario.glitch}"
69
- assertions.call(scenario)
70
81
  ensure
71
82
  @test.simulation_scenario = nil
72
83
  end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ChaoticJob
4
+ module Switch
5
+ extend self
6
+
7
+ def on?
8
+ @value ||= false
9
+ true == @value
10
+ end
11
+
12
+ def off?
13
+ @value ||= false
14
+ false == @value
15
+ end
16
+
17
+ def on!
18
+ @value = true
19
+ end
20
+
21
+ def off!
22
+ @value = false
23
+ end
24
+ end
25
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ChaoticJob
4
- VERSION = "0.9.1"
4
+ VERSION = "0.10.0"
5
5
  end
data/lib/chaotic_job.rb CHANGED
@@ -7,6 +7,7 @@ require_relative "chaotic_job/tracer"
7
7
  require_relative "chaotic_job/glitch"
8
8
  require_relative "chaotic_job/scenario"
9
9
  require_relative "chaotic_job/simulation"
10
+ require_relative "chaotic_job/switch"
10
11
  require "set"
11
12
 
12
13
  module ChaoticJob
@@ -62,6 +63,10 @@ module ChaoticJob
62
63
  end
63
64
  end
64
65
 
66
+ def self.switch
67
+ Switch
68
+ end
69
+
65
70
  module Helpers
66
71
  attr_accessor :simulation_scenario
67
72
 
@@ -78,11 +83,12 @@ module ChaoticJob
78
83
  Performer.perform_all_after(time)
79
84
  end
80
85
 
81
- def run_simulation(job, variations: nil, callstack: nil, &block)
86
+ def run_simulation(job, variations: nil, callstack: nil, perform_only_jobs_within: nil, &block)
82
87
  seed = defined?(RSpec) ? RSpec.configuration.seed : Minitest.seed
83
88
  kwargs = {test: self, seed: seed}
84
89
  kwargs[:variations] = variations if variations
85
90
  kwargs[:callstack] = callstack if callstack
91
+ kwargs[:perform_only_jobs_within] = perform_only_jobs_within if perform_only_jobs_within
86
92
  self.simulation_scenario = nil
87
93
  Simulation.new(job, **kwargs).run(&block)
88
94
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chaotic_job
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Margheim
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-06-12 00:00:00.000000000 Z
10
+ date: 2025-06-17 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activejob
@@ -41,6 +41,7 @@ files:
41
41
  - lib/chaotic_job/performer.rb
42
42
  - lib/chaotic_job/scenario.rb
43
43
  - lib/chaotic_job/simulation.rb
44
+ - lib/chaotic_job/switch.rb
44
45
  - lib/chaotic_job/tracer.rb
45
46
  - lib/chaotic_job/version.rb
46
47
  - sig/chaotic_job.rbs