Bug 236263 - http/tests/cache-storage/cache-origins.https.html is flaky
Summary: http/tests/cache-storage/cache-origins.https.html is flaky
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-02-07 14:57 PST by Chris Dumez
Modified: 2022-02-08 13:18 PST (History)
6 users (show)

See Also:


Attachments
Patch (2.15 KB, patch)
2022-02-07 15:01 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (2.35 KB, patch)
2022-02-07 15:27 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (2.87 KB, patch)
2022-02-07 16:15 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (4.19 KB, patch)
2022-02-07 16:21 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (4.15 KB, patch)
2022-02-08 07:33 PST, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2022-02-07 14:57:43 PST
http/tests/cache-storage/cache-origins.https.html is flaky because it relies on a particular HashMap ordering.
Comment 1 Chris Dumez 2022-02-07 15:01:47 PST
Created attachment 451157 [details]
Patch
Comment 2 Darin Adler 2022-02-07 15:10:35 PST
Comment on attachment 451157 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=451157&action=review

We should do this sorting inside WebCore, I think.

> LayoutTests/http/tests/cache-storage/cache-origins.https.html:23
> +        representation.sort((a, b) => { return a.origin.clientOrigin > b.origin.clientOrigin; });

This isn’t right. It’s supposed to be a three way sort function, and needs to return -1, 0, +1 based on the ordering. Not like C++ standard library where they used boolean less than style sorting.

> LayoutTests/http/tests/cache-storage/cache-origins.https.html:36
> +        representation.sort((a, b) => { return a.origin.clientOrigin > b.origin.clientOrigin; });

Ditto.
Comment 3 Chris Dumez 2022-02-07 15:27:53 PST
Created attachment 451163 [details]
Patch
Comment 4 Darin Adler 2022-02-07 15:38:53 PST
Comment on attachment 451163 [details]
Patch

I still think we should fix this inside WebCore, but this is a good fix. We should also take out the "value_or(0)" we added to work around it.
Comment 5 Chris Dumez 2022-02-07 16:15:56 PST
Created attachment 451167 [details]
Patch
Comment 6 Chris Dumez 2022-02-07 16:16:21 PST
Alternative approach, fixing it on native side, as suggested.
Comment 7 Chris Dumez 2022-02-07 16:21:40 PST
Created attachment 451168 [details]
Patch
Comment 8 Darin Adler 2022-02-07 17:54:24 PST
Comment on attachment 451168 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=451168&action=review

I like this as is, but I have some thoughts on little style tweaks.

> Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp:796
>      builder.append("{ \"path\": \"");
>      builder.append(m_rootPath);
>      builder.append("\", \"origins\": [");

We can merge these all into one line.

> Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp:797
> +    Vector<String> origins = WTF::map(m_caches, [](auto& keyValue) {

Could use auto here instead of Vector<String>. I think it would look a little better if it’s built even before we define StringBuilder.

> Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp:803
> +        originBuilder.append("\n{ \"origin\" : { \"topOrigin\" : \"");
> +        originBuilder.append(keyValue.key.topOrigin.toString());
> +        originBuilder.append("\", \"clientOrigin\": \"");
> +        originBuilder.append(keyValue.key.clientOrigin.toString());
> +        originBuilder.append("\" }, \"caches\" : ");

We can merge these all into fewer lines.

> Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp:811
> +    for (auto& origin : origins) {

Another way to write this:

    const char* divider = "";
    for (auto& origin : origins) {
        builder.append(divider, origin);
        divider = ",";
    }

A little less wordy than the isFirst version.
Comment 9 Chris Dumez 2022-02-08 07:33:53 PST
Created attachment 451243 [details]
Patch
Comment 10 EWS 2022-02-08 13:17:34 PST
Committed r289419 (246982@main): <https://commits.webkit.org/246982@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 451243 [details].
Comment 11 Radar WebKit Bug Importer 2022-02-08 13:18:21 PST
<rdar://problem/88648506>