working_helpers.rb 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. require 'spec_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. end