Changeset 215044 in webkit


Ignore:
Timestamp:
Apr 6, 2017 11:32:47 AM (7 years ago)
Author:
Antti Koivisto
Message:

Implement testing mode for disk cache
https://bugs.webkit.org/show_bug.cgi?id=170547

Reviewed by Andreas Kling.

Source/WebKit2:

Disable read timeouts and cache shrinking in TestRunner to eliminate potential sources of randomness.

Cache directories are deleted by TestRunner so lack of shrinking does not consume the disk.

This is enabled by the existing WKContextUseTestingNetworkSession SPI.

  • NetworkProcess/cache/NetworkCache.cpp:

(WebKit::NetworkCache::Cache::initialize):

  • NetworkProcess/cache/NetworkCache.h:
  • NetworkProcess/cache/NetworkCacheStorage.cpp:

(WebKit::NetworkCache::Storage::open):
(WebKit::NetworkCache::Storage::Storage):
(WebKit::NetworkCache::Storage::dispatchReadOperation):
(WebKit::NetworkCache::Storage::shrinkIfNeeded):

  • NetworkProcess/cache/NetworkCacheStorage.h:
  • NetworkProcess/cocoa/NetworkProcessCocoa.mm:

(WebKit::NetworkProcess::platformInitializeNetworkProcessCocoa):

LayoutTests:

Enable a few disabled tests to see how it goes.

  • platform/mac-wk2/TestExpectations:
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r215043 r215044  
     12017-04-06  Antti Koivisto  <antti@apple.com>
     2
     3        Implement testing mode for disk cache
     4        https://bugs.webkit.org/show_bug.cgi?id=170547
     5
     6        Reviewed by Andreas Kling.
     7
     8        Enable a few disabled tests to see how it goes.
     9
     10        * platform/mac-wk2/TestExpectations:
     11
    1122017-04-06  Romain Bellessort  <romain.bellessort@crf.canon.fr>
    213
  • trunk/LayoutTests/platform/mac-wk2/TestExpectations

    r214913 r215044  
    309309webkit.org/b/151455 [ Release ] http/tests/xmlhttprequest/workers/methods-async.html [ Pass Timeout ]
    310310
    311 webkit.org/b/162945 http/tests/cache/disk-cache/disk-cache-request-max-stale.html [ Pass Failure ]
    312 
    313 webkit.org/b/162946 http/tests/cache/disk-cache/disk-cache-media.html [ Pass Failure ]
    314 
    315311webkit.org/b/150542 fast/forms/state-restore-per-form.html [ Pass Timeout ]
    316312
  • trunk/Source/WebKit2/ChangeLog

    r215040 r215044  
     12017-04-06  Antti Koivisto  <antti@apple.com>
     2
     3        Implement testing mode for disk cache
     4        https://bugs.webkit.org/show_bug.cgi?id=170547
     5
     6        Reviewed by Andreas Kling.
     7
     8        Disable read timeouts and cache shrinking in TestRunner to eliminate potential sources of randomness.
     9
     10        Cache directories are deleted by TestRunner so lack of shrinking does not consume the disk.
     11
     12        This is enabled by the existing WKContextUseTestingNetworkSession SPI.
     13
     14        * NetworkProcess/cache/NetworkCache.cpp:
     15        (WebKit::NetworkCache::Cache::initialize):
     16        * NetworkProcess/cache/NetworkCache.h:
     17        * NetworkProcess/cache/NetworkCacheStorage.cpp:
     18        (WebKit::NetworkCache::Storage::open):
     19        (WebKit::NetworkCache::Storage::Storage):
     20        (WebKit::NetworkCache::Storage::dispatchReadOperation):
     21        (WebKit::NetworkCache::Storage::shrinkIfNeeded):
     22        * NetworkProcess/cache/NetworkCacheStorage.h:
     23        * NetworkProcess/cocoa/NetworkProcessCocoa.mm:
     24        (WebKit::NetworkProcess::platformInitializeNetworkProcessCocoa):
     25
    1262017-04-06  Chris Dumez  <cdumez@apple.com>
    227
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp

    r212965 r215044  
    7474#endif
    7575
    76 bool Cache::initialize(const String& cachePath, const Parameters& parameters)
    77 {
    78     m_storage = Storage::open(cachePath);
     76bool Cache::initialize(const String& cachePath, OptionSet<Option> options)
     77{
     78    m_storage = Storage::open(cachePath, options.contains(Option::TestingMode) ? Storage::Mode::Testing : Storage::Mode::Normal);
    7979
    8080#if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION)
    81     if (parameters.enableNetworkCacheSpeculativeRevalidation) {
     81    if (options.contains(Option::SpeculativeRevalidation)) {
    8282        m_lowPowerModeNotifier = std::make_unique<WebCore::LowPowerModeNotifier>([this](bool isLowPowerModeEnabled) {
    8383            ASSERT(WTF::isMainThread());
     
    9494#endif
    9595
    96     if (parameters.enableEfficacyLogging)
     96    if (options.contains(Option::EfficacyLogging))
    9797        m_statistics = Statistics::open(cachePath);
    9898
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.h

    r212965 r215044  
    3434#include <WebCore/ResourceResponse.h>
    3535#include <wtf/Function.h>
     36#include <wtf/OptionSet.h>
    3637#include <wtf/text/WTFString.h>
    3738
     
    9596    friend class WTF::NeverDestroyed<Cache>;
    9697public:
    97     struct Parameters {
    98         bool enableEfficacyLogging;
     98    enum class Option {
     99        EfficacyLogging,
     100        // In testing mode we try to eliminate sources of randomness. Cache does not shrink and there are no read timeouts.
     101        TestingMode,
    99102#if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION)
    100         bool enableNetworkCacheSpeculativeRevalidation;
     103        SpeculativeRevalidation,
    101104#endif
    102105    };
    103     bool initialize(const String& cachePath, const Parameters&);
     106    bool initialize(const String& cachePath, OptionSet<Option>);
    104107    void setCapacity(size_t);
    105108
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp

    r214786 r215044  
    150150}
    151151
    152 std::unique_ptr<Storage> Storage::open(const String& cachePath)
     152std::unique_ptr<Storage> Storage::open(const String& cachePath, Mode mode)
    153153{
    154154    ASSERT(RunLoop::isMain());
     
    159159    if (!salt)
    160160        return nullptr;
    161     return std::unique_ptr<Storage>(new Storage(cachePath, *salt));
     161    return std::unique_ptr<Storage>(new Storage(cachePath, mode, *salt));
    162162}
    163163
     
    208208}
    209209
    210 Storage::Storage(const String& baseDirectoryPath, Salt salt)
     210Storage::Storage(const String& baseDirectoryPath, Mode mode, Salt salt)
    211211    : m_basePath(baseDirectoryPath)
    212212    , m_recordsPath(makeRecordsDirectoryPath(baseDirectoryPath))
     213    , m_mode(mode)
    213214    , m_salt(salt)
    214215    , m_canUseSharedMemoryForBodyData(canUseSharedMemoryForPath(baseDirectoryPath))
     
    574575    m_activeReadOperations.add(WTFMove(readOperationPtr));
    575576
    576     // I/O pressure may make disk operations slow. If they start taking very long time we rather go to network.
    577     const auto readTimeout = 1500ms;
    578     m_readOperationTimeoutTimer.startOneShot(readTimeout);
     577    // Avoid randomness during testing.
     578    if (m_mode != Mode::Testing) {
     579        // I/O pressure may make disk operations slow. If they start taking very long time we rather go to network.
     580        const auto readTimeout = 1500ms;
     581        m_readOperationTimeoutTimer.startOneShot(readTimeout);
     582    }
    579583
    580584    bool shouldGetBodyBlob = mayContainBlob(readOperation.key);
     
    966970    ASSERT(RunLoop::isMain());
    967971
     972    // Avoid randomness caused by cache shrinks.
     973    if (m_mode == Mode::Testing)
     974        return;
     975
    968976    if (approximateSize() > m_capacity)
    969977        shrink();
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h

    r214559 r215044  
    4949    WTF_MAKE_NONCOPYABLE(Storage);
    5050public:
    51     static std::unique_ptr<Storage> open(const String& cachePath);
     51    enum class Mode { Normal, Testing };
     52    static std::unique_ptr<Storage> open(const String& cachePath, Mode);
    5253
    5354    struct Record {
     
    106107
    107108private:
    108     Storage(const String& directoryPath, Salt);
     109    Storage(const String& directoryPath, Mode, Salt);
    109110
    110111    String recordDirectoryPathForKey(const Key&) const;
     
    146147    const String m_basePath;
    147148    const String m_recordsPath;
    148 
     149   
     150    const Mode m_mode;
    149151    const Salt m_salt;
    150 
    151152    const bool m_canUseSharedMemoryForBodyData;
    152153
  • trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkProcessCocoa.mm

    r213747 r215044  
    113113#if ENABLE(NETWORK_CACHE)
    114114        if (parameters.shouldEnableNetworkCache) {
    115             NetworkCache::Cache::Parameters cacheParameters = {
    116                 parameters.shouldEnableNetworkCacheEfficacyLogging
     115            OptionSet<NetworkCache::Cache::Option> cacheOptions;
     116            if (parameters.shouldEnableNetworkCacheEfficacyLogging)
     117                cacheOptions |= NetworkCache::Cache::Option::EfficacyLogging;
     118            if (parameters.shouldUseTestingNetworkSession)
     119                cacheOptions |= NetworkCache::Cache::Option::TestingMode;
    117120#if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION)
    118                 , parameters.shouldEnableNetworkCacheSpeculativeRevalidation
    119 #endif
    120             };
    121             if (NetworkCache::singleton().initialize(m_diskCacheDirectory, cacheParameters)) {
     121            if (parameters.shouldEnableNetworkCacheSpeculativeRevalidation)
     122                cacheOptions |= NetworkCache::Cache::Option::SpeculativeRevalidation;
     123#endif
     124            if (NetworkCache::singleton().initialize(m_diskCacheDirectory, cacheOptions)) {
    122125                auto urlCache(adoptNS([[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil]));
    123126                [NSURLCache setSharedURLCache:urlCache.get()];
  • trunk/Source/WebKit2/NetworkProcess/soup/NetworkProcessSoup.cpp

    r213877 r215044  
    113113    SoupNetworkSession::clearOldSoupCache(WebCore::directoryName(m_diskCacheDirectory));
    114114
    115     NetworkCache::Cache::Parameters cacheParameters {
    116         parameters.shouldEnableNetworkCacheEfficacyLogging
     115    OptionSet<NetworkCache::Cache::Option> cacheOptions;
     116    if (parameters.shouldEnableNetworkCacheEfficacyLogging)
     117        cacheOptions |= NetworkCache::Cache::Option::EfficacyLogging;
    117118#if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION)
    118         , parameters.shouldEnableNetworkCacheSpeculativeRevalidation
     119    if (parameters.shouldEnableNetworkCacheSpeculativeRevalidation)
     120        cacheOptions |= NetworkCache::Cache::Option::SpeculativeRevalidation;
    119121#endif
    120     };
    121     NetworkCache::singleton().initialize(m_diskCacheDirectory, cacheParameters);
     122
     123    NetworkCache::singleton().initialize(m_diskCacheDirectory, cacheOptions);
    122124
    123125    if (!parameters.cookiePersistentStoragePath.isEmpty()) {
Note: See TracChangeset for help on using the changeset viewer.