Bug 1351753 - Follow-up: Fix test failure in test-session-store.js using waitFor() together with appropriate sleep(). r=aceman
authoralta88@gmail.com
Fri, 20 Oct 2017 08:48:16 -0600
changeset 29310 c382516f2d6f5efe22016e444395c524789eff1b
parent 29309 5014946f75dcc9e4a7947a7303d67a028c1187e7
child 29311 874a82d429d98d9c1ba8eca91a1ddfe149114e50
push id2068
push userclokep@gmail.com
push dateMon, 13 Nov 2017 19:02:14 +0000
treeherdercomm-beta@9c7e7ce8672b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaceman
bugs1351753
Bug 1351753 - Follow-up: Fix test failure in test-session-store.js using waitFor() together with appropriate sleep(). r=aceman
mail/test/mozmill/session-store/test-session-store.js
--- a/mail/test/mozmill/session-store/test-session-store.js
+++ b/mail/test/mozmill/session-store/test-session-store.js
@@ -20,17 +20,17 @@ Cu.import("resource:///modules/sessionSt
 Cu.import("resource://gre/modules/Services.jsm");
 
 var folderA, folderB;
 
 // Default JSONFile save delay with saveSoon().
 var kSaveDelayMs = 1500;
 
 // With async file writes, use a delay larger than the session autosave timer.
-var asyncFileWriteDelayMS = 6000;
+var asyncFileWriteDelayMS = 1000;
 
 /* ........ Helper Functions ................*/
 
 /**
  * Reads the contents of the session file into a JSON object.
  */
 function readFile() {
   try {
@@ -42,19 +42,20 @@ function readFile() {
     // fall through and return null if the session file cannot be read
     // or is bad
   }
 
   return null;
 }
 
 function waitForFileRefresh() {
-  controller.sleep(kSaveDelayMs + asyncFileWriteDelayMS);
-  assert_true(sessionStoreManager.sessionFile.exists(),
-                "file should exist");
+  controller.sleep(kSaveDelayMs);
+  utils.waitFor(() => sessionStoreManager.sessionFile.exists(),
+                "session file should exist");
+  controller.sleep(asyncFileWriteDelayMS);
 }
 
 function open3PaneWindow() {
   plan_for_new_window("mail:3pane");
   Services.ww.openWindow(null,
                          "chrome://messenger/content/messenger.xul", "",
                          "all,chrome,dialog=no,status,toolbar",
                          null);
@@ -97,42 +98,47 @@ function teardownModule(module) {
 }
 
 function test_periodic_session_persistence_simple() {
   // delete the session file if it exists
   let sessionFile = sessionStoreManager.sessionFile;
   if (sessionFile.exists())
     sessionFile.remove(false);
 
-  assert_false(sessionFile.exists(), "file should not exist");
+  utils.waitFor(() => !sessionFile.exists(),
+                "session file should not exist");
 
   // change some state to guarantee the file will be recreated
   // if periodic session persistence works
   be_in_folder(folderA);
 
   // if periodic session persistence is working, the file should be
   // re-created
   sessionStoreManager._saveState();
   waitForFileRefresh();
 }
 
 function test_periodic_nondirty_session_persistence() {
+  // This changes state.
   be_in_folder(folderB);
 
   sessionStoreManager._saveState();
   waitForFileRefresh();
 
   // delete the session file
   let sessionFile = sessionStoreManager.sessionFile;
   sessionFile.remove(false);
 
-  // since we didn't change the state of the session, the session file
-  // should not be re-created
+  // Since the state of the session hasn't changed since last _saveState(),
+  // the session file should not be re-created.
+  sessionStoreManager._saveState();
   controller.sleep(kSaveDelayMs + asyncFileWriteDelayMS);
-  assert_false(sessionFile.exists(), "file should not exist");
+
+  utils.waitFor(() => !sessionFile.exists(),
+                "session file should not exist");
 }
 
 function test_single_3pane_periodic_session_persistence() {
   be_in_folder(folderA);
 
   // get the state object. this assumes there is one and only one
   // 3pane window.
   let mail3PaneWindow = Services.wm.getMostRecentWindow("mail:3pane");
@@ -160,19 +166,19 @@ function test_restore_single_3pane_persi
   // 3pane window.
   let mail3PaneWindow = Services.wm.getMostRecentWindow("mail:3pane");
 
   // make sure we have a different window open, so that we don't start shutting
   // down just because the last window was closed
   let abwc = openAddressBook();
 
   // close the 3pane window
-  mail3PaneWindow.close();
+  close_window(new mozmill.controller.MozMillController(mail3PaneWindow));
   // Wait for window close async session write to finish.
-  controller.sleep(kSaveDelayMs + asyncFileWriteDelayMS);
+  controller.sleep(asyncFileWriteDelayMS);
 
   mc = open3PaneWindow();
   be_in_folder(folderA);
   assert_message_pane_hidden();
   // restore message pane.
   toggle_message_pane();
 
   // We don't need the address book window any more.
@@ -215,37 +221,37 @@ function test_message_pane_height_persis
     "The message pane height should be " + newHeight + ", but is actually " +
     actualHeight + ". The oldHeight was: " + oldHeight);
 
   // Make sure we have a different window open, so that we don't start shutting
   // down just because the last window was closed.
   let abwc = openAddressBook();
 
   // The 3pane window is closed.
-  mail3PaneWindow.close();
+  close_window(new mozmill.controller.MozMillController(mail3PaneWindow));
   // Wait for window close async session write to finish.
-  controller.sleep(kSaveDelayMs + asyncFileWriteDelayMS);
+  controller.sleep(asyncFileWriteDelayMS);
 
   mc = open3PaneWindow();
   be_in_folder(folderA);
   assert_message_pane_visible();
 
   actualHeight = mc.e("messagepaneboxwrapper").boxObject.height;
 
   assert_equals(newHeight, actualHeight,
     "The message pane height should be " + newHeight + ", but is actually " +
     actualHeight + ". The oldHeight was: " + oldHeight);
 
   // The old height is restored.
   _move_splitter(mc.e("threadpane-splitter"), 0, -diffHeight);
 
   // The 3pane window is closed.
-  mail3PaneWindow.close();
+  close_window(mc);
   // Wait for window close async session write to finish.
-  controller.sleep(kSaveDelayMs + asyncFileWriteDelayMS);
+  controller.sleep(asyncFileWriteDelayMS);
 
   mc = open3PaneWindow();
   be_in_folder(folderA);
   assert_message_pane_visible();
 
   actualHeight = mc.e("messagepaneboxwrapper").boxObject.height;
   assert_equals(oldHeight, actualHeight,
     "The message pane height should be " + oldHeight + ", but is actually " +
@@ -295,19 +301,19 @@ function test_message_pane_width_persist
     actualWidth + ". The oldWidth was: " + oldWidth);
   newWidth = actualWidth;
 
   // Make sure we have a different window open, so that we don't start shutting
   // down just because the last window was closed
   let abwc = openAddressBook();
 
   // The 3pane window is closed.
-  mail3PaneWindow.close();
+  close_window(new mozmill.controller.MozMillController(mail3PaneWindow));
   // Wait for window close async session write to finish.
-  controller.sleep(kSaveDelayMs + asyncFileWriteDelayMS);
+  controller.sleep(asyncFileWriteDelayMS);
 
   mc = open3PaneWindow();
   be_in_folder(folderA);
   assert_message_pane_visible();
   assert_pane_layout(kVerticalMailLayout);
 
   actualWidth = mc.e("messagepaneboxwrapper").boxObject.width;
   assert_equals(newWidth, actualWidth, "The message pane width should be " +
@@ -322,19 +328,19 @@ function test_message_pane_width_persist
   // persistency. Therefore it is enough if the actual width is equal to the
   // the requested width plus/minus two pixels.
   assert_equals_fuzzy(oldWidth, actualWidth, 2,
     "The message pane width should be " + oldWidth + ", but is actually " +
     actualWidth);
   oldWidth = actualWidth;
 
   // The 3pane window is closed.
-  mail3PaneWindow.close();
+  close_window(mc);
   // Wait for window close async session write to finish.
-  controller.sleep(kSaveDelayMs + asyncFileWriteDelayMS);
+  controller.sleep(asyncFileWriteDelayMS);
 
   mc = open3PaneWindow();
   be_in_folder(folderA);
   assert_message_pane_visible();
   assert_pane_layout(kVerticalMailLayout);
 
   actualWidth = mc.e("messagepaneboxwrapper").boxObject.width;
   assert_equals(oldWidth, actualWidth, "The message pane width should be " +
@@ -398,22 +404,19 @@ async function test_bad_session_file_sim
   sessionStoreManager._store = null;
   await sessionStoreManager._loadSessionFile();
 
   // since the session file is bad, the session store manager's state field
   // should be null
   assert_false(sessionStoreManager._initialState,
                "saved state is bad so state object should be null");
 
-  // Wait for bad file async rename to finish.
-  controller.sleep(kSaveDelayMs + asyncFileWriteDelayMS);
-
   // The bad session file should now not exist.
-  assert_false(sessionStoreManager.sessionFile.exists(),
-               "file should not exist");
+  utils.waitFor(() => !sessionStoreManager.sessionFile.exists(),
+                "session file should now not exist");
 }
 
 function test_clean_shutdown_session_persistence_simple() {
 
   // open a few more 3pane windows
   for (var i = 0; i < 3; ++i) {
     open3PaneWindow();
   }
@@ -428,32 +431,32 @@ function test_clean_shutdown_session_per
   while (enumerator.hasMoreElements()) {
     let window = enumerator.getNext();
     if (!enumerator.hasMoreElements())
       lastWindowState = window.getWindowStateForSessionPersistence();
 
     close_window(new mozmill.controller.MozMillController(window));
   }
 
-  // Wait for window close async session write to finish.
-  controller.sleep(kSaveDelayMs + asyncFileWriteDelayMS);
+  // Wait for session file to be created (removed in prior test) after
+  // all 3pane windows close and for session write to finish.
+  waitForFileRefresh();
 
   // load the saved state from disk
   let loadedState = readFile();
   assert_true(loadedState, "previously saved state should be non-null");
 
   assert_equals(loadedState.windows.length, 1,
           "only the state of the last 3pane window should have been saved");
 
   // get the state object for the one and only one 3pane window
   let windowState = loadedState.windows[0];
   assert_true(JSON.stringify(windowState) == JSON.stringify(lastWindowState),
               "saved state and loaded state should be equal");
 
-
   open3PaneWindow();
 
   // We don't need the address book window any more.
   plan_for_window_close(abwc);
   abwc.window.close();
   wait_for_window_close();
 }