Skip to content

Commit

Permalink
introduce process:died? to make backoff logic more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
telent committed Apr 22, 2021
1 parent 01f1943 commit 2bbfce2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions pppoe.fnl
Expand Up @@ -18,8 +18,7 @@
ipstate-script
ipstate-script))]
(each [event (event.next-event transport-device pppd)]
(when (not pppd.running?)
(pppd:backoff))
(when (pppd:died?) (pppd:backoff))
(when (and (not pppd.running?)
(netdev.link-up? transport-device)
(pppd:backoff-expired?))
Expand Down
4 changes: 2 additions & 2 deletions tests/pppoe-test.fnl
Expand Up @@ -49,6 +49,7 @@
(when (= nil p.backoff-until)
(set p.backoff-until (+ (clock) p.backoff-interval))
(set p.backoff-interval (* 2 p.backoff-interval))))
"died?" (fn [p] (and (not p.running?) (= p.backoff-until nil)))
"backoff-expired?"
(fn [p]
(and p.backoff-until (<= p.backoff-until (clock))))
Expand Down Expand Up @@ -82,10 +83,9 @@
(var started false)
(set my-events [1 2 3 4 5 6 7 8 ])
(mock :process :join #(set joined true))
(tset p "start" #(set started true))
(pppoe "eth0" "ppp0")
(assert joined "ifconfig process did not join")
(assert started "daemon did not start")))
(assert p.running? "daemon did not start")))

(lambda backoff-increases-on-failure []
(var delay 0)
Expand Down

0 comments on commit 2bbfce2

Please sign in to comment.