Module: Smith::Doctor::Checks::Serialization
- Defined in:
- lib/smith/doctor/checks/serialization.rb
Class Method Summary collapse
- .build_probe_class ⇒ Object
- .check_from_state(report) ⇒ Object
- .check_json_roundtrip(report) ⇒ Object
- .check_resume(report) ⇒ Object
- .check_to_state(report) ⇒ Object
- .run(report) ⇒ Object
Class Method Details
.build_probe_class ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/smith/doctor/checks/serialization.rb', line 68 def self.build_probe_class Class.new(::Smith::Workflow) do initial_state :idle state :done transition :finish, from: :idle, to: :done end end |
.check_from_state(report) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/smith/doctor/checks/serialization.rb', line 42 def self.check_from_state(report) klass = build_probe_class parsed = JSON.parse(JSON.generate(klass.new.to_state)) restored = klass.from_state(parsed) valid = restored.state == :idle report.add( name: "serialization.from_state", status: valid ? :pass : :fail, message: valid ? "from_state restores workflow" : "from_state produced invalid state" ) rescue StandardError => e report.add(name: "serialization.from_state", status: :fail, message: "from_state failed", detail: e.) end |
.check_json_roundtrip(report) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/smith/doctor/checks/serialization.rb', line 28 def self.check_json_roundtrip(report) state = build_probe_class.new.to_state parsed = JSON.parse(JSON.generate(state)) valid = parsed.is_a?(Hash) && parsed.key?("state") report.add( name: "serialization.json_roundtrip", status: valid ? :pass : :fail, message: valid ? "JSON round-trip preserves state" : "JSON round-trip corrupts state" ) rescue StandardError => e report.add(name: "serialization.json_roundtrip", status: :fail, message: "JSON round-trip failed", detail: e.) end |
.check_resume(report) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/smith/doctor/checks/serialization.rb', line 56 def self.check_resume(report) result = build_probe_class.new.run! valid = result.state == :done report.add( name: "serialization.resume", status: valid ? :pass : :fail, message: valid ? "Workflow completes after restore" : "Workflow did not reach terminal state" ) rescue StandardError => e report.add(name: "serialization.resume", status: :fail, message: "Resume failed", detail: e.) end |
.check_to_state(report) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/smith/doctor/checks/serialization.rb', line 16 def self.check_to_state(report) state = build_probe_class.new.to_state valid = state.is_a?(Hash) && state.key?(:state) && state.key?(:class) report.add( name: "serialization.to_state", status: valid ? :pass : :fail, message: valid ? "to_state produces valid Hash" : "to_state output is malformed" ) rescue StandardError => e report.add(name: "serialization.to_state", status: :fail, message: "to_state failed", detail: e.) end |
.run(report) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/smith/doctor/checks/serialization.rb', line 9 def self.run(report) check_to_state(report) check_json_roundtrip(report) check_from_state(report) check_resume(report) end |