Closed Bug 888544 Opened 11 years ago Closed 11 years ago

use a dynamic port in jsdownloads/ xpcshell tests so they can be run in parallel

Categories

(Toolkit :: General, defect)

x86_64
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla25

People

(Reporter: mihneadb, Assigned: mihneadb)

References

Details

Attachments

(1 file, 1 obsolete file)

      No description provided.
Blocks: 887064
Attached patch use -1 as httpd port (obsolete) — Splinter Review
Assignee: nobody → mihneadb
Attachment #769275 - Flags: review?(mak77)
Comment on attachment 769275 [details] [diff] [review]
use -1 as httpd port

Review of attachment 769275 [details] [diff] [review]:
-----------------------------------------------------------------

::: toolkit/components/jsdownloads/test/unit/head.js
@@ +50,5 @@
>                                        "@mozilla.org/binaryoutputstream;1",
>                                        "nsIBinaryOutputStream",
>                                        "setOutputStream")
>  
> +let serverSocket = null;

I don't think you need this complicate change that may easily create shadow variables in tests (indeed you had to unshadow a couple, that's confusing).

@@ +60,4 @@
>  
> +XPCOMUtils.defineLazyGetter(this, "FAKE_BASE", function() {
> +  return "http://localhost:" + serverSocket.port;
> +});

we generate a new fake server everytime we call startFakeServer, but since all of these are lazy getters, they will use the proper port only for the first generated server.
I suspect this works just by accident, likely the httpd server returns always the same free port, but that's fragile.
You need an actual getter here, but not a lazy one, you may create those with Object.defineProperty on the global object, I guess.

::: toolkit/components/jsdownloads/test/unit/test_DownloadCore.js
@@ +628,5 @@
>   * Ensures download error details are reported on network failures.
>   */
>  add_task(function test_download_error_source()
>  {
> +  serverSocket = startFakeServer();

please no

::: toolkit/components/jsdownloads/test/unit/test_DownloadLegacy.js
@@ +275,5 @@
>   * Ensures download error details are reported for legacy downloads.
>   */
>  add_task(function test_error()
>  {
> +  serverSocket = startFakeServer();

ditto
Attachment #769275 - Flags: review?(mak77) → review-
ah, rather than storing gServerSocket I think you may just store gFakeServerPort
Ok, I understand what the problems are, and I tried to do what was possible without changing the structure of the tests themselves (the fact that they all share those 'constants' in the head file while starting their own servers is a pain).

I'm not sure I fully understand what you suggest I should do.

Are you saying I should use defineProperty for all the URLs in the head file and inside the defProp function just use socketServer "blindly" (knowing that it will be defined by the time the getters are called)?


Thanks
(In reply to Mihnea Dobrescu-Balaur (:mihneadb) from comment #4)
> Are you saying I should use defineProperty for all the URLs in the head file
> and inside the defProp function just use socketServer "blindly" (knowing
> that it will be defined by the time the getters are called)?

I think that's fine, we use one server at a time. The alternative would be to provide an object that given a server returns urls, but that looks like an overkill for the current usage.
I hope I understood correctly what you suggested.
Attachment #773742 - Flags: review?(mak77)
Attachment #769275 - Attachment is obsolete: true
Comment on attachment 773742 [details] [diff] [review]
use dynamic ports

Review of attachment 773742 [details] [diff] [review]:
-----------------------------------------------------------------

well, ideally only the FAKE_BASE getters should not be lazy, but actually I think it's ok as it is, so all of them are coherent, there's less risk of using the wrong getter type.
Attachment #773742 - Flags: review?(mak77) → review+
This looks good. For the record, I noticed we started to have many repetitions of
the same pattern, in the future we might refactor that part a little bit (a good
moment might be while solving the intermittent failure in bug 865364).
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/d578673157a5
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla25
:mak77, this is not entirely fixed. Every once in a while I encounter this:

http://pastebin.mozilla.org/2796790

At first I thought it was the getTempDir function but that's not the problem. I'll run these sequentially for now (it's no big win, 4s vs 5s on my machine), marked in bug 898658.
Flags: needinfo?(mak77)
(In reply to Mihnea Dobrescu-Balaur (:mihneadb) from comment #12)
> :mak77, this is not entirely fixed. Every once in a while I encounter this:
> 
> http://pastebin.mozilla.org/2796790

This looks like the intermittent failure filed as bug 901017, do you think it
can be related to running the tests concurrently?
Flags: needinfo?(mak77)
:paolo, you are absolutely right. I just assumed it was my fault, haha :).
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: