 
 (defn rand-name
   ([]
-   (let [service-name (str (or (:name (meta (first *testing-vars*))) "test-unknown-name"))]
+   (let [service-name (current-test-name)]
      (rand-name service-name)))
   ([service-name]
-   (let [username (System/getProperty "user.name")
-         test-prefix (System/getenv "WAITER_TEST_PREFIX")]
-     (str/replace (str test-prefix service-name username (rand-int 3000000)) #"-" ""))))
+   (let [test-prefix (System/getenv "WAITER_TEST_PREFIX")]
+     (str/replace (str test-prefix (extract-acronym service-name) (System/nanoTime)) #"-" ""))))
 
 (defn- token->etag
   "Returns the current etag of a token"

(defn current-test-name
  "Get the name of the currently-running test."
  []
  (-> *testing-vars* first meta :name (or "test-unknown-name") str))

(defmacro testing-using-waiter-url
  [& body]

      :instance-id instance-id
      :service-id service-id)))

(defn extract-acronym
  "Shortens the name taking only the leading characters across the delimiters.
   E.g. `(extract-acronym \"aaa.bbb-ccc/ddd#eee-fff.ggg\") -> \"abcdfg\"`"
  [name-with-dashes]
  (->> (str/split (str name-with-dashes) #"-|\.|/")
    (remove str/blank?)
    (map first)
    (str/join "")
    str/lower-case))

(defn ensure-cid-in-headers
  [request-headers & {:keys [verbose] :or {verbose false}}]
  (let [cid (or (get request-headers "x-cid")
                (get request-headers :x-cid))]
    (if cid
      request-headers
      (let [correlation-id (cid/get-correlation-id)
            new-cid (str "test-" (extract-acronym (current-test-name)) "-" (utils/unique-identifier))]
        (when verbose
          (log/info "Using cid" new-cid))
        (when (str/includes? correlation-id "UNKNOWN")
          (log/info "Correlation id context unspecified")
          (when verbose
            (log/warn (RuntimeException.))))
