DEV: removes setTimeout and reduces timer in tests (#9701)

DEV: removes setTimeout and reduces timer in tests (#9701)

diff --git a/app/assets/javascripts/discourse/app/lib/category-tag-search.js b/app/assets/javascripts/discourse/app/lib/category-tag-search.js
index c258ddb..a5665a1 100644
--- a/app/assets/javascripts/discourse/app/lib/category-tag-search.js
+++ b/app/assets/javascripts/discourse/app/lib/category-tag-search.js
@@ -4,6 +4,7 @@ import Category from "discourse/models/category";
 import { TAG_HASHTAG_POSTFIX } from "discourse/lib/tag-hashtags";
 import { SEPARATOR } from "discourse/lib/category-hashtags";
 import { Promise } from "rsvp";
+import { later, cancel } from "@ember/runloop";
 
 var cache = {};
 var cacheTime;
@@ -17,9 +18,12 @@ function updateCache(term, results) {
 
 function searchTags(term, categories, limit) {
   return new Promise(resolve => {
-    const clearPromise = setTimeout(() => {
-      resolve(CANCELLED_STATUS);
-    }, 5000);
+    const clearPromise = later(
+      () => {
+        resolve(CANCELLED_STATUS);
+      },
+      Ember.testing ? 25 : 5000
+    );
 
     const debouncedSearch = discourseDebounce((q, cats, resultFunc) => {
       oldSearch = $.ajax(Discourse.getURL("/tags/filter/search"), {
@@ -55,7 +59,7 @@ function searchTags(term, categories, limit) {
     }, 300);
 
     debouncedSearch(term, categories, result => {
-      clearTimeout(clearPromise);
+      cancel(clearPromise);
       resolve(updateCache(term, result));
     });
   });
diff --git a/app/assets/javascripts/discourse/app/lib/user-search.js b/app/assets/javascripts/discourse/app/lib/user-search.js
index fcdc421..b374b59 100644
--- a/app/assets/javascripts/discourse/app/lib/user-search.js
+++ b/app/assets/javascripts/discourse/app/lib/user-search.js
@@ -3,6 +3,7 @@ import { CANCELLED_STATUS } from "discourse/lib/autocomplete";
 import { userPath } from "discourse/lib/url";
 import { emailValid } from "discourse/lib/utilities";
 import { Promise } from "rsvp";
+import { later, cancel } from "@ember/runloop";
 
 var cache = {},
   cacheKey,
@@ -180,9 +181,12 @@ export default function userSearch(options) {
 
     cacheKey = newCacheKey;
 
-    var clearPromise = setTimeout(function() {
-      resolve(CANCELLED_STATUS);
-    }, 5000);
+    const clearPromise = later(
+      () => {
+        resolve(CANCELLED_STATUS);
+      },
+      Ember.testing ? 25 : 5000
+    );
 
     if (skipSearch(term, options.allowEmails)) {
       resolve([]);
@@ -199,7 +203,7 @@ export default function userSearch(options) {
       allowedUsers,
       groupMembersOf,
       function(r) {
-        clearTimeout(clearPromise);
+        cancel(clearPromise);
         resolve(organizeResults(r, options));
       }
     );

GitHub sha: 350fe932

This commit appears in #9701 which was approved by eviltrout. It was merged by jjaffeux.