Module: SolidObjects::TestHelper
- Defined in:
- lib/solid_objects/test_helper.rb,
sig/generated/lib/solid_objects/test_helper.rbs
Class Method Summary collapse
-
.actor_owned_models ⇒ Array[Class]
Children first, so the order is safe whether or not the cascade fires.
- .included(test_case) ⇒ void
-
.reset_actors! ⇒ void
Deleting instances alone left every other actor-owned row to the database cascade.
Instance Method Summary collapse
- #build_solid_objects_runners(roles) ⇒ Array[Worker | EffectExecutor | ReminderScheduler | BroadcastExecutor]
- #drain_solid_objects(roles: [ :reminders, :actors, :effects, :broadcasts ], max_passes: 1_000) ⇒ Integer
- #reset_actors! ⇒ void
- #solid_objects_runner_result(runner) ⇒ Integer
Class Method Details
.actor_owned_models ⇒ Array[Class]
Children first, so the order is safe whether or not the cascade fires.
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/solid_objects/test_helper.rb', line 32 def actor_owned_models [ DeadLetter, ClaimedMessage, ReadyMessage, Broadcast, Effect, Reminder, Message, Instance ] end |
.included(test_case) ⇒ void
This method returns an undefined value.
9 10 11 12 13 |
# File 'lib/solid_objects/test_helper.rb', line 9 def included(test_case) test_case.use_transactional_tests = false if test_case.respond_to?(:use_transactional_tests=) test_case.setup { reset_actors! } test_case.teardown { reset_actors! } end |
.reset_actors! ⇒ void
This method returns an undefined value.
Deleting instances alone left every other actor-owned row to the database cascade. That cascade is not enforced everywhere: SQLite has to be asked for foreign keys, MySQL has to be on InnoDB, and a host application may have stripped the constraints out of the copied migration. Where it does not fire, rows survive into the next test with an instance_id pointing at nothing, and a test that reads them sees another test's data. Deleting each table costs nothing and does not depend on referential integrity.
24 25 26 27 28 |
# File 'lib/solid_objects/test_helper.rb', line 24 def reset_actors! SolidObjects.reset_caller_process! actor_owned_models.each(&:delete_all) Process.delete_all end |
Instance Method Details
#build_solid_objects_runners(roles) ⇒ Array[Worker | EffectExecutor | ReminderScheduler | BroadcastExecutor]
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/solid_objects/test_helper.rb', line 74 def build_solid_objects_runners(roles) unknown_roles = roles - [ :actors, :effects, :reminders, :broadcasts ] raise ArgumentError, "unknown Solid Objects test roles: #{unknown_roles.join(", ")}" if unknown_roles.any? runners = {} runners[:actors] = Worker.new if roles.include?(:actors) runners[:effects] = EffectExecutor.new if roles.include?(:effects) runners[:reminders] = ReminderScheduler.new if roles.include?(:reminders) runners[:broadcasts] = BroadcastExecutor.new if roles.include?(:broadcasts) [ runners[:reminders], runners[:actors], runners[:effects], runners[:actors], runners[:broadcasts] ].compact end |
#drain_solid_objects(roles: [ :reminders, :actors, :effects, :broadcasts ], max_passes: 1_000) ⇒ Integer
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/solid_objects/test_helper.rb', line 52 def drain_solid_objects( roles: [ :reminders, :actors, :effects, :broadcasts ], max_passes: 1_000 ) runners = build_solid_objects_runners(roles) total = 0 max_passes.times do processed = runners.sum { |runner| solid_objects_runner_result(runner) } break if processed.zero? total += processed end total ensure runners&.uniq&.each(&:stop) end |
#reset_actors! ⇒ void
This method returns an undefined value.
47 48 49 |
# File 'lib/solid_objects/test_helper.rb', line 47 def reset_actors! TestHelper.reset_actors! end |
#solid_objects_runner_result(runner) ⇒ Integer
94 95 96 97 98 99 |
# File 'lib/solid_objects/test_helper.rb', line 94 def solid_objects_runner_result(runner) result = runner.run_once return result if result.is_a?(Integer) result ? 1 : 0 end |