                                  :values (:values facts)
                                  :timestamp (-> 2 days ago)
                                  :environment nil
-                                 :producer_timestamp (-> 2 days ago)}))
-
-        (with-redefs [scf-store/update-facts!
+                                 :producer_timestamp (-> 2 days ago)})
+          (scf-store/ensure-environment "DEV"))
+
+        (with-redefs [mql/annotate-with-attempt
+                      (fn [msg ex]
+                        (swap! failures conj ex)
+                        (orig-annotate-attempt msg ex))
+                      scf-store/update-facts!
                       (fn [fact-data]
                         (.put hand-off-queue "got the lock")
                         (.poll hand-off-queue 5 TimeUnit/SECONDS)


            (test-msg-handler new-facts-cmd publish discard-dir
              (reset! second-message? true)
              (is (re-matches
                   #"(?sm).*ERROR: could not serialize access due to concurrent update.*"
                   (extract-error-message publish))))
            @fut
            (is (true? @first-message?))
            (is (true? @second-message?))))))))

            [puppetlabs.puppetdb.testutils
             :refer [args-supplied call-counter dotestseq times-called]]
            [puppetlabs.puppetdb.jdbc :refer [query-to-vec] :as jdbc]
            [puppetlabs.puppetdb.jdbc-test :refer [full-sql-exception-msg]]
            [puppetlabs.puppetdb.examples :refer :all]
            [puppetlabs.puppetdb.testutils.services :as svc-utils]
            [puppetlabs.puppetdb.command.constants :refer [command-names]]
