Commit 4f9a4b82 authored by Andrey Kosyakov's avatar Andrey Kosyakov Committed by Commit Bot

Unpause virtual time when stream response in received

... to prevent deadlocking against stream consumer that may be blocked
because of virtual time.

Change-Id: Ic823f056677d707291c2cfd60bc8f8677d10c070
Reviewed-on: https://chromium-review.googlesource.com/c/1359414Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Andrey Kosyakov <caseq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#613375}
parent 35a754d3
Tests that fetching a stream with back pressure does not stall with virtual time enabled.
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const server = new Map([
['http://test.com/index.html', '<html></html>'],
['http://test.com/fetch', 'HTTP/1.1 200 OK\r\nCache-Control: no-store\r\n\r\n<some data>']]);
(async function(testRunner) {
var {page, session, dp} = await testRunner.startBlank(
'Tests that fetching a stream with back pressure ' +
'does not stall with virtual time enabled.');
await dp.Network.enable();
await dp.Network.setRequestInterception({ patterns: [{ urlPattern: '*' }] });
dp.Network.onRequestIntercepted(event => {
let body = server.get(event.params.request.url);
dp.Network.continueInterceptedRequest({
interceptionId: event.params.interceptionId,
rawResponse: btoa(body)
});
});
dp.Emulation.onVirtualTimeBudgetExpired(async data => {
testRunner.log(await session.evaluate('document.title'));
testRunner.completeTest();
});
await dp.Emulation.setVirtualTimePolicy({policy: 'pause'});
await dp.Emulation.setVirtualTimePolicy({
policy: 'pauseIfNetworkFetchesPending', budget: 5000,
waitForNavigation: true});
await dp.Page.navigate({url: 'http://test.com/index.html'});
await session.evaluateAsync(`fetch('/fetch')`);
})
......@@ -224,6 +224,8 @@ HEADLESS_PROTOCOL_TEST(VirtualTimeStarvation,
HEADLESS_PROTOCOL_TEST(VirtualTimeVideo, "emulation/virtual-time-video.js");
HEADLESS_PROTOCOL_TEST(VirtualTimeErrorLoop,
"emulation/virtual-time-error-loop.js");
HEADLESS_PROTOCOL_TEST(VirtualTimeFetchStream,
"emulation/virtual-time-fetch-stream.js");
// Flaky Test crbug.com/859382
HEADLESS_PROTOCOL_TEST(DISABLED_VirtualTimeHistoryNavigation,
......
......@@ -905,6 +905,11 @@ void ResourceLoader::DidReceiveResponse(
request_context, resource_,
FetchContext::ResourceResponseType::kNotFromMemoryCache);
// When streaming, unpause virtual time early to prevent deadlocking
// against stream consumer in case stream has backpressure enabled.
if (handle)
resource_->VirtualTimePauser().UnpauseVirtualTime();
resource_->ResponseReceived(response_to_pass, std::move(handle));
// Send the cached code after we notify that the response is received.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment