Closed Bug 1132772 Opened 9 years ago Closed 9 years ago

afterCache and afterCommit should return Promise

Categories

(Firefox :: Search, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
Firefox 39
Tracking Status
firefox39 --- fixed

People

(Reporter: hiro, Assigned: hiro)

References

(Blocks 1 open bug)

Details

Attachments

(1 file, 3 obsolete files)

Attached patch wait_for_afterCache.patch (obsolete) — Splinter Review
test_nocache.js can be failed because the test does not wait for afterCache() on search.init().

The failure can be easily reproduced with removing "firefox-appdir = browser" from toolkit/components/search/tests/xpcshell/xpcshell.ini.

The result:

./mach xpcshell-test toolkit/components/search/tests/xpcshell/test_nocache.js

<snip>
 0:01.11 LOG: Thread-1 INFO "CONSOLE_MESSAGE: (info) NOTIFY: Engine: "Test search engine"; Verb: "engine-loaded""
 0:01.11 LOG: Thread-1 INFO "CONSOLE_MESSAGE: (info) nsSearchService::observe: Done installation of Test search engine."
 0:01.11 LOG: Thread-1 INFO "CONSOLE_MESSAGE: (info) _addEngineToStore: Adding engine: "Test search engine""
 0:01.11 LOG: Thread-1 INFO "CONSOLE_MESSAGE: (info) NOTIFY: Engine: "Test search engine"; Verb: "engine-added""
 0:01.14 LOG: Thread-1 INFO "afterCache: write-cache-to-disk-complete"
 0:01.14 LOG: Thread-1 INFO "afterCache: write-cache-to-disk-complete"
 0:01.14 TEST_STATUS: Thread-1 test_nocache PASS [test_nocache : 31] true == true
 0:01.14 LOG: Thread-1 INFO "Searching test engine in cache"
 0:01.14 TEST_STATUS: Thread-1 test_nocache FAIL [test_nocache : 62] false == true
    /home/ikezoe/mozilla-central/obj-firefox/_tests/xpcshell/toolkit/components/search/tests/xpcshell/test_nocache.js:test_nocache:62
    self-hosted:next:610
    _run_next_test@/home/ikezoe/mozilla-central/testing/xpcshell/head.js:1375:9
    do_execute_soon/<.run@/home/ikezoe/mozilla-central/testing/xpcshell/head.js:644:9
    _do_main@/home/ikezoe/mozilla-central/testing/xpcshell/head.js:207:5
    _execute_test@/home/ikezoe/mozilla-central/testing/xpcshell/head.js:504:5
    @-e:1:1
 0:01.14 LOG: Thread-1 INFO exiting test
 0:01.14 LOG: Thread-1 ERROR Unexpected exception 2147500036
Attachment #8563839 - Flags: review?(mak77)
Comment on attachment 8563839 [details] [diff] [review]
wait_for_afterCache.patch

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

::: toolkit/components/search/tests/xpcshell/test_nocache.js
@@ +21,5 @@
>  
>  add_task(function* test_nocache() {
>    let search = Services.search;
>  
> +  let cachePromise = new Promise(resolve => afterCache(resolve));

let's rather make afterCache return a Promise, and the call points using the callback can use .then()
Attachment #8563839 - Flags: review?(mak77)
Summary: Should wait afterCache in test_nocache.js → afterCache and afterCommit should return Promise
Attached patch return_Promise.patch (obsolete) — Splinter Review
Changed bug title.

afterCommit() is also changed to return a Promise.

https://treeherder.mozilla.org/#/jobs?repo=try&revision=f7984f66dde3
Assignee: nobody → hiikezoe
Attachment #8563839 - Attachment is obsolete: true
Attachment #8564933 - Flags: review?(mak77)
Comment on attachment 8564933 [details] [diff] [review]
return_Promise.patch

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

::: toolkit/components/search/tests/xpcshell/head_search.js
@@ +142,5 @@
>    return UTCOffset >= 150 && UTCOffset <= 600;
>  }
>  
>  /**
> + * Waits for being metadata committed.

s/being metadata/metadata being/

@@ +150,1 @@
>  {

while here please move brace in line with the function definition, per coding style

@@ +152,4 @@
>  }
>  
>  /**
> + * Waits for saving cache file.

Waits for the cache file to be saved.

::: toolkit/components/search/tests/xpcshell/test_nocache.js
@@ +34,1 @@
>      // Check that search.json has been created.

I'd prefer a more readable:

yield afterCachePromise;

// Check that search.json has...
...

@@ +43,5 @@
>      { name: "Test search engine", xmlFileName: "engine.xml" },
>    ]);
>  
>    do_print("Engine has been added, let's wait for the cache to be built");
> +  yield afterCachePromise;

Do we really need to store the promise in a temp var in this case?

The notification we wait for is notified on a promise resolution, so basically it should run one tick after us... If that would not be true, the previous code would have failed already.
I think this will just do:

yield promiseAfterCache();
Attachment #8564933 - Flags: review?(mak77) → feedback+
(In reply to Marco Bonardo [::mak] -- currently sick :( (delayed answers) from comment #4)

> @@ +43,5 @@
> >      { name: "Test search engine", xmlFileName: "engine.xml" },
> >    ]);
> >  
> >    do_print("Engine has been added, let's wait for the cache to be built");
> > +  yield afterCachePromise;
> 
> Do we really need to store the promise in a temp var in this case?
> 
> The notification we wait for is notified on a promise resolution, so
> basically it should run one tick after us... If that would not be true, the
> previous code would have failed already.

Ah, right.
My intention was to avoid waiting for wrong notification as the previous code did. Actually the notification received after addTestEngines() in the previous code came from search.init(). But unfortunately the temp var does not avoid the notification mismatch at all!. The mismatch can be fixed by the yield after search.init() as attachment 8564933 [details] [diff] [review] does, not the temp var!

I will attach a revised patch.

Thanks Marco! Take care!
Attached patch return Promise v2 (obsolete) — Splinter Review
https://treeherder.mozilla.org/#/jobs?repo=try&revision=4940a4a12f8a
There are a few build bustages unrelated this patch.
Attachment #8564933 - Attachment is obsolete: true
Attachment #8570267 - Flags: review?(mak77)
Comment on attachment 8570267 [details] [diff] [review]
return Promise v2

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

Taking over for Marco. LGTM with the one comment corrected. Thanks!

::: toolkit/components/search/tests/xpcshell/test_nocache.js
@@ +28,5 @@
>    yield new Promise((resolve, reject) => search.init(rv => {
>      Components.isSuccessCode(rv) ? resolve() : reject();
>    }));
>  
> +  // Check that cache is created at startup

Nit: // Check that the cache is created at startup.
Attachment #8570267 - Flags: review?(mak77) → review+
Thanks Tim!
Carrying over review+.
Attachment #8570267 - Attachment is obsolete: true
Attachment #8577796 - Flags: review+
Keywords: checkin-needed
https://hg.mozilla.org/integration/fx-team/rev/97f74a12b427
Flags: in-testsuite+
Keywords: checkin-needed
Whiteboard: [fixed-in-fx-team]
https://hg.mozilla.org/mozilla-central/rev/97f74a12b427
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Whiteboard: [fixed-in-fx-team]
Target Milestone: --- → Firefox 39
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: