Functional Weave
Code in Python

monitor.alert-state@1.0.0

vectors.json

8,666 bytes · view raw

[
  {"name": "the condition starting on an inactive alert makes it pending", "args": [{"phase": "inactive", "since": null, "lastNotifiedAt": null, "clearSince": null}, true, 1000, {"forSeconds": 300, "clearForSeconds": 0, "renotifySeconds": null}], "expect": {"state": {"phase": "pending", "since": 1000, "lastNotifiedAt": null, "clearSince": null}, "notify": null, "changed": true}},
  {"name": "forSeconds 0 fires at once and notifies", "args": [{"phase": "inactive", "since": null, "lastNotifiedAt": null, "clearSince": null}, true, 1000, {"forSeconds": 0, "clearForSeconds": 0, "renotifySeconds": null}], "expect": {"state": {"phase": "firing", "since": 1000, "lastNotifiedAt": 1000, "clearSince": null}, "notify": "firing", "changed": true}},
  {"name": "an inactive alert with the condition false stays as it is", "args": [{"phase": "inactive", "since": null, "lastNotifiedAt": null, "clearSince": null}, false, 1000, {"forSeconds": 300, "clearForSeconds": 0, "renotifySeconds": null}], "expect": {"state": {"phase": "inactive", "since": null, "lastNotifiedAt": null, "clearSince": null}, "notify": null, "changed": false}},
  {"name": "pending one second short of forSeconds stays pending", "args": [{"phase": "pending", "since": 1000, "lastNotifiedAt": null, "clearSince": null}, true, 1299, {"forSeconds": 300, "clearForSeconds": 0, "renotifySeconds": null}], "expect": {"state": {"phase": "pending", "since": 1000, "lastNotifiedAt": null, "clearSince": null}, "notify": null, "changed": false}},
  {"name": "pending for exactly forSeconds fires and notifies", "args": [{"phase": "pending", "since": 1000, "lastNotifiedAt": null, "clearSince": null}, true, 1300, {"forSeconds": 300, "clearForSeconds": 0, "renotifySeconds": null}], "expect": {"state": {"phase": "firing", "since": 1300, "lastNotifiedAt": 1300, "clearSince": null}, "notify": "firing", "changed": true}},
  {"name": "the condition ending while pending goes back to inactive without a notification", "args": [{"phase": "pending", "since": 1000, "lastNotifiedAt": null, "clearSince": null}, false, 1100, {"forSeconds": 300, "clearForSeconds": 0, "renotifySeconds": null}], "expect": {"state": {"phase": "inactive", "since": 1100, "lastNotifiedAt": null, "clearSince": null}, "notify": null, "changed": true}},
  {"name": "firing and still true, with no repeat interval, sends nothing", "args": [{"phase": "firing", "since": 1300, "lastNotifiedAt": 1300, "clearSince": null}, true, 1500, {"forSeconds": 300, "clearForSeconds": 0, "renotifySeconds": null}], "expect": {"state": {"phase": "firing", "since": 1300, "lastNotifiedAt": 1300, "clearSince": null}, "notify": null, "changed": false}},
  {"name": "firing and still true for exactly the repeat interval sends a repeat", "args": [{"phase": "firing", "since": 1300, "lastNotifiedAt": 1300, "clearSince": null}, true, 4900, {"forSeconds": 300, "clearForSeconds": 0, "renotifySeconds": 3600}], "expect": {"state": {"phase": "firing", "since": 1300, "lastNotifiedAt": 4900, "clearSince": null}, "notify": "repeat", "changed": false}},
  {"name": "one second short of the repeat interval sends nothing", "args": [{"phase": "firing", "since": 1300, "lastNotifiedAt": 1300, "clearSince": null}, true, 4899, {"forSeconds": 300, "clearForSeconds": 0, "renotifySeconds": 3600}], "expect": {"state": {"phase": "firing", "since": 1300, "lastNotifiedAt": 1300, "clearSince": null}, "notify": null, "changed": false}},
  {"name": "firing then false with clearForSeconds 0 resolves at once", "args": [{"phase": "firing", "since": 1300, "lastNotifiedAt": 1300, "clearSince": null}, false, 2000, {"forSeconds": 300, "clearForSeconds": 0, "renotifySeconds": null}], "expect": {"state": {"phase": "resolved", "since": 2000, "lastNotifiedAt": 2000, "clearSince": null}, "notify": "resolved", "changed": true}},
  {"name": "firing then false with a clear delay starts the clear clock and keeps firing", "args": [{"phase": "firing", "since": 1300, "lastNotifiedAt": 1300, "clearSince": null}, false, 2000, {"forSeconds": 300, "clearForSeconds": 600, "renotifySeconds": null}], "expect": {"state": {"phase": "firing", "since": 1300, "lastNotifiedAt": 1300, "clearSince": 2000}, "notify": null, "changed": false}},
  {"name": "false for the whole clear delay resolves", "args": [{"phase": "firing", "since": 1300, "lastNotifiedAt": 1300, "clearSince": 2000}, false, 2600, {"forSeconds": 300, "clearForSeconds": 600, "renotifySeconds": null}], "expect": {"state": {"phase": "resolved", "since": 2600, "lastNotifiedAt": 2600, "clearSince": null}, "notify": "resolved", "changed": true}},
  {"name": "false one second short of the clear delay keeps firing", "args": [{"phase": "firing", "since": 1300, "lastNotifiedAt": 1300, "clearSince": 2000}, false, 2599, {"forSeconds": 300, "clearForSeconds": 600, "renotifySeconds": null}], "expect": {"state": {"phase": "firing", "since": 1300, "lastNotifiedAt": 1300, "clearSince": 2000}, "notify": null, "changed": false}},
  {"name": "a flap back to true during the clear delay cancels it, no resolved sent", "args": [{"phase": "firing", "since": 1300, "lastNotifiedAt": 1300, "clearSince": 2000}, true, 2300, {"forSeconds": 300, "clearForSeconds": 600, "renotifySeconds": null}], "expect": {"state": {"phase": "firing", "since": 1300, "lastNotifiedAt": 1300, "clearSince": null}, "notify": null, "changed": false}},
  {"name": "a resolved alert with the condition false stays resolved", "args": [{"phase": "resolved", "since": 2000, "lastNotifiedAt": 2000, "clearSince": null}, false, 3000, {"forSeconds": 300, "clearForSeconds": 0, "renotifySeconds": null}], "expect": {"state": {"phase": "resolved", "since": 2000, "lastNotifiedAt": 2000, "clearSince": null}, "notify": null, "changed": false}},
  {"name": "a resolved alert whose condition returns goes pending, keeping the last notification time", "args": [{"phase": "resolved", "since": 2000, "lastNotifiedAt": 2000, "clearSince": null}, true, 3000, {"forSeconds": 300, "clearForSeconds": 0, "renotifySeconds": null}], "expect": {"state": {"phase": "pending", "since": 3000, "lastNotifiedAt": 2000, "clearSince": null}, "notify": null, "changed": true}},
  {"name": "now before the state's since is an error", "args": [{"phase": "pending", "since": 1000, "lastNotifiedAt": null, "clearSince": null}, true, 900, {"forSeconds": 300, "clearForSeconds": 0, "renotifySeconds": null}], "expectError": "now 900 is earlier than since 1000"},
  {"name": "now before the last notification is an error", "args": [{"phase": "firing", "since": 1300, "lastNotifiedAt": 1500, "clearSince": null}, true, 1400, {"forSeconds": 300, "clearForSeconds": 0, "renotifySeconds": null}], "expectError": "now 1400 is earlier than lastNotifiedAt 1500"},
  {"name": "now before clearSince is an error", "args": [{"phase": "firing", "since": 1300, "lastNotifiedAt": 1300, "clearSince": 2000}, false, 1900, {"forSeconds": 300, "clearForSeconds": 0, "renotifySeconds": null}], "expectError": "now 1900 is earlier than clearSince 2000"},
  {"name": "an unknown phase is an error", "args": [{"phase": "acknowledged", "since": 1000, "lastNotifiedAt": null, "clearSince": null}, true, 1000, {"forSeconds": 300, "clearForSeconds": 0, "renotifySeconds": null}], "expectError": "unknown alert phase: acknowledged"},
  {"name": "a pending state without since is an error", "args": [{"phase": "pending", "since": null, "lastNotifiedAt": null, "clearSince": null}, true, 1000, {"forSeconds": 300, "clearForSeconds": 0, "renotifySeconds": null}], "expectError": "since must be set in phase pending"},
  {"name": "a negative forSeconds is an error", "args": [{"phase": "inactive", "since": null, "lastNotifiedAt": null, "clearSince": null}, true, 1000, {"forSeconds": -1, "clearForSeconds": 0, "renotifySeconds": null}], "expectError": "forSeconds must not be negative"},
  {"name": "a negative clearForSeconds is an error", "args": [{"phase": "inactive", "since": null, "lastNotifiedAt": null, "clearSince": null}, true, 1000, {"forSeconds": 300, "clearForSeconds": -1, "renotifySeconds": null}], "expectError": "clearForSeconds must not be negative"},
  {"name": "a zero repeat interval is an error", "args": [{"phase": "inactive", "since": null, "lastNotifiedAt": null, "clearSince": null}, true, 1000, {"forSeconds": 300, "clearForSeconds": 0, "renotifySeconds": 0}], "expectError": "renotifySeconds must be null or at least 1"},
  {"name": "a fractional now is an error", "args": [{"phase": "inactive", "since": null, "lastNotifiedAt": null, "clearSince": null}, true, 1000.5, {"forSeconds": 300, "clearForSeconds": 0, "renotifySeconds": null}], "expectError": "now must be a whole number of seconds"}
]