working_helpers.rb 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. require 'rails_helper'
  2. shared_examples_for WorkingHelpers do
  3. describe "recent_error_logs?" do
  4. it "returns true if last_error_log_at is near last_event_at" do
  5. agent = described_class.new
  6. agent.last_error_log_at = 10.minutes.ago
  7. agent.last_event_at = 10.minutes.ago
  8. expect(agent.recent_error_logs?).to be_truthy
  9. agent.last_error_log_at = 11.minutes.ago
  10. agent.last_event_at = 10.minutes.ago
  11. expect(agent.recent_error_logs?).to be_truthy
  12. agent.last_error_log_at = 5.minutes.ago
  13. agent.last_event_at = 10.minutes.ago
  14. expect(agent.recent_error_logs?).to be_truthy
  15. agent.last_error_log_at = 15.minutes.ago
  16. agent.last_event_at = 10.minutes.ago
  17. expect(agent.recent_error_logs?).to be_falsey
  18. agent.last_error_log_at = 2.days.ago
  19. agent.last_event_at = 10.minutes.ago
  20. expect(agent.recent_error_logs?).to be_falsey
  21. end
  22. end
  23. describe "received_event_without_error?" do
  24. before do
  25. @agent = described_class.new
  26. end
  27. it "should return false until the first event was received" do
  28. expect(@agent.received_event_without_error?).to eq(false)
  29. @agent.last_receive_at = Time.now
  30. expect(@agent.received_event_without_error?).to eq(true)
  31. end
  32. it "should return false when the last error occured after the last received event" do
  33. @agent.last_receive_at = Time.now - 1.minute
  34. @agent.last_error_log_at = Time.now
  35. expect(@agent.received_event_without_error?).to eq(false)
  36. end
  37. it "should return true when the last received event occured after the last error" do
  38. @agent.last_receive_at = Time.now
  39. @agent.last_error_log_at = Time.now - 1.minute
  40. expect(@agent.received_event_without_error?).to eq(true)
  41. end
  42. end
  43. describe "checked_without_error?" do
  44. before do
  45. @agent = described_class.new
  46. end
  47. it "should return false until the first time check ran" do
  48. expect(@agent.checked_without_error?).to eq(false)
  49. @agent.last_check_at = Time.now
  50. expect(@agent.checked_without_error?).to eq(true)
  51. end
  52. it "should return false when the last error occured after the check" do
  53. @agent.last_check_at = Time.now - 1.minute
  54. @agent.last_error_log_at = Time.now
  55. expect(@agent.checked_without_error?).to eq(false)
  56. end
  57. it "should return true when the last check occured after the last error" do
  58. @agent.last_check_at = Time.now
  59. @agent.last_error_log_at = Time.now - 1.minute
  60. expect(@agent.checked_without_error?).to eq(true)
  61. end
  62. end
  63. end