Bug 1792124 follow-up - Fix broken test. rs=bustage-fix
authorGeoff Lankow <geoff@darktrojan.net>
Wed, 28 Sep 2022 14:18:13 +1300
changeset 36814 7401e01653d24d901197e5d06f236bf17a2fd6e4
parent 36813 f72f2ceff5876ba0db15ce4026f0b6f22d9b8fa1
child 36815 36e0a3e4b5bdd6f614ff2fa59d1d49f6c984c162
push id20332
push usergeoff@darktrojan.net
push dateWed, 28 Sep 2022 02:50:48 +0000
treeherdercomm-central@7401e01653d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbustage-fix
bugs1792124
Bug 1792124 follow-up - Fix broken test. rs=bustage-fix Fixes the test by pretending to be offline before running it, and cleans up some names I missed when renaming things.
calendar/test/unit/test_storage_connection.js
--- a/calendar/test/unit/test_storage_connection.js
+++ b/calendar/test/unit/test_storage_connection.js
@@ -28,28 +28,28 @@ add_task(async function testLocal() {
   Assert.equal(
     dbA.databaseFile.path,
     PathUtils.join(PathUtils.profileDir, "calendar-data", "local.sqlite"),
     "local calendar A uses the right database file"
   );
   Assert.equal(
     dbB.databaseFile.path,
     PathUtils.join(PathUtils.profileDir, "calendar-data", "local.sqlite"),
-    "local calendar two uses the right database file"
+    "local calendar B uses the right database file"
   );
   Assert.equal(dbA, dbB, "local calendars share a database connection");
 });
 
 /**
  * Tests that local storage calendars using the same specified database file share a connection,
  * and that local storage calendars with a different specified database file do not.
  */
 add_task(async function testLocalFile() {
   let testFileA = new FileUtils.File(PathUtils.join(PathUtils.osTempDir, "file-a.sqlite"));
-  let testFileB = new FileUtils.File(PathUtils.join(PathUtils.osTempDir, "file-two.sqlite"));
+  let testFileB = new FileUtils.File(PathUtils.join(PathUtils.osTempDir, "file-b.sqlite"));
 
   let fileCalendarA = cal.manager.createCalendar("storage", Services.io.newFileURI(testFileA));
   fileCalendarA.id = cal.getUUID();
   let dbA = fileCalendarA.wrappedJSObject.mStorageDb.db;
 
   let fileCalendarB = cal.manager.createCalendar("storage", Services.io.newFileURI(testFileB));
   fileCalendarB.id = cal.getUUID();
   let dbB = fileCalendarB.wrappedJSObject.mStorageDb.db;
@@ -61,22 +61,22 @@ add_task(async function testLocalFile() 
   Assert.equal(
     dbA.databaseFile.path,
     testFileA.path,
     "local calendar A uses the right database file"
   );
   Assert.equal(
     dbB.databaseFile.path,
     testFileB.path,
-    "local calendar two uses the right database file"
+    "local calendar B uses the right database file"
   );
   Assert.equal(
     dbC.databaseFile.path,
     testFileA.path,
-    "local calendar three uses the right database file"
+    "local calendar C uses the right database file"
   );
   Assert.notEqual(
     dbA,
     dbB,
     "calendars with different file URLs do not share a database connection"
   );
   Assert.notEqual(
     dbB,
@@ -85,40 +85,43 @@ add_task(async function testLocalFile() 
   );
   Assert.equal(dbA, dbC, "calendars with matching file URLs share a database connection");
 });
 
 /**
  * Tests that cached network calendars share a database connection.
  */
 add_task(async function testNetwork() {
+  // Pretend to be offline so connecting to calendars that don't exist doesn't throw errors.
+  Services.io.offline = true;
+
   let networkCalendarA = cal.manager.createCalendar(
     "ics",
     Services.io.newURI("http://localhost/ics")
   );
   networkCalendarA.id = cal.getUUID();
   networkCalendarA.setProperty("cache.enabled", true);
   cal.manager.registerCalendar(networkCalendarA);
-  let dbA = cal.manager.getCalendarById(networkCalendarA.id).wrappedJSObject.mCachedCalendar
-    .wrappedJSObject.mStorageDb.db;
+  networkCalendarA = cal.manager.getCalendarById(networkCalendarA.id);
+  let dbA = networkCalendarA.wrappedJSObject.mCachedCalendar.wrappedJSObject.mStorageDb.db;
 
   let networkCalendarB = cal.manager.createCalendar(
     "caldav",
     Services.io.newURI("http://localhost/caldav")
   );
   networkCalendarB.id = cal.getUUID();
   networkCalendarB.setProperty("cache.enabled", true);
   cal.manager.registerCalendar(networkCalendarB);
-  let dbB = cal.manager.getCalendarById(networkCalendarB.id).wrappedJSObject.mCachedCalendar
-    .wrappedJSObject.mStorageDb.db;
+  networkCalendarB = cal.manager.getCalendarById(networkCalendarB.id);
+  let dbB = networkCalendarB.wrappedJSObject.mCachedCalendar.wrappedJSObject.mStorageDb.db;
 
   Assert.equal(
     dbA.databaseFile.path,
     PathUtils.join(PathUtils.profileDir, "calendar-data", "cache.sqlite"),
     "network calendar A uses the right database file"
   );
   Assert.equal(
     dbB.databaseFile.path,
     PathUtils.join(PathUtils.profileDir, "calendar-data", "cache.sqlite"),
-    "network calendar two uses the right database file"
+    "network calendar B uses the right database file"
   );
   Assert.equal(dbA, dbB, "network calendars share a database connection");
 });