Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 431262

Summary: Client tests failure in searchCrawler
Product: [ECD] Orion Reporter: Mark Macdonald <mamacdon>
Component: ClientAssignee: libing wang <libingw>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: ahunter.eclipse, libingw, simon_kaegi
Version: 5.0   
Target Milestone: 6.0 M2   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Mark Macdonald CLA 2014-03-26 12:12:10 EDT
Changes to deferred.js caused the cancellation test to fail. It has been like this for several weeks. It needs to be fixed.

> Name	                Status     Type
> ---------------------------------------------
> test_NormalCancel	Failure	   Timed out
Comment 1 libing wang CLA 2014-03-26 14:18:31 EDT
Looking at it now...
Comment 2 libing wang CLA 2014-03-26 17:12:32 EDT
fixed with patch below. Will push to master when it is opened.

diff --git a/bundles/org.eclipse.orion.client.ui/web/js-tests/searchCrawler/testcase.js b/bundles/org.eclipse.orion.client.ui/web/js-tests/searchCrawler/testcase.js
index 96f855b..c0f4512 100644
--- a/bundles/org.eclipse.orion.client.ui/web/js-tests/searchCrawler/testcase.js
+++ b/bundles/org.eclipse.orion.client.ui/web/js-tests/searchCrawler/testcase.js
@@ -667,6 +667,8 @@
 			keyword: "EveryWhere"
 		},
 		{location: "root"});
+		//There is time racing issue: if deferred.resolve is faster than deferred.cancel, then we need to tell the crawler teh mode is simulating.
+		crawler._simulating = true; 
 		return _cancellAndCompare(crawler, 3, {
 			response: {
 				numFound: 3,
diff --git a/bundles/org.eclipse.orion.client.ui/web/orion/crawler/searchCrawler.js b/bundles/org.eclipse.orion.client.ui/web/orion/crawler/searchCrawler.js
index 755f3a7..5cf050e 100644
--- a/bundles/org.eclipse.orion.client.ui/web/orion/crawler/searchCrawler.js
+++ b/bundles/org.eclipse.orion.client.ui/web/orion/crawler/searchCrawler.js
@@ -60,16 +60,17 @@
 			this.contentTypesCache = ct;
 			var crawler = this;
 			this._visitRecursively(this._childrenLocation).then(function(){
-				if(!crawler._cancelled) {
+				if(!crawler._cancelled || crawler._simulating){//If it is in simulating mode we need to report the result anyway
 					crawler._reportResult();
+				} 
+				//Normally if a cancellation happens it goes to error handler. But in corner cases that deferred.resolve is faster than deferred.cancel we need to capture the case
+				if(crawler._cancelled) {
+					crawler._HandleStatus({name: "Cancel"}); //$NON-NLS-0$
 				}
 			}.bind(crawler),
 			function(error){
 				crawler._reportResult();
-				if(crawler._statusService && error.name === "Cancel") { //$NON-NLS-0$
-					console.log("Crawling search cancelled. Deferred array length : " + crawler._deferredArray.length); //$NON-NLS-0$
-					crawler._statusService.setProgressResult({Message: messages["Search cancelled by user"], Severity: "Warning"}); //$NON-NLS-0$
-				}
+				crawler._HandleStatus(error); 
 			}.bind(crawler));
 		}.bind(this));
 	};
@@ -157,6 +158,13 @@
 		}.bind(this)); 
 	};
 		
+	SearchCrawler.prototype._HandleStatus = function(error){
+		if(this._statusService && error.name === "Cancel") { //$NON-NLS-0$
+			console.log("Crawling search cancelled. Deferred array length : " + this._deferredArray.length); //$NON-NLS-0$
+			this._statusService.setProgressResult({Message: messages["Search cancelled by user"], Severity: "Warning"}); //$NON-NLS-0$
+		}
+	};
+		
 	SearchCrawler.prototype._reportResult = function(){
 		this._sort(this.fileLocations);
 		var response = {numFound: this.fileLocations.length, docs: this.fileLocations };
Comment 4 Mark Macdonald CLA 2014-04-01 09:36:05 EDT
Strange.. the test is still failing. For example it failed in last night's build (I20140331-2230)

http://download.eclipse.org/orion/drops/I201403312230/Firefox-23.0-testResults.html#searchCrawler
Comment 5 libing wang CLA 2014-04-01 12:38:12 EDT
Hmm, strange. Will try it again locally.
Comment 6 libing wang CLA 2014-04-01 15:00:19 EDT
I downloaded FF 23 and tried the tests locally. The tests are successful.
Will wait to see what tycho build result when Bug 431176 is fixed.
Comment 7 Mark Macdonald CLA 2015-04-28 14:44:03 EDT
Passing now