Bug 1762690 - Enable test_stopMovingToLocalFolder.js for imap-js. r=benc
authorPing Chen <remotenonsense@gmail.com>
Fri, 23 Sep 2022 10:47:29 +0000
changeset 36833 24201dc5e5d4dc0bb1e23060ab80c1b4992f65a1
parent 36832 b2697513aaef997a47e11b6ca5990c4ba407a396
child 36834 af26a1c1d48d13a9b63a66507f23d6b48a6833e0
push id20341
push usergeoff@darktrojan.net
push dateFri, 30 Sep 2022 04:25:32 +0000
treeherdercomm-central@b9e3fe9b3470 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbenc
bugs1762690
Bug 1762690 - Enable test_stopMovingToLocalFolder.js for imap-js. r=benc Differential Revision: https://phabricator.services.mozilla.com/D157703
mailnews/imap/src/ImapChannel.jsm
mailnews/imap/src/ImapClient.jsm
mailnews/imap/src/ImapIncomingServer.jsm
mailnews/imap/test/unit/xpcshell-cpp.ini
mailnews/imap/test/unit/xpcshell-shared.ini
mailnews/imap/test/unit/xpcshell_maildir-cpp.ini
--- a/mailnews/imap/src/ImapChannel.jsm
+++ b/mailnews/imap/src/ImapChannel.jsm
@@ -149,22 +149,22 @@ class ImapChannel {
       client.startRunningUrl(null, null, this.URI);
       client.channel = this;
       this._listener.onStartRequest(this);
       client.onReady = () => {
         client.fetchMessage(this.URI.folder, this._msgKey);
       };
 
       client.onData = data => {
-        if (!data) {
-          try {
-            this.loadGroup?.removeRequest(this, null, Cr.NS_OK);
-          } catch (e) {}
-          this._listener.onStopRequest(this, Cr.NS_OK);
-          return;
-        }
         this.contentLength += data.length;
         outputStream.write(data, data.length);
         this._listener.onDataAvailable(this, inputStream, 0, data.length);
       };
+
+      client.onDone = status => {
+        try {
+          this.loadGroup?.removeRequest(this, null, status);
+        } catch (e) {}
+        this._listener.onStopRequest(this, status);
+      };
     });
   }
 }
--- a/mailnews/imap/src/ImapClient.jsm
+++ b/mailnews/imap/src/ImapClient.jsm
@@ -368,16 +368,17 @@ class ImapClient {
   /**
    * Fetch the full content of a message by UID.
    * @param {nsIMsgFolder} folder - The associated folder.
    * @param {number} uid - The message uid.
    */
   fetchMessage(folder, uid) {
     this._logger.debug(`fetchMessage folder=${folder.name} uid=${uid}`);
     if (folder.hasMsgOffline(uid, null, 10)) {
+      this.onDone = () => {};
       this.channel?.readFromLocalCache();
       this._actionDone();
       return;
     }
     let fetchUid = () => {
       this._nextAction = this._actionUidFetchBodyResponse;
       this._sendTagged(`UID FETCH ${uid} (UID RFC822.SIZE FLAGS BODY.PEEK[])`);
     };
@@ -599,17 +600,16 @@ class ImapClient {
   }
 
   /**
    * Send LOGOUT and close the socket.
    */
   logout() {
     this._sendTagged("LOGOUT");
     this._socket.close();
-    this._actionDone();
   }
 
   /**
    * The open event handler.
    */
   _onOpen = () => {
     this._logger.debug("Connected");
     this._socket.ondata = this._onData;
@@ -1324,17 +1324,16 @@ class ImapClient {
     if (this._bodysToDownload.length) {
       // nsImapMailFolder decides to fetch the full body by calling
       // NotifyBodysToDownload.
       let uids = this._bodysToDownload.join(",");
       this._nextAction = this._actionUidFetchBodyResponse;
       this._sendTagged(`UID FETCH ${uids} (UID RFC822.SIZE FLAGS BODY.PEEK[])`);
       return;
     }
-    this.onData?.();
     this._actionDone();
   }
 
   /**
    * Handle UID FETCH BODY response.
    * @param {ImapResponse} res - Response received from the server.
    */
   _actionUidFetchBodyResponse(res) {
@@ -1348,17 +1347,16 @@ class ImapClient {
         true,
         this.runningUrl,
         msg.body.length
       );
       this._folderSink.EndMessage(this.runningUrl, msg.uid);
       this.onData?.(msg.body);
     }
     this._folderSink.headerFetchCompleted(this);
-    this.onData?.();
     this._actionDone();
   }
 
   /**
    * Send NOOP command.
    */
   _actionNoop() {
     this._nextAction = this._actionNoopResponse;
@@ -1426,18 +1424,20 @@ class ImapClient {
   /**
    * Finish a request and do necessary cleanup.
    */
   _actionDone = (status = Cr.NS_OK) => {
     this._logger.debug(`Done with status=${status}`);
     this._nextAction = null;
     this._urlListener?.OnStopRunningUrl(this.runningUrl, status);
     this.runningUrl.SetUrlState(false, status);
-    this.onDone?.();
+    this.onDone?.(status);
     this._reset();
+    // Tell ImapIncomingServer this client can be reused now.
+    this.onFree?.();
   };
 
   /** @see nsIImapProtocol */
   NotifyBodysToDownload(keys) {
     this._logger.debug("NotifyBodysToDownload", keys);
     this._bodysToDownload = keys;
   }
 
--- a/mailnews/imap/src/ImapIncomingServer.jsm
+++ b/mailnews/imap/src/ImapIncomingServer.jsm
@@ -444,17 +444,17 @@ class ImapIncomingServer extends MsgInco
    * @param {Function} handler - A callback function to take a ImapClient
    *   instance, and do some actions.
    */
   async withClient(handler) {
     let client = await this._getNextClient();
     if (!client) {
       return;
     }
-    client.onDone = async () => {
+    client.onFree = async () => {
       this._busyConnections = this._busyConnections.filter(c => c != client);
       this._freeConnections.push(client);
       let resolve = this._connectionWaitingQueue.shift();
       if (resolve) {
         // Resovle the first waiting in queue.
         resolve(true);
       } else if (
         !this._busyConnections.length &&
--- a/mailnews/imap/test/unit/xpcshell-cpp.ini
+++ b/mailnews/imap/test/unit/xpcshell-cpp.ini
@@ -17,18 +17,14 @@ prefs =
 [test_imapHighWater.js]
 [test_imapUndo.js]
 [test_offlineCopy.js]
 [test_offlineDraftDataloss.js]
 [test_offlinePlayback.js]
 [test_offlineMoveLocalToIMAP.js]
 [test_offlineStoreLocking.js]
 [test_partsOnDemand.js]
-[test_preserveDataOnMove.js]
-[test_saveImapDraft.js]
-[test_saveTemplate.js]
-[test_stopMovingToLocalFolder.js]
 [test_subfolderLocation.js]
 [test_syncChanges.js]
 [test_trustSpamAssassin.js]
 [test_cacheParts.js]
 
 [include:xpcshell-shared.ini]
--- a/mailnews/imap/test/unit/xpcshell-shared.ini
+++ b/mailnews/imap/test/unit/xpcshell-shared.ini
@@ -33,9 +33,13 @@
 skip-if = os == 'mac'
 [test_listClosesDB.js]
 [test_listSubscribed.js]
 [test_localToImapFilter.js]
 [test_localToImapFilterQuarantine.js]
 [test_lsub.js]
 [test_mailboxes.js]
 [test_nsIMsgFolderListenerIMAP.js]
+[test_preserveDataOnMove.js]
+[test_saveImapDraft.js]
+[test_saveTemplate.js]
 [test_starttlsFailure.js]
+[test_stopMovingToLocalFolder.js]
--- a/mailnews/imap/test/unit/xpcshell_maildir-cpp.ini
+++ b/mailnews/imap/test/unit/xpcshell_maildir-cpp.ini
@@ -17,17 +17,13 @@ prefs =
 [test_imapHighWater.js]
 [test_imapUndo.js]
 [test_offlineCopy.js]
 [test_offlineDraftDataloss.js]
 [test_offlinePlayback.js]
 [test_offlineMoveLocalToIMAP.js]
 [test_offlineStoreLocking.js]
 [test_partsOnDemand.js]
-[test_preserveDataOnMove.js]
-[test_saveImapDraft.js]
-[test_saveTemplate.js]
-[test_stopMovingToLocalFolder.js]
 [test_subfolderLocation.js]
 [test_syncChanges.js]
 [test_trustSpamAssassin.js]
 
 [include:xpcshell-shared.ini]