Skip to content

Commit de4dc61

Browse files
committed
fix(test): avoid race condition in FileFilters integration tests
Set exclusion filter before opening the search bar to prevent a race where _showFindBar() inherits the previous query and triggers an unfiltered search that populates the worker cache with all files. Also add retry loops to exclude-filter tests to handle instant/deferred search races, matching the existing pattern in "should search in files".
1 parent dcb3b53 commit de4dc61

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

test/spec/FileFilters-integ-test.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,16 @@ define(function (require, exports, module) {
207207
}
208208

209209
it("should exclude files from search", async function () {
210-
await openSearchBar();
210+
// Set the exclusion filter before opening the search bar to avoid
211+
// a race where opening the bar triggers an unfiltered search that
212+
// populates the worker cache with all files (including *.css).
211213
await setExcludeCSSFiles();
212214
await openSearchBar();
213-
await executeCleanSearch("{1}");
215+
await awaitsFor(async ()=>{
216+
await executeCleanSearch("{1}");
217+
return !FindInFiles.searchModel.results[testPath + "/test1.css"];
218+
// retry as instant/deferred searches can race with the explicit search
219+
}, "Search to exclude css results", 7000, 300);
214220
// *.css should have been excluded this time
215221
expect(FindInFiles.searchModel.results[testPath + "/test1.css"]).toBeFalsy();
216222
expect(FindInFiles.searchModel.results[testPath + "/test1.html"]).toBeTruthy();
@@ -219,7 +225,6 @@ define(function (require, exports, module) {
219225

220226
it("should respect filter when searching folder", async function () {
221227
let dirEntry = FileSystem.getDirectoryForPath(testPath);
222-
await openSearchBar(dirEntry);
223228
await setExcludeCSSFiles();
224229
await openSearchBar(dirEntry);
225230
await executeCleanSearch("{1}");
@@ -265,8 +270,8 @@ define(function (require, exports, module) {
265270
}, 30000);
266271

267272
it("should respect filter when editing code", async function () {
268-
await openSearchBar();
269273
await setExcludeCSSFiles();
274+
await openSearchBar();
270275
await executeCleanSearch("{1}");
271276
let promise = testWindow.brackets.test.DocumentManager.getDocumentForPath(testPath + "/test1.css");
272277
await awaitsForDone(promise);
@@ -322,7 +327,11 @@ define(function (require, exports, module) {
322327
it("should search exclude files", async function () {
323328
await openSearchBar();
324329
_setExcludeFiles("*.css");
325-
await executeCleanSearch("{1}");
330+
await awaitsFor(async ()=>{
331+
await executeCleanSearch("{1}");
332+
return !FindInFiles.searchModel.results[testPath + "/test1.css"];
333+
// retry as instant/deferred searches can race with the explicit search
334+
}, "Search to exclude css results", 7000, 300);
326335
expect(FindInFiles.searchModel.results[testPath + "/test1.css"]).toBeFalsy();
327336
expect(FindInFiles.searchModel.results[testPath + "/test1.html"]).toBeTruthy();
328337
await closeSearchBar();

0 commit comments

Comments
 (0)