test_bug22806_retry_deadlock.js
Go to the documentation of this file.
1 /*
2  *=BEGIN SONGBIRD GPL
3  *
4  * This file is part of the Songbird web player.
5  *
6  * Copyright(c) 2005-2010 POTI, Inc.
7  * http://www.songbirdnest.com
8  *
9  * This file may be licensed under the terms of of the
10  * GNU General Public License Version 2 (the ``GPL'').
11  *
12  * Software distributed under the License is distributed
13  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the GPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the GPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/gpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  *=END SONGBIRD GPL
23  */
24 
30 Components.utils.import("resource://app/jsmodules/ArrayConverter.jsm");
31 Components.utils.import("resource://app/jsmodules/sbLibraryUtils.jsm");
32 Components.utils.import("resource://app/jsmodules/URLUtils.jsm");
33 
34 function runTest() {
35  // set up the server
36  var port = getTestServerPortNumber();
37 
38  var server = Cc["@mozilla.org/server/jshttp;1"]
39  .createInstance(Ci.nsIHttpServer);
40 
41  server.start(port);
42  server.registerDirectory("/", getTempFolder());
43 
44  // try to run the test, but make sure to at least always shut down the server
45  try {
46  var lib = createLibrary("bug22806_blacklist_deadlock");
47  lib.clear();
48  runTestInternal(lib);
49  }
50  finally {
51  server.stop(function() void(0));
52  lib.clear();
53  }
54 }
55 
60 function runTestInternal(library) {
61  var libUtils = LibraryUtils.manager.QueryInterface(Ci.sbILibraryUtils);
62  var fileMetaSvc = Cc["@songbirdnest.com/Songbird/FileMetadataService;1"]
63  .getService(Ci.sbIFileMetadataService)
64  .QueryInterface(Ci.sbPIFileMetadataService);
65  const URL_PREFIX = "http://localhost:" + getTestServerPortNumber() + "/";
66  const JOBS_PER_GROUP = 12;
67  var items = [];
68  var filename, i, job;
69  var jobs = 0; // number of outstanding jobs (we'll have up to 2 of them)
70 
71  /* job progress callback to know when the test is done */
72  function onJobProgress(job) {
73  reportJobProgress(job, "bug22806_blacklist_deadlock - onJobProgress");
74  if (job.status == Ci.sbIJobProgress.STATUS_RUNNING) {
75  return;
76  }
77  job.removeJobProgressListener(onJobProgress);
78  if (--jobs < 1) {
79  testFinished();
80  }
81  }
82 
83  // first, spin up a collection of local (background thread) and remote (main
84  // thread) metadata reads, to make sure both thread have pending jobs
85  for (i = 0; i < JOBS_PER_GROUP; ++i) {
86  filename = "bug22806_blacklist_good_" + i + ".mp3";
88  "testharness/metadatamanager/files/MP3_NoTags.mp3"),
89  filename);
90  if (i % 2) {
91  url = libUtils.getFileContentURI(file);
92  }
93  else {
94  url = libUtils.getContentURI(URLUtils.newURI(URL_PREFIX + filename));
95  }
96  items.push(library.createMediaItem(url));
97  }
98  job = fileMetaSvc.read(ArrayConverter.nsIArray(items));
99  job.addJobProgressListener(onJobProgress);
100  ++jobs;
101 
102  // next, spin up a bunch of blacklisted remote (main thread) reads, so that
103  // it will need to attempt to get into the undesired state
104  items = [];
105  for (i = 0; i < JOBS_PER_GROUP; ++i) {
106  filename = "bug22806_blacklist_blacklisted_" + i + ".mp3";
108  "testharness/metadatamanager/files/MP3_NoTags.mp3"),
109  filename);
110  url = libUtils.getContentURI(URLUtils.newURI(URL_PREFIX + filename));
111  fileMetaSvc.AddBlacklistURL(url.spec);
112  items.push(library.createMediaItem(url));
113  }
114  job = fileMetaSvc.read(ArrayConverter.nsIArray(items));
115  job.addJobProgressListener(onJobProgress);
116  ++jobs;
117 
118  // wait for both jobs to finish
119  testPending();
120 }
121 
const Cc
function runTest()
Advanced DataRemote unit tests.
function newAppRelativeFile(path)
function testFinished()
function server(port, basePath)
Definition: httpd.js:4758
function reportJobProgress(job, jobName)
function getCopyOfFile(file, tempName, optionalLocation)
function createLibrary(databaseGuid, databaseLocation)
Definition: test_load.js:151
function url(spec)
function getTempFolder()
const Ci
Javascript wrappers for common library tasks.
function getTestServerPortNumber()
_getSelectedPageStyle s i
var file
function runTestInternal(library)
function testPending()