       (is (false? @shutdown-called?))
       (internal/request-shutdown shutdown-svc)
       (tk/run-app app)
-      (is (true? @shutdown-called?))))
-
+      (is (true? @shutdown-called?)))))
+
+(deftest shutdown-on-error-custom-fn-error-test
   (testing (str "`shutdown-on-error` in custom function causes services to be "
                 "shut down and the error is rethrown from main")
     (let [shutdown-called?  (atom false)

          app         (bootstrap-services-with-empty-config [service1 service2])]
      (is (empty? @order))
      (internal/shutdown! (app-context app))
      (is (= @order [2 1]))))

  (testing "services continue to shut down when one throws an exception"
    (let [shutdown-called?  (atom false)
          test-service      (service []

                                           context)
                                     (test-fn [this]
                                              (future (shutdown-on-error
                                                       (service-id this)
                                                       #(throw
                                                         (Throwable.
                                                          "oops"))))))
          app               (tk/boot-services-with-config [test-service] {})
          test-svc          (get-service app :ShutdownTestServiceWithFn)]
      (is (false? @shutdown-called?))
      (test-fn test-svc)
      (is (thrown-with-msg?
           Throwable
           #"oops"
           (tk/run-app app)))
      (is (true? @shutdown-called?)))))

(defn bootstrap-and-validate-shutdown
  [services shutdown-called? expected-exception-message]
  (let [app         (tk/boot-services-with-config services {})]
    (is (thrown-with-msg?
         Throwable
         expected-exception-message
         (tk/run-app app))
        "tk run-app did not die with expected exception.")
    (is (true? @shutdown-called?)
        "Service shutdown was not called.")))

(deftest shutdown-ex-during-init-test
  (testing (str "shutdown will be called if a service throws an exception "
                "during init on main thread, with appropriate errors logged")
    (logging/with-test-logging
     (let [shutdown-called? (atom false)
           test-service     (service ShutdownTestService
                                     []
                                     (init [this context]
                                           (throw (Throwable. "oops"))
                                           context)
                                     (stop [this context]
                                           (reset! shutdown-called? true)
                                           context))]
       (bootstrap-and-validate-shutdown
        [test-service]
        shutdown-called?
        #"oops")
       (is (logged? #"Error during service init!!!" :error)
           "Error message for service init not logged.")))))

(deftest shutdown-ex-during-start-test
  (testing (str "shutdown will be called if a service throws an exception "
                "during start on main thread, with appropriate errors logged")
    (logging/with-test-logging
     (let [shutdown-called?  (atom false)
           test-service      (service ShutdownTestService
                                      []
                                      (start [this context]
                                             (throw (Throwable. "oops"))
                                             context)
                                      (stop  [this context]
                                             (reset! shutdown-called? true)
                                             context))]
       (bootstrap-and-validate-shutdown
        [test-service]
        shutdown-called?
        #"oops")
       (is (logged? #"Error during service start!!!" :error)
           "Error message for service start not logged.")))))

(deftest shutdown-log-errors-during-init-test
  (testing (str "`shutdown-on-error` will catch and log errors raised during "
                "init on main thread")
    (logging/with-test-logging
     (let [shutdown-called?  (atom false)
           test-service      (service ShutdownTestService
                                      [[:ShutdownService shutdown-on-error]]
                                      (init [this context]
                                            (shutdown-on-error
                                             :ShutdownTestService
                                             #(throw (Throwable. "oops")))
                                            context)
                                      (stop [this context]
                                            (reset! shutdown-called? true)
                                            context))]
       (bootstrap-and-validate-shutdown
        [test-service]
        shutdown-called?
        #"oops")
       (is (logged? #"shutdown-on-error triggered because of exception!"
                    :error)
           "Error message for shutdown-on-error not logged.")))))

(deftest shutdown-log-errors-during-init-future-test
  (testing (str "`shutdown-on-error` will catch and log errors raised during "
                "init on future")
    (logging/with-test-logging
     (let [shutdown-called?  (atom false)
           test-service      (service ShutdownTestService
                                      [[:ShutdownService shutdown-on-error]]
                                      (init [this context]
                                            @(future
                                              (shutdown-on-error
                                               :ShutdownTestService
                                               #(throw (Throwable. "oops"))))
                                            context)
                                      (stop [this context]
                                            (reset! shutdown-called? true)
                                            context))]
       (bootstrap-and-validate-shutdown
        [test-service]
        shutdown-called?
        #"oops")
       (is (logged? #"shutdown-on-error triggered because of exception!"
                    :error)
           "Error message for shutdown-on-error not logged.")))))

(deftest shutdown-log-errors-during-start-test
  (testing (str "`shutdown-on-error` will catch and log errors raised during"
                "start on main thread")
    (logging/with-test-logging
     (let [shutdown-called?  (atom false)
           test-service      (service ShutdownTestService
                                      [[:ShutdownService shutdown-on-error]]
                                      (start [this context]
                                             (shutdown-on-error
                                              :ShutdownTestService
                                              #(throw (Throwable. "oops")))
                                             context)
                                      (stop [this context]
                                            (reset! shutdown-called? true)
                                            context))]
       (bootstrap-and-validate-shutdown
        [test-service]
        shutdown-called?
        #"oops")
       (is (logged? #"shutdown-on-error triggered because of exception!"
                    :error)
           "Error message for shutdown-on-error not logged.")))))

(deftest shutdown-log-errors-during-start-future-test
  (testing (str "`shutdown-on-error` will catch and log errors raised during "
                "start on future")
    (logging/with-test-logging
     (let [shutdown-called?  (atom false)
           test-service      (service ShutdownTestService
                                      [[:ShutdownService shutdown-on-error]]
                                      (start [this context]
                                             @(future
                                               (shutdown-on-error
                                                :ShutdownTestService
                                                #(throw (Throwable. "oops"))))
                                             context)
                                      (stop [this context]
                                            (reset! shutdown-called? true)
                                            context))]
       (bootstrap-and-validate-shutdown
        [test-service]
        shutdown-called?
        #"oops")
       (is (logged? #"shutdown-on-error triggered because of exception!"
                    :error)
           "Error message for shutdown-on-error not logged.")))))

(deftest shutdown-on-error-callback-test
  (testing "`shutdown-on-error` takes an optional function that is called on error"
    (let [shutdown-called?    (atom false)
          on-error-fn-called? (atom false)
